ANTLR validate wrong string

9 views
Skip to first unread message

Люблю Пиво

unread,
Sep 16, 2017, 2:36:08 PM9/16/17
to antlr-discussion

I have following antlr 4.7 grammar. It needs to validate open and closed quotes, brckets and so on. So, string like '"(" will not validate, but it is. Antlr plug-in of intellij Idea and Eclipse can't build syntax tree and show me where I'm wrong.

So, where is my problem? Please, see grammar bellow. What I need to do to make the string not validatable and why antlr plug-in can't build the syntax tree for it?


grammar WellFormedGrammarValidator; main_program : ( string | string_one_quote | expression | multiline_comment | xml_comment | one_line_comment | EscapeSequence )* ; one_line_comment : ONE_LINE_COMMENT ; multiline_comment : MULTILINE_COMMENT ; xml_comment : XML_COMMENT ; string : QUOTED ; string_one_quote : QUOTED_SINGLE ; expression : not_string_term | '{' ( main_program? ) '}' | '[' ( main_program? ) ']' | '(' ( main_program? ) ')' ; not_string_term : NOT_STRING_CHAR+ ; NOT_STRING_CHAR : ( ~['"'] ) | '|' ; QUOTED : '"' StringCharacters? '"' | CharacterLiteral ; QUOTED_SINGLE : '\'' StringCharactersOneQuote '\'' ; CharacterLiteral : '\'' SingleCharacter '\'' | '\'' EscapeSequence '\'' ; fragment SingleCharacter : ~['\\] ; fragment StringCharacters : StringCharacter+ ; fragment StringCharactersOneQuote : StringCharacterOneQuote+ ; StringCharacterOneQuote : ( ~'\'' ) | '\\\\\'' | EscapeSequence ; fragment StringCharacter : ( ~["] ) | '\\\\"' | EscapeSequence ; EscapeSequence : '\\' [btnfr"'\\] ; ONE_LINE_COMMENT : '#' ~[\r\n]* ; MULTILINE_COMMENT : '/*' .*? '*/' ; XML_COMMENT : '<!--' .*? '-->' ; WS : [ \t\r\n\u000C]+ -> skip ;

Reply all
Reply to author
Forward
0 new messages