<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Regarding my question about how to call different machines from the same file, I found a June 7 post on this list that answered my question.<div><br></div><div><span class="Apple-style-span" style="font-family: arial; "><font face="Courier, Monospaced" class="fixed_width" style="font-family: fixed-width, monospace; font-size: 100%; "></font></span></div><blockquote type="cite"><div><span class="Apple-style-span" style="font-family: arial; "><font face="Courier, Monospaced" class="fixed_width" style="font-family: fixed-width, monospace; font-size: 100%; ">You can pick and choose which machine to start when exec is called by <br>setting the cs variable to [machine name]_en_[machine definition]. <br><p>e.g: <br></p><p>int cs; <br>%%{ <br> machine foo; <br> bar := 'bar'; <br> baz := 'baz'; <br></p><div><br class="webkit-block-placeholder"></div><div id="qhide_867385" class="qt" style="display: block; ">}%% <br><br></div>%%write init; <br>cs = (condition) ? foo_bar : foo_baz; <br>%%write exec; <br></font><p><font face="Courier, Monospaced" class="fixed_width" style="font-family: fixed-width, monospace; font-size: 100%; ">Take care, <br>-Mitchell;</font></p></span></div></blockquote><div>But since I'm doing several ways of attribute parsing, I had to start a new file anyway, but now they can all be in the same file and share the same basic structure.</div><div><br><div><div>On Jun 17, 2008, at 1:04 AM, Erich Ocean wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><br>Jason,<br><br>Basically, you need one-token lookahead for that, which a straight <br>regex can't do. You might be able to use manual state transitions, but <br>it's easier to just separate the logic out into another function.<br><br>For example, you could capture the inner contents of the emphasized <br>string into a buffer and then call into a C function where you can run <br>the three (Ragel) machines in sequence, in the priority order you've <br>set. Use the first one that works and return into your original <br>scanner machine/function. Order them longest-match-first. :-)<br><br>Best, Erich<br><br>On Jun 16, 2008, at 8:15 PM, Jason Garber wrote:<br><br><blockquote type="cite">In RedCloth, we have a problem where an _emphasized_ bit of text can <br></blockquote><blockquote type="cite">have _(myclass#myid)a CSS class and/or id_ but shouldn't have a <br></blockquote><blockquote type="cite">class or id if the whole emphasis is in parentheses _(practically <br></blockquote><blockquote type="cite">speaking)_. Consider this example (simplified):<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">in: "before _(in parens)_ after"<br></blockquote><blockquote type="cite">expected: "<p>before <em>(in parens)</em> after</p>"<br></blockquote><blockquote type="cite">but was: "<p>before <em class=\"in parens\">in parens)</em> after</p>"<br></blockquote><blockquote type="cite">It simultaneously pursues the possibilities that the parenthesized <br></blockquote><blockquote type="cite">text is the class and that it's just regular parenthesized text <br></blockquote><blockquote type="cite">inside the em. When the class possibility doesn't work out, the <br></blockquote><blockquote type="cite">final state is the regular text part but the class has already been <br></blockquote><blockquote type="cite">captured.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">C = "(" ( [^)#]+ >A %{ STORE(class) } )? ("#" [^)]+ >A % <br></blockquote><blockquote type="cite">{STORE(id)} )? ")"<br></blockquote><blockquote type="cite">mtext = ( chars (mspace chars)* ) ;<br></blockquote><blockquote type="cite">em = "_" >X C? mtext >A %T :> "_" ;<br></blockquote><blockquote type="cite"># The >X resets the register from the last match, >A registers the <br></blockquote><blockquote type="cite">beginning of a string and the STORE saves it away.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I tried having the class info get written to a buffer that was then <br></blockquote><blockquote type="cite">captured with a leaving action, which works for the class part, but <br></blockquote><blockquote type="cite">I again run into the same problem with capturing the text because <br></blockquote><blockquote type="cite">the right side of the union matches also, so it captures too much <br></blockquote><blockquote type="cite">text. Whichever side of the vertical pipe writes last, wins.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">C = "(" ( [^)#]+ >A %{ STORE(class_buf) } )? ("#" [^)]+ >A % <br></blockquote><blockquote type="cite">{STORE(id_buf)} )? ")"<br></blockquote><blockquote type="cite">C_mtext = (C %{ STORE_ATTRIBUTES(); } mtext >A %{STORE(text)} | <br></blockquote><blockquote type="cite">mtext >B %{ STORE_B(text); });<br></blockquote><blockquote type="cite"># SET_ATTRIBUTES copies the attributes from their buffers and stores <br></blockquote><blockquote type="cite">them where they belong.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">results in...<br></blockquote><blockquote type="cite">expected: "<p><span class=\"myclass\">SPAN</span></p>"<br></blockquote><blockquote type="cite">but was: "<p><span class=\"myclass\">(myclass)SPAN</span></p>"<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Really what I want is for it to try the first pattern (with the C) <br></blockquote><blockquote type="cite">and, if that fails, try the second (the plain ol' mtext). Sounds <br></blockquote><blockquote type="cite">like a scanner to me. Problem is, I'm already inside a scanner, so <br></blockquote><blockquote type="cite">it won't let me call a scanner from within a pattern.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Got any ideas?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Jason<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><br><br><br><br></blockquote></div><br></div></body></html>