Allow comments in grammar rules. Start working on Python3 class (not

finished). More test organization.
This commit is contained in:
rocky
2015-12-22 11:41:10 -05:00
parent 41cceb5931
commit 35592b50ed
19 changed files with 153 additions and 94 deletions

View File

@@ -1,5 +1,6 @@
'''
"""
Copyright (c) 1998-2002 John Aycock
Copyright (c) 2015 Rocky Bernstein
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -19,10 +20,11 @@ Copyright (c) 1998-2002 John Aycock
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''
"""
from __future__ import print_function
import os, re
__version__ = 'SPARK-1.0 Python3 compatible'
def _namelist(instance):
@@ -130,8 +132,13 @@ class GenericParser:
def preprocess(self, rule, func):
return rule, func
def addRule(self, doc, func, _preprocess=1):
def addRule(self, doc, func, _preprocess=True):
"""Add a grammar rules to self.rules, self.rule2func and self.rule2name"""
fn = func
# remove blanks lines and comment lines, e.g. lines starting with "#"
doc = os.linesep.join([s for s in doc.splitlines() if s and not re.match("^\s*#", s)])
rules = doc.split()
index = []