| 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 | 
 | 
| 9 | import pgen2.driver, pgen2.pgen, pgen2.parse
 | 
| 10 | 
 | 
| 11 | from oil_lang.expr_parse import NoSingletonAction
 | 
| 12 | 
 | 
| 13 | from tokenizer import TokenDef, opmap, tok_name
 | 
| 14 | 
 | 
| 15 | with 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 | 
 | 
| 19 | nt_name = _grammar.number2symbol.copy()
 | 
| 20 | 
 | 
| 21 | def ParseTree(tokens):
 | 
| 22 | 	return pgen2.driver.PushTokens(
 | 
| 23 | 		_parser,
 | 
| 24 | 		tokens,
 | 
| 25 | 		_grammar,
 | 
| 26 | 		start_symbol='start',
 | 
| 27 | 		opmap=opmap
 | 
| 28 | 	)
 |