1414import liquidjava .rj_language .ast .LiteralString ;
1515import liquidjava .rj_language .ast .UnaryExpression ;
1616import liquidjava .rj_language .ast .Var ;
17+ import liquidjava .rj_language .parsing .ParsingException ;
1718import liquidjava .utils .Utils ;
1819
1920import org .antlr .v4 .runtime .tree .ParseTree ;
@@ -63,7 +64,7 @@ public CreateASTVisitor(String prefix) {
6364 this .prefix = prefix ;
6465 }
6566
66- public Expression create (ParseTree rc ) {
67+ public Expression create (ParseTree rc ) throws ParsingException {
6768 if (rc instanceof ProgContext )
6869 return progCreate ((ProgContext ) rc );
6970 else if (rc instanceof StartContext )
@@ -84,20 +85,20 @@ else if (rc instanceof LiteralContext)
8485 return null ;
8586 }
8687
87- private Expression progCreate (ProgContext rc ) {
88+ private Expression progCreate (ProgContext rc ) throws ParsingException {
8889 if (rc .start () != null )
8990 return create (rc .start ());
9091 return null ;
9192 }
9293
93- private Expression startCreate (ParseTree rc ) {
94+ private Expression startCreate (ParseTree rc ) throws ParsingException {
9495 if (rc instanceof StartPredContext )
9596 return create (((StartPredContext ) rc ).pred ());
9697 // alias and ghost do not have evaluation
9798 return null ;
9899 }
99100
100- private Expression predCreate (ParseTree rc ) {
101+ private Expression predCreate (ParseTree rc ) throws ParsingException {
101102 if (rc instanceof PredGroupContext )
102103 return new GroupExpression (create (((PredGroupContext ) rc ).pred ()));
103104 else if (rc instanceof PredNegateContext )
@@ -112,7 +113,7 @@ else if (rc instanceof IteContext)
112113 return create (((PredExpContext ) rc ).exp ());
113114 }
114115
115- private Expression expCreate (ParseTree rc ) {
116+ private Expression expCreate (ParseTree rc ) throws ParsingException {
116117 if (rc instanceof ExpGroupContext )
117118 return new GroupExpression (create (((ExpGroupContext ) rc ).exp ()));
118119 else if (rc instanceof ExpBoolContext ) {
@@ -124,7 +125,7 @@ else if (rc instanceof ExpBoolContext) {
124125 }
125126 }
126127
127- private Expression operandCreate (ParseTree rc ) {
128+ private Expression operandCreate (ParseTree rc ) throws ParsingException {
128129 if (rc instanceof OpLiteralContext )
129130 return create (((OpLiteralContext ) rc ).literalExpression ());
130131 else if (rc instanceof OpArithContext )
@@ -143,7 +144,7 @@ else if (rc instanceof OpGroupContext)
143144 return null ;
144145 }
145146
146- private Expression literalExpressionCreate (ParseTree rc ) {
147+ private Expression literalExpressionCreate (ParseTree rc ) throws ParsingException {
147148 if (rc instanceof LitGroupContext )
148149 return new GroupExpression (create (((LitGroupContext ) rc ).literalExpression ()));
149150 else if (rc instanceof LitContext )
@@ -158,20 +159,22 @@ else if (rc instanceof VarContext) {
158159 }
159160 }
160161
161- private Expression functionCallCreate (FunctionCallContext rc ) {
162+ private Expression functionCallCreate (FunctionCallContext rc ) throws ParsingException {
162163 if (rc .ghostCall () != null ) {
163164 GhostCallContext gc = rc .ghostCall ();
164- List <Expression > le = getArgs (gc .args ());
165165 String name = Utils .qualifyName (prefix , gc .ID ().getText ());
166- return new FunctionInvocation (name , le );
166+ List <Expression > args = getArgs (gc .args ());
167+ if (args .isEmpty ())
168+ throw new ParsingException ("Function call cannot have empty arguments" );
169+ return new FunctionInvocation (name , args );
167170 } else {
168171 AliasCallContext gc = rc .aliasCall ();
169- List <Expression > le = getArgs (gc .args ());
170- return new AliasInvocation (gc .ID_UPPER ().getText (), le );
172+ List <Expression > args = getArgs (gc .args ());
173+ return new AliasInvocation (gc .ID_UPPER ().getText (), args );
171174 }
172175 }
173176
174- private List <Expression > getArgs (ArgsContext args ) {
177+ private List <Expression > getArgs (ArgsContext args ) throws ParsingException {
175178 List <Expression > le = new ArrayList <>();
176179 if (args != null )
177180 for (PredContext oc : args .pred ()) {
@@ -180,7 +183,7 @@ private List<Expression> getArgs(ArgsContext args) {
180183 return le ;
181184 }
182185
183- private Expression literalCreate (LiteralContext literalContext ) {
186+ private Expression literalCreate (LiteralContext literalContext ) throws ParsingException {
184187 if (literalContext .BOOL () != null )
185188 return new LiteralBoolean (literalContext .BOOL ().getText ());
186189 else if (literalContext .STRING () != null )
0 commit comments