From 8d2e9c93ae372cf15c324e1a69def9329f3f8d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 5 Jul 2022 11:34:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=85=B3=E9=94=AE=E5=AD=97?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lexical.go | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/lexical.go b/lexical.go index 77e062e..5dcd4fd 100644 --- a/lexical.go +++ b/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]