Skip to content
Permalink
Browse files
re: make bare names easier to use
They can now refer to external definitions as well as non-terminals.
  • Loading branch information
fanf2 committed Nov 23, 2010
1 parent 5b730ca commit 1143f16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
@@ -68,8 +68,8 @@ <h2><a name="basic"></a>The <code>re</code> Module</h2>
<tr><td><code>.</code></td> <td>any character</td></tr>
<tr><td><code>%name</code></td>
<td>pattern <code>defs[name]</code> or a pre-defined pattern</td></tr>
<tr><td><code>name</code></td><td>non terminal</td></tr>
<tr><td><code>&lt;name&gt;</code></td><td>non terminal</td></tr>
<tr><td><code>name</code></td><td>equivalent to &lt;name&gt; or %name</td></tr>
<tr><td><code>{}</code></td> <td>position capture</td></tr>
<tr><td><code>{ p }</code></td> <td>simple capture</td></tr>
<tr><td><code>{: p :}</code></td> <td>anonymous group capture</td></tr>
6 re.lua
@@ -128,6 +128,10 @@ local defined = "%" * Identifier / function (c,Defs)
return cat
end

local def_or_var = Identifier / function (n,Defs)
return (Defs and Defs[n]) or (#n > 2 and Predef[n]) or m.V(n)
end

local Range = m.Cs(any * (m.P"-"/"") * (any - "]")) / mm.R

local item = defined + Range + m.C(any)
@@ -185,7 +189,7 @@ local exp = m.P{ "Exp",
+ "{~" * m.V"Exp" * "~}" / mm.Cs
+ "{" * m.V"Exp" * "}" / mm.C
+ m.P"." * m.Cc(any)
+ name * -arrow / mm.V
+ def_or_var * -arrow / mm.V
+ "<" * name * ">" / mm.V;
Definition = Identifier * arrow * m.V"Exp";
Grammar = m.Cf(m.V"Definition" / firstdef * m.Cg(m.V"Definition")^0, adddef) /

0 comments on commit 1143f16

Please sign in to comment.