Permalink
Browse files

copy parser frontend to compiler. add compiler to manifest.

  • Loading branch information...
1 parent ef48962 commit f6820a95948cb36f74f61cb52b31f5e65be58d7e @darius committed Dec 4, 2012
Showing with 6 additions and 5 deletions.
  1. +1 −0 MANIFEST.in
  2. +5 −5 extras/compiler.py
View
@@ -1,2 +1,3 @@
include examples/*.py
+include extras/*.py
include CHANGES LICENSE MANIFEST.in README.rst
View
@@ -7,13 +7,13 @@
def Parser(grammar):
# Map the name of each grammar rule to a list of its alternatives.
-
- parts = re.split(r'\s('+_identifier+')\s+=\s', ' '+grammar)
- if not parts: raise BadGrammar("No grammar")
- if parts[0].strip(): raise BadGrammar("Missing left hand side", parts[0])
+ parts = re.split(' ('+_identifier+') += ',
+ ' '+re.sub(r'\s', ' ', grammar))
+ if len(parts) == 1 or parts[0].strip():
+ raise BadGrammar("Missing left hand side", parts[0])
if len(set(parts[1::2])) != len(parts[1::2]):
raise BadGrammar("Multiply-defined rule(s)", grammar)
- rules = dict((lhs, [alt.split() for alt in re.split(r'\s[|](?:\s|$)', rhs)])
+ rules = dict((lhs, [alt.split() for alt in (' '+rhs+' ').split(' | ')])
for lhs, rhs in zip(parts[1::2], parts[2::2]))
def comp():

0 comments on commit f6820a9

Please sign in to comment.