| @@ -15,4 +15,5 @@ | |||||
| - [python\_parser.py](python_parser.py) - A fully-working Python 2 & 3 parser (but not production ready yet!) | - [python\_parser.py](python_parser.py) - A fully-working Python 2 & 3 parser (but not production ready yet!) | ||||
| - [conf\_lalr.py](conf_lalr.py) - Demonstrates the power of LALR's contextual lexer on a toy configuration language | - [conf\_lalr.py](conf_lalr.py) - Demonstrates the power of LALR's contextual lexer on a toy configuration language | ||||
| - [conf\_earley.py](conf_earley.py) - Demonstrates the power of Earley's dynamic lexer on a toy configuration language | - [conf\_earley.py](conf_earley.py) - Demonstrates the power of Earley's dynamic lexer on a toy configuration language | ||||
| - [custom\_lexer.py](custom_lexer.py) - Demonstrates using a custom lexer to parse a non-textual stream of data | |||||
| - [reconstruct\_json.py](reconstruct_json.py) - Demonstrates the experimental text-reconstruction feature | - [reconstruct\_json.py](reconstruct_json.py) - Demonstrates the experimental text-reconstruction feature | ||||
| @@ -16,7 +16,6 @@ class TypeLexer(Lexer): | |||||
| pass | pass | ||||
| def lex(self, data): | def lex(self, data): | ||||
| print(data) | |||||
| for obj in data: | for obj in data: | ||||
| if isinstance(obj, int): | if isinstance(obj, int): | ||||
| yield Token('INT', obj) | yield Token('INT', obj) | ||||
| @@ -44,9 +43,12 @@ class ParseToDict(Transformer): | |||||
| def test(): | def test(): | ||||
| data = ['alice', 1, 27, 3, 'bob', 4, 'carrie', 'dan', 8, 6] | data = ['alice', 1, 27, 3, 'bob', 4, 'carrie', 'dan', 8, 6] | ||||
| print(data) | |||||
| tree = parser.parse(data) | tree = parser.parse(data) | ||||
| res = ParseToDict().transform(tree) | res = ParseToDict().transform(tree) | ||||
| print('-->') | |||||
| print(res) # prints {'alice': [1, 27, 3], 'bob': [4], 'carrie': [], 'dan': [8, 6]} | print(res) # prints {'alice': [1, 27, 3], 'bob': [4], 'carrie': [], 'dan': [8, 6]} | ||||