<!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 Levente.<br></div><div><br></div><div>Regarding my previous letter, I am almost certain that "consume" means a match has been made and eat the string.<br></div><div>"Yield" means  "invoke the callback" or "return the section of a AST for that rule.<br></div><div><br></div><div>anyhoo, I have been going through your old emails and cross checking with:<a href="https://nim-lang.org/docs/pegs.html" target="_blank">https://nim-lang.org/docs/pegs.html</a><br></div><div>and have come up with a preliminary "terse guide" to the syntax.<br></div><div><br></div><div>I would like to expand this into tests/examples for others to use going forward. Eventually this will make its way to a SqueakBook when/if I get some time.<br></div><div><br></div><div>Anyhoo, if you could peruse it and see if anything jumps out at you that is incorrect/incomplete. <br></div><div><br></div><div>Much appreciated.<br></div><div><br></div><div>t</div><div><br></div><div>p.s. I have cc'd squeak-dev in case anybody else finds this interesting.<br></div><div><br></div><div><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>XTreams<br></div><div><a target="_blank" href="https://code.google.com/archive/p/xtreams/wikis/Parsing.wiki">https://code.google.com/archive/p/xtreams/wikis/Parsing.wiki</a><br></div><div><a target="_blank" href="https://nim-lang.org/docs/pegs.html">https://nim-lang.org/docs/pegs.html</a><br></div><div><br></div><div><br></div><div>A  < - E <br></div><div>Rule:<br></div><div>Bind the expression  E  to the nonterminal symbol  A .<br></div><div>Left recursive rules are not possible and crash the matching engine.<br></div><div><br></div><div>\ddd <br></div><div>Character with decimal code ddd<br></div><div><br></div><div>\" , etc<br></div><div>Literal  " , etc.<br></div><div>PEG: Literal                            <-   QUOTE LiteralEntity{QUOTE}/     DOUBLE_QUOTE LiteralEntity{DOUBLE_QUOTE}<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>A ... Z <br></div><div>Sequence:<br></div><div>Apply expressions  A , ...,  Z , in this order, to consume consecutive portions of the text ahead, as long as they succeed.<br></div><div>Indicate success if all succeeded.<br></div><div>Otherwise do not consume any text and indicate failure.<br></div><div>The sequence's precedence is higher than that of Ordered Choice:  A B / C  means  (A B) / Z  and not  A (B / Z) .<br></div><div><br></div><div>A / ... / Z <br></div><div>Ordered Choice:<br></div><div>Apply expressions  A , ...,  Z , in this order, to the text ahead, until one of them succeeds and possibly consumes some text. Indicate success if one of expressions succeeded.<br></div><div>Otherwise do not consume any text and indicate failure.<br></div><div>The Ordered Choice precedence is lower than that of Sequence:  A B / C  means  (A B) / Z  and not  A (B / Z) .<br></div><div><br></div><div>(E) <br></div><div>Grouping:<br></div><div>Parenthesis can be used to change operator priority.<br></div><div>(A B) / Z  vs.  A (B / Z) .<br></div><div><br></div><div><br></div><div>{E}    <br></div><div>Cardinality:  Stop Expression<br></div><div>A <- B{C}<br></div><div>to accept A,  means, accept any number of B up until E comes.<br></div><div>Consume E too, but don't yield it.<br></div><div>So, such expression accepts: BE, BBE, BBBE, BBBBE, etc, and yields B, BB, BBB, BBBB, etc.<br></div><div><br></div><div>A <- B{1,"\n"}<br></div><div>means that a A consists of one or more Bs.<br></div><div>The parser will  read B's up until "\n" appears on the stream, which is a carriage return<br></div><div>character.<br></div><div><br></div><div>E?<br></div><div>Cardinality:<br></div><div>Zero or One  E<br></div><div><br></div><div><br></div><div>E* <br></div><div>Cardinality<br></div><div>Zero or more: E<br></div><div>Apply expression  E  repeatedly to match the text ahead, as long as it succeeds.<br></div><div>Consume the matched text (if any).<br></div><div>Always indicate success.<br></div><div><br></div><div>E*<br></div><div>Cardinality:<br></div><div>Matches zero or more E.<br></div><div><br></div><div><br></div><div>E+<br></div><div>Cardinality:<br></div><div>Matches one or more E<br></div><div>Apply expression  E  repeatedly to match the text ahead, as long as it succeeds.<br></div><div>Consume the matched text (if any) and indicate success if there was at least one match.<br></div><div>Otherwise indicate failure.<br></div><div><br></div><div>E{m}<br></div><div>Cardinality:<br></div><div>Matches m repetitions of E.<br></div><div>B{3}, which is a shorthand for BBB.<br></div><div>B{E} means, accept any number of B up until E comes.<br></div><div>Consume E too, but don't yield it.<br></div><div>So, such expression accepts: BE, BBE, BBBE, BBBBE, etc, and yields B, BB, BBB, BBBB, etc.<br></div><div><br></div><div><br></div><div>E{m,n}<br></div><div>Cardinality:<br></div><div>Matches from m to n repetitions of E.<br></div><div>B{1,3} means B 1 to 3 times, so it accepts B, BB, and BBB.<br></div><div><br></div><div>[A-Za-z]+<br></div><div>Cardinality:<br></div><div>EXAMPLE: Matches one or more alphabetical characters.<br></div><div><br></div><div><br></div><div>$ <br></div><div>Anchor:<br></div><div>Matches at the end of the input.<br></div><div>No character is consumed. Same as  !. .<br></div><div><br></div><div>!. = $<br></div><div>Anchor:<br></div><div>Matches at the end of the input.<br></div><div>No character is consumed. Same as  $<br></div><div><br></div><div>^ <br></div><div>Anchor: Matches at the start of the input.<br></div><div>No character is consumed.<br></div><div><br></div><div>&E <br></div><div>And predicate:<br></div><div>Indicate success if expression  E  matches the text ahead;<br></div><div>otherwise indicate failure.<br></div><div>Do not consume any text.<br></div><div><br></div><div>!E <br></div><div>Not predicate:<br></div><div>Indicate failure if expression E matches the text ahead;<br></div><div>otherwise indicate success.<br></div><div>Do not consume any text.<br></div><div><br></div><div><br></div><div>[s] <br></div><div>Character class:<br></div><div>If the character ahead appears in the string  s , consume it and indicate success.<br></div><div>Otherwise indicate failure.<br></div><div><br></div><div>[a-b] <br></div><div>Character range:<br></div><div>If the character ahead is one from the range  a  through  b , consume it and indicate success.<br></div><div>Otherwise indicate failure.<br></div><div><br></div><div>'s' <br></div><div>String:<br></div><div>If the text ahead is the string  s , consume it and indicate success.<br></div><div>Otherwise indicate failure.<br></div><div><br></div><div><br></div><div>. <br></div><div>Any character:<br></div><div>If there is a character ahead, consume it and indicate success.<br></div><div>Otherwise (that is, at the end of input) indicate failure.<br></div><div><br></div><div><br></div><div><br></div><div>"BELOW PROBABLY NOT IN PEG"<br></div><div>_ <br></div><div>Any Unicode character:<br></div><div>If there is an UTF-8 character ahead, consume it and indicate success.<br></div><div>Otherwise indicate failure.<br></div><div><br></div><div>@E <br></div><div>Search:<br></div><div>Shorthand for  (!E .)* E .<br></div><div>(Search loop for the pattern  E .)<br></div><div><br></div><div><br></div><div>{@} E <br></div><div>Captured Search:<br></div><div>Shorthand for  {(!E .)*} E .<br></div><div>(Search loop for the pattern  E .) Everything until and exluding  E  is captured.<br></div><div><br></div><div>@@ E <br></div><div>Same as  {@} E .<br></div><div><br></div><div>\identifier <br></div><div>Built-in macro for a longer expression.<br></div><div><br></div><div><br></div><div><br></div><div>$i <br></div><div>Back reference to the  i th capture.  i  counts from 1.<br></div><div><br></div><div><br></div><div>i's' <br></div><div>String match ignoring case.<br></div><div><br></div><div>y's' <br></div><div>String match ignoring style.<br></div><div><br></div><div>v's' <br></div><div>Verbatim string match: Use this to override a global  \i  or  \y  modifier.<br></div><div><br></div><div>i$j <br></div><div>String match ignoring case for back reference.<br></div><div><br></div><div>y$j <br></div><div>String match ignoring style for back reference.<br></div><div><br></div><div>v$j <br></div><div>Verbatim string match for back reference.<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></blockquote><br></div><div><br></div></div><br></body></html>