Skip to content

Commit

Permalink
optimize: optimize parser to support empty annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyJavaBean committed Nov 17, 2023
1 parent 0e4d8ea commit 9275188
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 5 additions & 1 deletion parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct s {
2: string f2 ( a = "a", b = "" );
3: string (str = "str") f3;
4: string f4;
5: string f5 ();
6: string f6 ( );
} (
xxx = "",
yyy = "y",
Expand Down Expand Up @@ -104,7 +106,7 @@ func TestAnnotation(t *testing.T) {
test.Assert(t, has(ast.Structs[0].Annotations, "xxx", ""))
test.Assert(t, has(ast.Structs[0].Annotations, "yyy", "y"))
test.Assert(t, has(ast.Structs[0].Annotations, "zzz", "zzz"))
test.Assert(t, len(ast.Structs[0].Fields) == 4)
test.Assert(t, len(ast.Structs[0].Fields) == 6)
test.Assert(t, len(ast.Structs[0].Fields[0].Annotations) == 1)
test.Assert(t, len(ast.Structs[0].Fields[1].Annotations) == 2)
test.Assert(t, len(ast.Structs[0].Fields[2].Annotations) == 0)
Expand All @@ -113,6 +115,8 @@ func TestAnnotation(t *testing.T) {
test.Assert(t, has(ast.Structs[0].Fields[1].Annotations, "a", "a"))
test.Assert(t, has(ast.Structs[0].Fields[1].Annotations, "b", ""))
test.Assert(t, has(ast.Structs[0].Fields[2].Type.Annotations, "str", "str"))
test.Assert(t, ast.Structs[0].Fields[4].Annotations == nil)
test.Assert(t, ast.Structs[0].Fields[5].Annotations == nil)

test.Assert(t, len(ast.Exceptions) == 1)
test.Assert(t, len(ast.Exceptions[0].Annotations) == 1)
Expand Down
2 changes: 1 addition & 1 deletion parser/thrift.peg
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ DoubleConstant <- Skip <[+\-]? (

Exponent <- ('e' / 'E') IntConstant

Annotations <- LPAR Annotation+ RPAR
Annotations <- LPAR Annotation* RPAR

Annotation <- Identifier EQUAL Literal ListSeparator?

Expand Down
5 changes: 1 addition & 4 deletions parser/thrift.peg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9275188

Please sign in to comment.