Skip to content

Commit

Permalink
refactoring: modules: Rule->Generate, Parse->Rules
Browse files Browse the repository at this point in the history
  • Loading branch information
deztructor committed Jun 21, 2012
1 parent f5b45f3 commit f413607
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/vcard.py
Expand Up @@ -155,4 +155,5 @@ class VCardCtx(object):
g = grammar(VCardCtx(), mk_options(is_remember = False))

pos, value = g.parse(source(vc))
from parsed.Rules import CachingParser
print value
2 changes: 1 addition & 1 deletion examples/xml_parser.py
Expand Up @@ -196,7 +196,7 @@ def element_close(elem, children, closing):
print sw.dt


from parsed.Parse import CachingParser
from parsed.Rules import CachingParser

with codecs.open(sys.argv[1], encoding = 'utf-8') as f:
s = u'\n'.join(f.readlines())
Expand Down
2 changes: 1 addition & 1 deletion parsed/Rule.py → parsed/Generate.py
Expand Up @@ -4,7 +4,7 @@
# Copyright (c) 2012 Denis Zalevskiy
# Licensed under MIT License

from Parse import *
from Rule import *
from cor import is_iterable, Err, integers
from Common import *

Expand Down
1 change: 0 additions & 1 deletion parsed/Parse.py → parsed/Rules.py
Expand Up @@ -229,7 +229,6 @@ def fn(src):

return fn


def match_string(name, s, action, options):
if not (isinstance(s, str) or isinstance(s, unicode)):
raise Err("{} is not a string", s)
Expand Down
15 changes: 8 additions & 7 deletions parsed/__init__.py
Expand Up @@ -6,23 +6,24 @@

import string

import Rule
import Parse
import Generate
import Rules
from Common import *

def rule(fn): return Rule.TopRule(fn)
def rule(fn): return Generate.TopRule(fn)

def char(c): return Rule.mk_first_match_rule(c)
def text(s): return Rule.StringRule(s)
def char(c): return Generate.mk_first_match_rule(c)
def text(s): return Generate.StringRule(s)
def equal(c): return Generate.FirstEqualRule(c)

def source(src, begin = 0, end = None):
return Parse.InfiniteInput(src, begin, end)
return Rules.InfiniteInput(src, begin, end)

def cache_clean(rules_dict):
'''rules_dict is ordinary result of grammar module globals()
call'''
for x in rules_dict.values():
if isinstance(x, Rule.Rule):
if isinstance(x, Generate.Rule):
x.parser_cache_reset()


Expand Down
2 changes: 1 addition & 1 deletion tests/basic.py
Expand Up @@ -4,7 +4,7 @@
# Copyright (c) 2012 Denis Zalevskiy
# Licensed under MIT License

from parsed.Parse import InfiniteInput
from parsed.Rules import InfiniteInput
import unittest
from parsed import mk_options, rule, char, cache_clean
import parsed.Parse as P
Expand Down

0 comments on commit f413607

Please sign in to comment.