升级关键字解析逻辑
This commit is contained in:
parent
43f4d51146
commit
8d2e9c93ae
35
lexical.go
35
lexical.go
@ -96,6 +96,37 @@ func (l *lexical) Parse(jsonData string) ([]*lexicalNode, error) {
|
||||
//
|
||||
// Date : 18:15 2022/7/4
|
||||
func (l *lexical) inputCharIsToken(inputChar string, tmpStr string) bool {
|
||||
tokenList := []string{
|
||||
// list 类型起始
|
||||
listLeftToken,
|
||||
// listRight list 类型结束
|
||||
listRightToken,
|
||||
// 对象起始
|
||||
objectLeftToken,
|
||||
// 对象结束
|
||||
objectRightToken,
|
||||
// key 值的起始
|
||||
keyLeftRightToken,
|
||||
// 转义符
|
||||
// escapeCharacterToken,
|
||||
// 冒号
|
||||
colonToken,
|
||||
// 逗号
|
||||
commaToken,
|
||||
}
|
||||
preCheck := false
|
||||
for _, item := range tokenList {
|
||||
if item == inputChar {
|
||||
preCheck = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !preCheck {
|
||||
// 输入一定不是关键字
|
||||
return false
|
||||
}
|
||||
|
||||
if len(tmpStr) == 0 && inputChar == keyLeftRightToken {
|
||||
// 双引号关键字
|
||||
return true
|
||||
@ -130,7 +161,7 @@ func (l *lexical) inputCharIsToken(inputChar string, tmpStr string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
tmpStrType := l.getTpmStrType(tmpStr)
|
||||
tmpStrType := l.getTmpStrType(tmpStr)
|
||||
// , 是关键字的场景
|
||||
// {"name":"zhangsan", "age":"18"}
|
||||
// [{"name":"zhangsan", "age":"18"}, {"name":"zhangsan", "age":"18"}]
|
||||
@ -220,7 +251,7 @@ func (l *lexical) inputCharIsToken(inputChar string, tmpStr string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (l *lexical) getTpmStrType(tmpStr string) string {
|
||||
func (l *lexical) getTmpStrType(tmpStr string) string {
|
||||
var preNode *lexicalNode
|
||||
if len(l.lexicalResult) > 0 {
|
||||
preNode = l.lexicalResult[len(l.lexicalResult)-1]
|
||||
|
Loading…
Reference in New Issue
Block a user