by LoSboccacc · 7y ago · 0 comments
as for the solution, one can get a premade grammar and query the ast
And in any case, neither comments nor CDATA sections nest, so the is no problem handling them at the lexical analysis stage.
As for "get a premade grammar" - what does that mean? Do you mean use a tool like Lex? AFAIK Lex uses regular expressions.
and no I mean tool like antlr or javacc which build an in memory syntax tree you can query or observe.
https://github.com/antlr/grammars-v4/blob/72810b7c59bb481750...
this is different than querying the document as XML, since an empty node is equivalent to an empty element, but they differ in the syntax, so querying the syntax tree allowed you to know because it produces a TAG_SLASH_CLOSE
regex are ok for text that's context free, so they match perfectly for the lexing°. once you need context then are back to whacky hacks, layers and loops of regexes or preparser that remove the hard part out of the content - basically you're rolling your own grammar except manually, on the wrong toolchain and on your own.
"can I build my raster engine to draw poligons on screen" "well yes but is going to cost a lot of time, be error prone and miss a lot of features from ready to use solutions"
°you can actually put token production in the lexer itself between expressions, so they can already handle more than plain rexeg even in lexing.