antlr / antlr4-lab

A client/server for trying out and learning about ANTLR
MIT License
39 stars 11 forks source link

BAD JSON RESPONSE with a parser and no lexer on lab site. #58

Closed Kiroto closed 2 years ago

Kiroto commented 2 years ago

On the lab site. There is nothing on the lexer tab.

The tool console returns BAD JSON RESPONSE when I click the run button. I understand this issue has to do with the server and not my code (let me know if I'm wrong about this!)

Parser contents ```antlr4 grammar program; program: book EOF; book: entry+; entry: receta porciones (tiempoprep)? (tiempococ)? calorias ingredientes elaboracion; receta: LINE_START REC_LBL SEP nombre_receta NL; nombre_receta: TEXT; porciones: LINE_START POR_LBL SEP cantidad_porciones WS unidad_porciones NL; cantidad_porciones: NUMBER; unidad_porciones: TEXT; tiempoprep: LINE_START TMP_LBL SEP tiempo NL; tiempococ: LINE_START TMC_LBL SEP tiempo NL; tiempo: NUMBER WS TEXT; calorias: LINE_START CAL_LBL SEP calorias_text NL; calorias_text: NUMBER WS TEXT; ingredientes: LINE_START ING_LBL SEP NL ingredient_list NL; ingredient_list: ingredient_list_item (COM NL ingredient_list_item)*; ingredient_list_item: TAB amount WS ingredient_name; amount: NUMBER; ingredient_name: TEXT; elaboracion: LINE_START ELA_LBL SEP NL (elaboration_list)+ NL?; elaboration_list: elaboration_list_item (NL elaboration_list_item)*; elaboration_list_item: INT L_SEP TEXT; LINE_START: GUION WS; GUION: '-'; REC_LBL: 'RECETA'; POR_LBL: 'PORCIONES'; TMP_LBL: 'TIEMPO PREPARACION'; TMC_LBL: 'TIEMPO COCCION'; CAL_LBL: 'CALORIAS'; ING_LBL: 'INGREDIENTES'; ELA_LBL: 'ELABORACION'; FEC_LBL: 'FECHA'; HOR_LBL: 'HORA'; DUR_LBL: 'DURACION'; TEM_LBL: 'TEMA'; L_SEP: ')'; COM: ','; SEP: ':'; WS: ' '+; NL: '\n'; TAB: '\t'; NUMBER: INT | FLOAT; INT: [0-9]+; FLOAT: [0-9]+ '.' [0-9]+; LISTA: [0-9]+ ')'; TEXT: WORD (WS WORD)*; WORD: [A-Za-z_]+; ```
Input ``` - RECETA: Pudin de pan - PORCIONES: 3 personas - TIEMPO PREPARACION: 20 min - TIEMPO COCCION: 60 min - CALORIAS: 535 kcal - INGREDIENTES: 2.5 tazas leche evaporada, 2 huevos, 2 cucharadita extracto de vainilla, 1 cucharadita canela en polvo, 0.5 cucharadita jengibre rallado o en polvo, 0.5 cucharadita clavo dulce en polvo, 0.25 cucharadita sal, 0.5 taza azucar morena, 3 tazas pan viejo en trocitos, 0.25 taza pasas, 0.25 taza mantequilla - ELABORACION: 1) Buscar una licuadora 2) Echar todos los liquidos 3) Echar todos los solidos 4) Licuar 5) Beberselo en el vaso de la licuadora 6) Fin - RECETA: Pudin de pan - PORCIONES: 2 jartones - CALORIAS: 2000 calorias - INGREDIENTES: 2 Pizzas Grandes de Pizza Hut - ELABORACION: 1) Colocar la Pizza en la mesa 2) Comersela ```

Looking at the console, there's some text Bad JSON: followed by a JSON too big to add here. Let me know if you need more information regarding this.

Kiroto commented 2 years ago

Here's another situation that returns similar results, this time with a lexer. I got this while playing around with the sample.

Lexer contents ```antlr4 // DELETE THIS CONTENT IF YOU PUT COMBINED GRAMMAR IN Parser TAB lexer grammar ExprLexer; OP : '+' | '-' | '*' | '/'; AND : 'and' ; OR : 'or' ; NOT : 'not' ; EQ : '=' ; COMMA : ',' ; SEMI : ';' ; LPAREN : '(' ; RPAREN : ')' ; LCURLY : '{' ; RCURLY : '}' ; INT : [0-9]+ ; TEXT: [a-zA-Z_0-9]+; ID: [a-zA-Z_][a-zA-Z_0-9]* ; WS: [ \t\n\r\f]+ -> skip ; STR_DEL: '"'; ```
Parser contents ```antlr4 parser grammar ExprParser; options { tokenVocab=ExprLexer; } program : (stat | def)* EOF ; stat: (assignment | func) SEMI ; assignment : ID EQ expr; def : ID '(' ID (',' ID)* ')' '{' stat* '}' ; expr: ID | INT | str | func | 'not' expr | expr 'and' expr | expr 'or' expr | expr OP expr ; func : ID LPAREN (expr (',' expr)*)? RPAREN ; str : '"' TEXT? '"'; ```
Input ``` f(x,y) { a = 3+foo; b = foo * bar; z = x and y; rank = zz("banana"); zz(); } banana = richi; ```

It, however, (doesn't) work(s) as expected if I change the lexer to the following (Moving the TEXT below the ID).

Lexer contents ```antlr4 // DELETE THIS CONTENT IF YOU PUT COMBINED GRAMMAR IN Parser TAB lexer grammar ExprLexer; OP : '+' | '-' | '*' | '/'; AND : 'and' ; OR : 'or' ; NOT : 'not' ; EQ : '=' ; COMMA : ',' ; SEMI : ';' ; LPAREN : '(' ; RPAREN : ')' ; LCURLY : '{' ; RCURLY : '}' ; INT : [0-9]+ ; ID: [a-zA-Z_][a-zA-Z_0-9]* ; TEXT: [a-zA-Z_0-9]+; WS: [ \t\n\r\f]+ -> skip ; STR_DEL: '"'; ```
parrt commented 2 years ago

hi. yes, I believe this is caused by the same bug we've had that we are generating improper Json.

parrt commented 2 years ago

Fixed by https://github.com/antlr/antlr4-lab/pull/59