OILS / tools / find / parser.py View on Github | oilshell.org

28 lines, 15 significant
1#!/usr/bin/env python2
2# Copyright 2019 Wilke Schwiedop. All rights reserved.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8
9import pgen2.driver, pgen2.pgen, pgen2.parse
10
11from oil_lang.expr_parse import NoSingletonAction
12
13from tokenizer import TokenDef, opmap, tok_name
14
15with open('tools/find/find.pgen2') as f:
16 _grammar = pgen2.pgen.MakeGrammar(f, tok_def=TokenDef())
17_parser = pgen2.parse.Parser(_grammar, convert=NoSingletonAction)
18
19nt_name = _grammar.number2symbol.copy()
20
21def ParseTree(tokens):
22 return pgen2.driver.PushTokens(
23 _parser,
24 tokens,
25 _grammar,
26 start_symbol='start',
27 opmap=opmap
28 )