compiler construction - Markdown blockquote parsing with ANTLR -
this has been that's been bothering me while. how 1 go parsing following text html below using antlr? can't seem wrap head around @ all.
any ideas?
markdown:
> first line > second line > > nested quote
output html:
<blockquote>   <p>first line   second line</p>   <blockquote>     <p>nested quote</p>   </blockquote> </blockquote>      
funny mention because tackling problem last week. see jmd, markdown , brief overview of parsing , compilers. i'm working on true markdown parser , tried antlr.
there couple of ways can deal this.
firstly parse:
block_quote : '>' (' ' | '\t')? ;   and work out in parsing step, possibly rewrite rule.
thing these important when appear @ beginning of line here approach:
@members {   int quotedepth = 0; }  block_quote : '\n' (q+='>' (' ' | '\t')?)+   { if ($q.size() > quotedepth) /* emit 1 or more start_quote tokens */     else if ($q.size() < quotedepth /* emit 1 or more end_quote tokens */     quotedepth = $q.size(); }   the above may need parser rule rather lexical rule too. forget.
but unsatisfying because sort of forces treat markdown source sequence of lines, isn't want in other parts.
also each lexical rule can result in 1 token have overwrite class escapes me allow emitting multiple tokens. there example of in (excellent , required) the definitive antlr reference: building domain-specific languages.
ultimately abandoned antlr tool of choice this. own hand-coded solution should appearing in next week or two.
Comments
Post a Comment