Esempio n. 1
0
File: view.go Progetto: haofree/lime
func (v *View) parsethread() {
	pc := 0
	lastParse := -1
	doparse := func() {
		p := Prof.Enter("syntax.parse")
		defer p.Exit()
		defer func() {
			if r := recover(); r != nil {
				log4go.Error("Panic in parse thread: %v\n%s", r, string(debug.Stack()))
				if pc > 0 {
					panic(r)
				}
				pc++
			}
		}()
		b := v.Buffer()
		b.Lock()
		sub := b.Substr(Region{0, b.Size()})
		b.Unlock()
		source, _ := v.Settings().Get("syntax", "").(string)
		if len(source) != 0 {
			// TODO
			if pr, err := textmate.NewLanguageParser(source, sub); err != nil {
				log4go.Error("Couldn't parse: %v", err)
			} else if syn, err := parser.NewSyntaxHighlighter(pr); err != nil {
				log4go.Error("Couldn't create syntaxhighlighter: %v", err)
			} else {
				v.lock.Lock()
				defer v.lock.Unlock()
				// Only set if it isn't invalid already, otherwise the
				// current syntax highlighting will be more accurate
				// as it will have had incremental adjustments done to it
				if v.buffer.ChangeCount() == lastParse {
					v.syntax = syn
					for k := range v.regions {
						if strings.HasPrefix(k, "lime.syntax") {
							delete(v.regions, k)
						}
					}
					for k, v2 := range syn.Flatten() {
						if v2.Regions.HasNonEmpty() {
							v.regions[k] = v2
						}
					}
				}
			}
		}
	}
	for pr := range v.reparseChan {
		if cc := v.buffer.ChangeCount(); lastParse != cc || pr.forced {
			lastParse = cc
			doparse()
			v.Settings().Set("lime.syntax.updated", lastParse)
		}
	}
}
Esempio n. 2
0
func (v *View) parsethread() {
	pc := 0
	doparse := func() {
		p := Prof.Enter("syntax.parse")
		defer p.Exit()
		defer func() {
			if r := recover(); r != nil {
				log4go.Error("Panic in parse thread: %v\n%s", r, string(debug.Stack()))
				if pc > 0 {
					panic(r)
				}
				pc++
			}
		}()
		b := v.Buffer()
		b.Lock()
		sub := b.Substr(Region{0, b.Size()})
		b.Unlock()
		source, _ := v.Settings().Get("syntax", "").(string)
		if len(source) != 0 {
			// TODO
			if pr, err := textmate.NewLanguageParser(source, sub); err != nil {
				log4go.Error("Couldn't parse: %v", err)
			} else if syn, err := parser.NewSyntaxHighlighter(pr); err != nil {
				log4go.Error("Couldn't create syntaxhighlighter: %v", err)
			} else {
				v.lock.Lock()
				defer v.lock.Unlock()
				v.syntax = syn
			}
		}
	}
	lastParse := -1
	for pr := range v.reparseChan {
		if cc := v.buffer.ChangeCount(); lastParse != cc || pr.forced {
			lastParse = cc
			doparse()
		}
	}
}