Hi Jeff,<br><br><div class="gmail_quote">2009/3/23 jm <span dir="ltr"><<a href="mailto:jeffm@ghostgun.com">jeffm@ghostgun.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Say the lexer definition contains, among other things,<br>
<br>
Definitions.<br>
W = [^=\s\r\n]<br>
WS = \s<br>
CR = \r<br>
NL = \n<br>
EQ = =<br>
<br>
Rules.<br>
{W}+ : {token, {word, TokenLine, TokenChars}}.<br>
{EQ} : {token, {eq, TokenLine, TokenChars}}.<br>
{WS}+ : {token, {ws, TokenLine, TokenChars}}.<br>
({CR}|{NL}|{CR}{NL}) : {token, {nl, TokenLine, TokenChars}}.<br>
<br>
<br>
At the moment, the yecc definition file contains,<br>
<br>
Nonterminals<br>
request lines line lhs rhs words.<br>
<br>
Terminals<br>
eq word ws nl.<br>
<br>
Rootsymbol request.<br>
request -> lines : '$1'.<br>
<br>
lines -> line nl : ['$1'].<br>
lines -> line lines nl : ['$1'] ++ '$3'.<br>
<br>
line -> lhs eq rhs nl : {line, '$1', '$3'}.<br>
<br>
lhs -> word : {lhs, '$1'}.<br>
<br>
rhs -> words : {rhs, '$1'}.<br>
<br>
words -> word : ['$1'].<br>
words -> word ws words : ['$1', '$2'] ++ '$3'.<br>
<br>
<br>
and is designed to parse the postfix policy request (see<br>
<a href="http://www.postfix.org/SMTPD_POLICY_README.html" target="_blank">http://www.postfix.org/SMTPD_POLICY_README.html</a>)<br>
<br>
A couple of questions:<br>
<br>
1) What do I put in the yecc file so the it can spot a double newline<br>
which is used to terminate a request?</blockquote><div><br>Just of the top of my head I think you could do it by defining:<br><br>request -> lines nl : {request,'$1'}.<br><br>lines -> line : ['$1'].<br>
lines -> lines line : '$1' ++ ['$2'].<br><br>line -> lhs eq rhs nl : {line, '$1', '$3'}.<br><br>I think this will do it assuming you only allow one blank line between requests and you always have one blank line after a request, even after the last one. Sitting at a conference now so I will try it later tonight.<br>
<br>Robert<br><br></div></div>