<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head><body ><div style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt;"><div>Hi Folks,<br></div><div><br></div><div>In XTreams parsing, the grammarWiki/PEGWikiGenerator combo do not parse the Wikimedia headings.<br></div><div> I have copied the grammarWiki to grammarWikiMedia and I am slowly building it up in an attempt to isolate the problem.<br></div><div>Grammar looks like this:<br></div><div><br></div><div><br></div><div><blockquote style="border: 1px solid rgb(204, 204, 204); padding: 7px; background-color: rgb(245, 245, 245);"><div>grammarWikiMedia<br></div><div>"<br></div><div><a target="_blank" href="http://en.wikipedia.org/wiki/Help:Wiki_markup">http://en.wikipedia.org/wiki/Help:Wiki_markup</a><br></div><div>"<br></div><div>^<br></div><div>'Page <- (Heading)*<br></div><div><br></div><div>LineCharacter <- [^\n]<br></div><div>Flow <- Escape / Bold / Italic / LinkShort / LinkFull / LineCharacter<br></div><div>Escape <- "**" / "__" / "[["<br></div><div>Bold <- "*" Flow{"*"}<br></div><div>Italic <- "_" Flow{"_"}<br></div><div>LinkShort <- "[" .{&[>\]]} "]"<br></div><div>LinkFull <- "[" Flow{">"} .{"]"}<br></div><div><br></div><div>Line <- Flow{1,"\n"}<br></div><div>Paragraph <- Line<br></div><div>Empty <- "\n"<br></div><div>Whitespace <- [\t\s]*<br></div><div><br></div><div>Heading         <-   Heading6 /  Heading5 / Heading4 / Heading3 / Heading2 / Heading1<br></div><div>Heading1  <-   Whitespace "= " Flow{" ="}<br></div><div>Heading2 <-   Whitespace "== " Flow{" =="}<br></div><div>Heading3       <-   Whitespace "=== " Flow{" ==="}<br></div><div>Heading4     <-   Whitespace "==== " Flow{" ===="}<br></div><div>Heading5   <-   Whitespace "===== " Flow{" ====="}<br></div><div>Heading6 <-   Whitespace "====== " Flow{" ======"}<br></div><div><br></div><div>'<br></div></blockquote><br></div><div><br></div><div><br></div><div><div>For the Actor, I have copied the PEGWikiGenerator, saving it as PEGWikiMediaGenerator. I have made some minor additions to support H5 and H6 heading levels per Wikimedia standards.<br></div><div>My problem, is that Wikimedia seems to like to wrap its <hN></hN> tags within a paragraph: <p><hN></hN></p><br></div><div>So, while I can parse this input just ducky:<br></div><div><br></div></div><div><blockquote style="border: 1px solid rgb(204, 204, 204); padding: 7px; background-color: rgb(245, 245, 245);"><div>| wikiGrammar wikiParser input output | <br></div><div>wikiGrammar := PEGParser grammarWikiMedia reading positioning. "This is your grammar converted to an xtream."<br></div><div>wikiParser := PEGParser parserPEG parse: 'Grammar' stream: wikiGrammar actor: PEGParserParser new. "This is the parser generated from your grammar."<br></div><div>input := ' = Heading 1 =  == Heading 2 == === Heading 3 === ==== Heading 4 ==== ===== Heading 5 ===== ====== Heading 6 ======'.<br></div><div>output := wikiParser parse: 'Page' stream: input actor: PEGWikiMediaGenerator new. "An actual compiler doing the most basic stuff."<br></div><div>output inspect.<br></div></blockquote><div>Producing an XMLElement looking like this:<br></div><div><br></div><div><br></div><blockquote style="border: 1px solid rgb(204, 204, 204); padding: 7px; background-color: rgb(245, 245, 245);"><div><div><h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><h5>Heading 5</h5><h6>Heading 6</h6></div><br></div></blockquote></div><div>When I wrap the <hn> elements in <p> tags for this input...<br></div><div><br></div><div><br></div><div><blockquote style="border: 1px solid rgb(204, 204, 204); padding: 7px; background-color: rgb(245, 245, 245);"><div>| wikiGrammar wikiParser input output | <br></div><div>wikiGrammar := PEGParser grammarWikiMedia reading positioning. "This is your grammar converted to an xtream."<br></div><div>wikiParser := PEGParser parserPEG parse: 'Grammar' stream: wikiGrammar actor: PEGParserParser new. "This is the parser generated from your grammar."<br></div><div>input := '<p>= Heading 1 =</p>  <p>== Heading 2 ==</p> <p>=== Heading 3 ===</p> <p>==== Heading 4 ====</p> <p>===== Heading 5 =====</p> <p> ====== Heading 6 ======</p>'.<br></div><div>output := wikiParser parse: 'Page' stream: input actor: PEGWikiMediaGenerator new. "An actual compiler doing the most basic stuff."<br></div><div>output inspect.<br></div></blockquote><div>my XMLElement looks like this:<br></div><div><br></div><blockquote style="border: 1px solid rgb(204, 204, 204); padding: 7px; background-color: rgb(245, 245, 245);"><div><div/><br></div></blockquote></div><div><br></div><div>I am supposing that I have a wayward Grammar specification.<br></div><div><br></div><div>Where should I focus?<br></div><div><br></div><div>Should I hack at <blockquote style="border: 1px solid rgb(204, 204, 204); padding: 7px; background-color: rgb(245, 245, 245);"><div>Heading1 <-   Whitespace "= " Flow{" ="}<br></div><meta content="text/html; charset=utf-8"></blockquote></div><div>and change "Whitespace" to something else ?<br></div><div><br></div><div>Or should I redefine the <br></div><div><br></div><div><blockquote style="border: 1px solid rgb(204, 204, 204); padding: 7px; background-color: rgb(245, 245, 245);"><div><blockquote style="border: 1px solid rgb(204, 204, 204); padding: 7px; background-color: rgb(245, 245, 245);"><div>Line <- Flow{1,"\n"}<br></div><div>Paragraph <- Line<br></div></blockquote></div><meta content="text/html; charset=utf-8"></blockquote><br></div><div>duo?<br></div><div><br></div><div>If a general principle exists that will guide me going forward, I would very much appreciate it.<br></div><div><br></div><div>Thank you in advance.<br></div><div><br></div><div>t</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br></body></html>