词法分析树增加String()方法
This commit is contained in:
23
lexical.go
23
lexical.go
@ -41,13 +41,13 @@ type lexical struct {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:11 2022/7/4
|
||||
func (l *lexical) Parse(jsonData string) ([]*lexicalNode, error) {
|
||||
func (l *lexical) Parse() error {
|
||||
// mt.Println(jsonData)
|
||||
if len(jsonData) < 2 {
|
||||
return nil, errors.New("input data is not json")
|
||||
if len(l.jsonData) < 2 {
|
||||
return errors.New("input data is not json")
|
||||
}
|
||||
tmpStr := ""
|
||||
for _, itemChar := range jsonData {
|
||||
for _, itemChar := range l.jsonData {
|
||||
currentChar := string(itemChar)
|
||||
tmpRealVal, tmpStrType := l.getTmpStrType(tmpStr)
|
||||
if l.inputCharIsToken(currentChar, tmpStr, tmpStrType) {
|
||||
@ -83,7 +83,7 @@ func (l *lexical) Parse(jsonData string) ([]*lexicalNode, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return l.lexicalResult, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// inputCharIsToken 输入字符是否为关键字
|
||||
@ -272,3 +272,16 @@ func (l *lexical) getTmpStrType(tmpStr string) (interface{}, string) {
|
||||
}
|
||||
return tmpStr, "string"
|
||||
}
|
||||
|
||||
// String 将解析后的词法, 转换为字符串
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:34 2022/7/5
|
||||
func (l *lexical) String() string {
|
||||
str := ""
|
||||
for _, item := range l.lexicalResult {
|
||||
str = str + item.ValStr()
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
Reference in New Issue
Block a user