Пример #1
0
def validate_address(text):
    try: 
        run_text_parser(partial(seq, address, partial(one_of, '\n')), text)
        return True
    except Exception, e:
        print e
        return False
Пример #2
0
 def Run(self, query_str):
   """Runs the parser on the provided query expression and returns
   the resulting query tree.
   """
   # Convert query_str to Unicode since picoparser expects Unicode for non-ASCII characters.
   query_tree, _ = run_text_parser(self._expr_parser, escape.to_unicode(query_str))
   return query_tree
Пример #3
0
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from picoparse import partial
from picoparse import one_of, optional, many, choice, p, cue
from picoparse.text import run_text_parser, whitespace
import sys


def matched(start, stop, name):
    one_of(start)
    v = expression()
    one_of(stop)
    return [name, v]


bracketed = p(matched, '[', ']', 'bracket')
braced = p(matched, '{', '}', 'brace')
parened = p(matched, '(', ')', 'paren')

part = p(choice, bracketed, braced, parened)
expression = p('expression', many, part)

if __name__ == "__main__":
    text = ''
    if len(sys.argv) > 1:
        text = sys.argv[1]
    print run_text_parser(p(cue, whitespace, part), text)
Пример #4
0
 def run_parser(self, parser, input):
     return run_text_parser(parser, input)
Пример #5
0
 def Run(self, attributes):
     """Runs the parser on the provided comma-separated string of attributes.
 """
     # Convert query_expr to Unicode since picoparser expects Unicode for non-ASCII characters.
     _ = run_text_parser(self._expr_parser, escape.to_unicode(attributes))
     return self._updates
Пример #6
0
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
# POSSIBILITY OF SUCH DAMAGE.

from picoparse import partial
from picoparse import one_of, optional, many, choice, p, cue
from picoparse.text import run_text_parser, whitespace
import sys

def matched(start, stop, name):
    one_of(start)
    v = expression()
    one_of(stop)
    return [name, v]

bracketed = p(matched, '[', ']', 'bracket')
braced = p(matched, '{', '}', 'brace')
parened = p(matched, '(', ')', 'paren')

part = p(choice, bracketed, braced, parened)
expression = p('expression', many, part)

if __name__ == "__main__":
    text = ''
    if len(sys.argv) > 1:
        text = sys.argv[1]
    print run_text_parser(p(cue, whitespace, part), text)

Пример #7
0
  return ('def', name, expr)

def semi():
  return special(';')

def program_part():
  expr = choice(definition, expression)
  optional(semi)
  return expr

def program():
  prog = many(program_part)
  whitespace()
  eof()
  return ('prog', prog)

if __name__ == "__main__":
    text = """
    def fib = fn n ->
        if (n == 0)
            then 0
            else (fib n1 + fib n2)
                where n1 = n - 1, n2 = n1 - 1
    let x = 5, y = 4
    in fib (x * y)
    """
    if len(sys.argv) > 1:
        text = sys.argv[1]
    print run_text_parser(program, text)

Пример #8
0
 def run_parser(self, *args):
     return run_text_parser(*args)
Пример #9
0
 def Run(self, attributes):
   """Runs the parser on the provided comma-separated string of attributes.
   """
   # Convert query_expr to Unicode since picoparser expects Unicode for non-ASCII characters.
   _ = run_text_parser(self._expr_parser, escape.to_unicode(attributes))
   return self._updates
Пример #10
0
    def run_parser(self, *args):
		return run_text_parser(*args)