antlr4

How to throw meaningful error on syntax or parsing error [duplicate]

家住魔仙堡 提交于 2020-03-28 07:06:50
问题 This question already has answers here : Is there a way to easily adapt the error messages of ANTLR4? (2 answers) Closed 10 days ago . I have a grammar for parsing jcl The jcl looks like below /*comment line //PR1290@ JOB (10),'ISPW COB SN900E' lexer and parser is working perfectly fine. Suppose instead of // if jcl starts from / currently lexer is throwing 1:0 token recognition error at: '/P' Parser will throw no viable alternative input R1290@ JOB I am looking for throwing error similar to

How to use antlr if an error with fs occurs?

人盡茶涼 提交于 2020-03-25 09:23:23
问题 I have actually a problem with antlr. I use angular in visual studio code. I know how to include and write a grammar in a project. However, now I faced the problem that an error occurs while starting it: "ERROR in ./node_modules/antlr4/CharStreams.js Module not found: Error: Can't resolve 'fs' in 'C:\Users\simon\antlrTestProject\node_modules\antlr4' ERROR in ./node_modules/antlr4/FileStream.js Module not found: Error: Can't resolve 'fs' in 'C:\Users\simon\antlrTestProject\node_modules\antlr4'

How to write Antlr rules in a non-recursive way?

一笑奈何 提交于 2020-02-25 22:46:33
问题 I have the following the expressions I need to parse and(true, false) or(true, false, true) not(or(true, false, true)) and(and(true, false), false) or(or(true, false, true), true) so far I have the following grammar expr : orExpr ; orExpr : OR '(' andExpr (',' andExpr)+ ')' | andExpr ; andExpr : AND '(' equalityExpr (',' equalityExpr)+ ')' | equalityExpr ; equalityExpr : comparison ((EQUALS | NOT_EQUALS) comparison)* ; comparison : notExpr ((GREATER_THAN_EQUALS | LESS_THAN_EQUALS | GREATER

How to write Antlr rules in a non-recursive way?

百般思念 提交于 2020-02-25 22:44:51
问题 I have the following the expressions I need to parse and(true, false) or(true, false, true) not(or(true, false, true)) and(and(true, false), false) or(or(true, false, true), true) so far I have the following grammar expr : orExpr ; orExpr : OR '(' andExpr (',' andExpr)+ ')' | andExpr ; andExpr : AND '(' equalityExpr (',' equalityExpr)+ ')' | equalityExpr ; equalityExpr : comparison ((EQUALS | NOT_EQUALS) comparison)* ; comparison : notExpr ((GREATER_THAN_EQUALS | LESS_THAN_EQUALS | GREATER

Semantic lexer predicate performance

筅森魡賤 提交于 2020-02-22 05:49:38
问题 I have a lexer creates MACRO tokens for a dynamic list of macro strings passed to the lexer. I used a semantic predicate in the very top lexer rule to implement this feature: MACRO: { macros != null && tryMacro() }? .; Where tryMacro() just checks if any macro string matches the input sequence. The performance of this approach was very bad and after some research I tried changing the lexer rule to the following: MACRO: . { macros != null && tryMacro() }?; This severely improved the

Semantic lexer predicate performance

泪湿孤枕 提交于 2020-02-22 05:49:06
问题 I have a lexer creates MACRO tokens for a dynamic list of macro strings passed to the lexer. I used a semantic predicate in the very top lexer rule to implement this feature: MACRO: { macros != null && tryMacro() }? .; Where tryMacro() just checks if any macro string matches the input sequence. The performance of this approach was very bad and after some research I tried changing the lexer rule to the following: MACRO: . { macros != null && tryMacro() }?; This severely improved the

Semantic lexer predicate performance

孤者浪人 提交于 2020-02-22 05:48:27
问题 I have a lexer creates MACRO tokens for a dynamic list of macro strings passed to the lexer. I used a semantic predicate in the very top lexer rule to implement this feature: MACRO: { macros != null && tryMacro() }? .; Where tryMacro() just checks if any macro string matches the input sequence. The performance of this approach was very bad and after some research I tried changing the lexer rule to the following: MACRO: . { macros != null && tryMacro() }?; This severely improved the

Why does the order of ANTLR4 tokens matter?

无人久伴 提交于 2020-02-04 03:35:46
问题 I have a simple grammar that will eventually parse YANG source. When I make when seem to be an arbitrary change the location of the MODULE token the IntelliJ ANTLR4 Plugin can/cannot parse my input. The input string to be parsed: module x { } Here is the grammar that works without any error: grammar Yang ; yang: module_open module_close; module_open : MODULE ID BRACKET_OPEN ; module_close: BRACKET_CLOSE ; MODULE: 'module' ; ID: ([A-Za-z][A-Za-z0-9_-]*) ; BRACKET_OPEN: '{' ; BRACKET_CLOSE: '}'

Trying to use keywords as identifiers in ANTLR4; not working

北城以北 提交于 2020-02-03 10:16:05
问题 I'm trying to get some sql keywords to be accepted as identifiers, when used as identifiers. The Antlr book p210 suggests this trick: id : 'if' | 'call' | 'then' | ID ; I've got something similar but it's not working and I assume it's a misunderstanding on my part. regular_ident is the parse rule for an identifier thus: regular_ident : // (1) KEYWORD_AS_IDENT | REGULAR_IDENT ; REGULAR_IDENT is the main lex rule for idents. It's roughly this (simplified here), and it works: REGULAR_IDENT : [a

Uncaught ReferenceError: ___ is not defined - typescript

有些话、适合烂在心里 提交于 2020-01-25 20:53:08
问题 I am getting "Uncaught ReferenceError: ___ is not defined" in typescript at runtime even though the class is defined in the same file and exported. Please guide. Update : I was able to fix this issue by changing the order of exported class. That means I defined ExpressionContext class before it's used. It's a dirty way since it's a generated code and I don't want to touch it. I would like to understand why it's failing. 来源: https://stackoverflow.com/questions/43765160/uncaught-referenceerror