java - ANTLR 4 Not all tokens being displayed -
this obvious question can't seem find on it. @ moment have grammar type in simple commands broken down html later via java
grammar cocodemol; r : file; file : line* ; line : newtype | assignment | clear (linebreak)? | end (linebreak)? ; newtype : types space num* space? '=' space? 'new' space types (linebreak)? ; assignment : num* '.' variables space? '=' space? nums* (linebreak)? ; types : 'body' | 'div' | 'span' | 'html' ; variables : 'width' | 'height' | 'background' | 'margin' | 'margin-left' | 'margin-right' | 'margin-top' | 'margin-bottom' | 'padding' | 'padding-left' | 'padding-right' | 'padding-top' | 'padding-bottom' | 'float' ; declarations : 'new' ; end : 'end' (linebreak)? ; clear : 'clear' (linebreak)? ; num : ([0-9]|'a'..'z'|'a'..'z')+; nums : ([0-9]|'a'..'z'|'a'..'z'|' ')+; space : ' ' ; linebreak : '\r'? '\n' | '\r' ;
this used in conjunction java read file containing:
body body = new body body.margin = 0 body.padding = 0 div container = new div container.width = 900px container.margin = 0 auto div header = new div header.width = 890px header.padding = 0px end div leftbox = new div leftbox.width = 200px leftbox.float = left end div rightbox = new div rightbox.width = 700px rightbox.float = right end clear end end
but when loop through lexer print tokens, receive assignment, newtype, clear , end, contain lines. wanted tokens bit more in-depth , tell java type each of words matched (num, variable etc) lines (assignment, newtype, clear , end) seem ones showing up.
any suggestions? (i know grammar tacky, first attempt while try learn language)
you have asked antlr match tokens, such newtype. use newtype parser rule not lexer rule.
Comments
Post a Comment