def __init__(self, args): lark_logger.setLevel(logging.DEBUG) self.args = args if self.args.table_filter: self.table_filter = self.args.table_filter.split(",") else: self.table_filter = [] self.fh = open(self.args.file, "rb") self.seen_table = set()
def test_loglevel_higher(self): logger.setLevel(logging.ERROR) collision_grammar = ''' start: as as as: a* a: "a" ''' with capture_log() as log: Lark(collision_grammar, parser='lalr', debug=True) log = log.getvalue() # no log messge self.assertEqual(len(log), 0)
def test_non_debug(self): logger.setLevel(logging.DEBUG) collision_grammar = ''' start: as as as: a* a: "a" ''' with capture_log() as log: Lark(collision_grammar, parser='lalr', debug=False) log = log.getvalue() # no log messge self.assertEqual(len(log), 0)
def test_debug(self): logger.setLevel(logging.DEBUG) collision_grammar = ''' start: as as as: a* a: "a" ''' with capture_log() as log: Lark(collision_grammar, parser='lalr', debug=True) log = log.getvalue() # since there are conflicts about A # symbol A should appear in the log message for hint self.assertIn("A", log)
# -*- coding: utf-8 -*- from __future__ import absolute_import import unittest import logging import os import codecs from lark import logger from lark.tools.nearley import create_code_for_nearley_grammar, main as nearley_tool_main logger.setLevel(logging.INFO) TEST_PATH = os.path.abspath(os.path.dirname(__file__)) NEARLEY_PATH = os.path.join(TEST_PATH, 'nearley') BUILTIN_PATH = os.path.join(NEARLEY_PATH, 'builtin') if not os.path.exists(BUILTIN_PATH): logger.warn( "Nearley not included. Skipping Nearley tests! (use git submodule to add)" ) raise ImportError("Skipping Nearley tests!") import js2py # Ensures that js2py exists, to avoid failing tests class TestNearley(unittest.TestCase): def test_css(self): fn = os.path.join(NEARLEY_PATH, 'examples/csscolor.ne') with open(fn) as f: grammar = f.read()
def build_lalr(namespace): logger.setLevel((ERROR, WARN, INFO, DEBUG)[min(namespace.verbose, 3)]) if len(namespace.start) == 0: namespace.start.append('start') kwargs = {n: getattr(namespace, n) for n in options} return Lark(namespace.grammar_file, parser='lalr', **kwargs), namespace.out
from lark import Lark, logger import logging import os import time logger.setLevel(logging.DEBUG) dir_path = os.path.dirname(os.path.realpath(__file__)) grammar_file_path = os.path.join(dir_path, "puml_sequence_demo.ebnf") f = open(grammar_file_path) l = Lark(f.read()) f.close() logger.debug("grammar loaded") example_file_path = os.path.join(dir_path, "test.puml") f = open(example_file_path) start_time = time.time() logger.debug("parsing...") result = l.parse(f.read()) logger.debug("parsing end") logger.debug("--- %s seconds ---" % (time.time() - start_time)) f.close() print(result) print(result.pretty())