Skip to content

Commit 037cad9

Browse files
lvan100lianghuan
authored andcommitted
111
1 parent 95a9627 commit 037cad9

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

lib/tidl/parser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ func ParseMeta(data []byte) (*MetaInfo, error) {
111111

112112
// Parse runs the parsing pipeline for a single IDL input.
113113
func Parse(data []byte) (doc Document, err error) {
114+
if data = bytes.TrimSpace(data); len(data) == 0 {
115+
return Document{}, nil
116+
}
117+
114118
e := &ErrorListener{
115119
Scanner: bufio.NewScanner(bytes.NewReader(data)),
116120
}

lib/vidl/parser.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func (e InnerExpr) Text() string {
108108

109109
// Parse parses the input string and returns an Expr AST.
110110
func Parse(data string) (expr Expr, err error) {
111+
if data = strings.TrimSpace(data); data == "" {
112+
return nil, nil
113+
}
114+
111115
e := &ErrorListener{Data: data}
112116

113117
// Recover from parser panics to provide better error reporting
@@ -132,7 +136,6 @@ func Parse(data string) (expr Expr, err error) {
132136
p := NewVParser(tokens)
133137
p.RemoveErrorListeners()
134138
p.AddErrorListener(e)
135-
p.GetInterpreter().SetPredictionMode(antlr.PredictionModeSLL) // Use faster SLL mode
136139

137140
// Step 3: Walk parse tree with custom listener
138141
l := &ParseTreeListener{

lib/vidl/parser_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,6 @@ func TestParse(t *testing.T) {
287287
input: "a + b",
288288
expectError: errors.New("line 1:2 token recognition error at: '+ ' << text: \"a + b\""),
289289
},
290-
{
291-
name: "syntax_error_empty",
292-
input: "",
293-
expectError: errors.New("line 1:0 mismatched input '<EOF>' expecting {'$', 'nil', '!', '(', STRING, INTEGER, FLOAT, IDENTIFIER} << text: \"\""),
294-
},
295290
{
296291
name: "syntax_error_missing_comma_in_function",
297292
input: "func(a b)",

0 commit comments

Comments
 (0)