コード例 #1
0
 def test_trace_drop(self):
     lang = r"""
         @ literalws = right
         @ drop = strings, whitespace
         expression = term  { ("+" | "-") term}
         term       = factor  { ("*"|"/") factor}
         factor     = number | variable | "("  expression  ")"
                    | constant | fixed
         variable   = /[a-z]/~
         number     = /\d+/~
         constant   = "A" | "B"
         fixed      = "X"
         """
     set_config_value('compiled_EBNF_log', 'test_trace_parser.py')
     gr = grammar_provider(lang)()
     all_desc = all_descendants(gr.root_parser__)
     set_tracer(all_desc, trace_history)
     # st = gr('2*(3+4)')
     st = gr('2*(3 + 4*(5 + 6*(7 + 8 + 9*2 - 1/5*1000) + 2) + 5000 + 4000)')
     serialization = st.serialize()
     assert '*' not in serialization  # same for '/', '+', '-'
     log_parsing_history(gr, 'trace_drop')
     history_file = get_history('trace_drop')
     assert "DROP" in history_file
     assert "FAIL" in history_file
     assert "MATCH" in history_file
コード例 #2
0
    parser.add_argument('-d', '--debug', action='store_const', const='debug')
    parser.add_argument('-x', '--xml', action='store_const', const='xml')

    args = parser.parse_args()
    file_name, log_dir = args.files[0], ''

    if not os.path.exists(file_name):
        print('File "%s" not found!' % file_name)
        sys.exit(1)
    if not os.path.isfile(file_name):
        print('"%s" is not a file!' % file_name)
        sys.exit(1)

    if args.debug is not None:
        log_dir = 'LOGS'
        set_config_value('history_tracking', True)
        set_config_value('resume_notices', True)
        set_config_value('log_syntax_trees',
                         set(['cst', 'ast']))  # don't use a set literal, here
    start_logging(log_dir)

    result, errors, _ = compile_src(file_name)

    if errors:
        cwd = os.getcwd()
        rel_path = file_name[len(cwd):] if file_name.startswith(
            cwd) else file_name
        for error in errors:
            print(rel_path + ':' + str(error))
        sys.exit(1)
    else:
コード例 #3
0
ファイル: LyrikParser_example.py プロジェクト: jecki/DHParser
    parser.add_argument('-d', '--debug', action='store_const', const='debug')
    parser.add_argument('-x', '--xml', action='store_const', const='xml')

    args = parser.parse_args()
    file_name, log_dir = args.files[0], ''

    if not os.path.exists(file_name):
        print('File "%s" not found!' % file_name)
        sys.exit(1)
    if not os.path.isfile(file_name):
        print('"%" is not a file!' % file_name)
        sys.exit(1)

    if args.debug is not None:
        log_dir = 'LOGS'
        set_config_value('history_tracking', True)
        set_config_value('resume_notices', True)
        set_config_value('log_syntax_trees', set(('cst', 'ast')))
    start_logging(log_dir)
    result, errors, _ = compile_src(file_name)
    if errors:
        cwd = os.getcwd()
        rel_path = file_name[len(cwd):] if file_name.startswith(
            cwd) else file_name
        for error in errors:
            print(rel_path + ':' + str(error))
        sys.exit(1)
    else:
        print(
            result.serialize(how='default' if args.xml is None else 'xml'
                             ) if isinstance(result, Node) else result)