/
check.go
39 lines (35 loc) · 1012 Bytes
/
check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2018, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package spell
import (
"strings"
"cogentcore.org/core/parse/lexer"
"cogentcore.org/core/parse/token"
)
// CheckLexLine returns the Lex regions for any words that are misspelled
// within given line of text with existing Lex tags -- automatically
// excludes any Code token regions (see token.IsCode). Token is set
// to token.TextSpellErr on returned Lex's
func CheckLexLine(src []rune, tags lexer.Line) lexer.Line {
wrds := tags.NonCodeWords(src)
var ser lexer.Line
for _, t := range wrds {
wrd := string(t.Src(src))
lwrd := lexer.FirstWordApostrophe(wrd)
if len(lwrd) <= 2 {
continue
}
_, known := CheckWord(lwrd)
if !known {
t.Token.Token = token.TextSpellErr
widx := strings.Index(wrd, lwrd)
ld := len(wrd) - len(lwrd)
t.St += widx
t.Ed += widx - ld
t.Now()
ser = append(ser, t)
}
}
return ser
}