Skip to content

Commit

Permalink
fixed types for regular expression loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
nesaro committed Jul 1, 2012
1 parent 107b182 commit f6d70ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
5 changes: 4 additions & 1 deletion pydsl/Grammar/Checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def __init__(self, regexp, flags = ""):
myflags = 0
if "i" in flags:
myflags |= re.I
self.__regexp = re.compile(regexp, myflags)
if isinstance(regexp, str):
self.__regexp = re.compile(regexp, myflags)
else:
self.__regexp = regexp

def check(self, word):
"""returns True if any match any regexp"""
Expand Down
12 changes: 7 additions & 5 deletions pydsl/Memory/Storage/Dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ def generate_all_summaries(self) -> list:
return result

def load(self, index, **kwargs):
from pydsl.Grammar.Tool.Regular import RegularExpressionGrammarTools
flags = ""
import re
if "flags" in self._content[index]:
return RegularExpressionGrammarTools(self._content[index]["regexp"], self._content[index]["flags"])
return RegularExpressionGrammarTools(self._content[index]["regexp"])
flags = 0
if "i" in self._content[index]["flags"]:
flags |= re.I
return re.compile(self._content[index]["regexp"], flags)
return re.compile(self._content[index]["regexp"])

def provided_iclasses(self) -> list:
return ["RegularExpressionGrammarTools"]
return ["re"]


class FileTypeDictStorage(DictStorage):
Expand Down
4 changes: 2 additions & 2 deletions pydsl/Memory/Storage/Directory/Grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

"""Grammar FileLibraries"""

__author__ = "Néstor Arocha Rodríguez"
__copyright__ = "Copyright 2008-2012, Néstor Arocha Rodríguez"
__author__ = "Nestor Arocha Rodriguez"
__copyright__ = "Copyright 2008-2012, Nestor Arocha Rodriguez"
__email__ = "[email protected]"


Expand Down
6 changes: 3 additions & 3 deletions pydsl/Memory/Storage/Directory/Regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def load_re_from_file(filepath):
raise Exception #TODO find proper exception
else:
regexp = cleanline.rstrip('\n')
flagstr = 0
flags = 0
if "i" in flagstr:
flagstr |= re.I
return re.compile(regexp, flagstr)
flags |= re.I
return re.compile(regexp, flags)

0 comments on commit f6d70ca

Please sign in to comment.