From fef774f78fcb3516fff470a910f4634f29832450 Mon Sep 17 00:00:00 2001 From: Jan Rydzewski Date: Fri, 26 Oct 2018 14:08:06 +0200 Subject: [PATCH 1/5] Instructions how to get Shift/Reduce messages printed (Issue #258) --- docs/how_to_use.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/how_to_use.md b/docs/how_to_use.md index 95041e4..a76df2d 100644 --- a/docs/how_to_use.md +++ b/docs/how_to_use.md @@ -52,3 +52,18 @@ class MyTransformer(Transformer): new_tree = MyTransformer().transform(tree) ``` +## LALR usage + +By default Lark silently resolves Shift/Reduce conflicts as Shift. To enable warnings pass `debug=True`. To get the messages printed you have to configure `logging` framework beforehand. For example: + +``` +import logging +logging.basicConfig(level=logging.DEBUG) + +collision_grammar = ''' +start: as as +as: a* +a: 'a' +''' +p = Lark(collision_grammar, parser='lalr', debug=True) +``` From d36a6dbec208aab37e4e547c1adbcee9b2266d20 Mon Sep 17 00:00:00 2001 From: Jan Rydzewski Date: Fri, 26 Oct 2018 14:09:45 +0200 Subject: [PATCH 2/5] Update how_to_use.md --- docs/how_to_use.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/how_to_use.md b/docs/how_to_use.md index a76df2d..c1a8518 100644 --- a/docs/how_to_use.md +++ b/docs/how_to_use.md @@ -56,7 +56,7 @@ new_tree = MyTransformer().transform(tree) By default Lark silently resolves Shift/Reduce conflicts as Shift. To enable warnings pass `debug=True`. To get the messages printed you have to configure `logging` framework beforehand. For example: -``` +```python import logging logging.basicConfig(level=logging.DEBUG) From 188e87c65bfafb12c0fd12b11471fca31a7661a2 Mon Sep 17 00:00:00 2001 From: Jan Rydzewski Date: Fri, 26 Oct 2018 14:10:55 +0200 Subject: [PATCH 3/5] Update how_to_use.md --- docs/how_to_use.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/how_to_use.md b/docs/how_to_use.md index c1a8518..5113d27 100644 --- a/docs/how_to_use.md +++ b/docs/how_to_use.md @@ -57,6 +57,7 @@ new_tree = MyTransformer().transform(tree) By default Lark silently resolves Shift/Reduce conflicts as Shift. To enable warnings pass `debug=True`. To get the messages printed you have to configure `logging` framework beforehand. For example: ```python +from lark import Lark import logging logging.basicConfig(level=logging.DEBUG) From ed95ce28bcb31e0089ddaa82a12936bceee94bb8 Mon Sep 17 00:00:00 2001 From: Muhammed Alkan Date: Mon, 29 Oct 2018 12:18:47 +0300 Subject: [PATCH 4/5] Fix typo --- docs/grammar.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/grammar.md b/docs/grammar.md index 69a6704..87912a5 100644 --- a/docs/grammar.md +++ b/docs/grammar.md @@ -43,7 +43,7 @@ Literals can be one of: * `/regular expression+/` * `"case-insensitive string"i` * `/re with flags/imulx` -* Literal range: `"a".."z"`, `"1..9"`, etc. +* Literal range: `"a".."z"`, `"1".."9"`, etc. #### Notes for when using a lexer: @@ -145,4 +145,4 @@ If the module path is relative, such as `.path.to.file`, Lark will attempt to lo ### %declare -Declare a terminal without defining it. Useful for plugins. \ No newline at end of file +Declare a terminal without defining it. Useful for plugins. From 149f7cec1f828358ad74d91bde7ddef63a118159 Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Tue, 6 Nov 2018 16:07:27 +0200 Subject: [PATCH 5/5] BUGFIX: Importing the same grammar twice could lead to unexpected behavior (Issue #268) --- lark/load_grammar.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lark/load_grammar.py b/lark/load_grammar.py index 2f48cb1..1966117 100644 --- a/lark/load_grammar.py +++ b/lark/load_grammar.py @@ -526,8 +526,12 @@ def import_grammar(grammar_path, base_paths=[]): return _imported_grammars[grammar_path] def import_from_grammar_into_namespace(grammar, namespace, aliases): + """Returns all rules and terminals of grammar, prepended + with a 'namespace' prefix, except for those which are aliased. + """ + imported_terms = dict(grammar.term_defs) - imported_rules = {n:(n,t,o) for n,t,o in grammar.rule_defs} + imported_rules = {n:(n,deepcopy(t),o) for n,t,o in grammar.rule_defs} term_defs = [] rule_defs = [] @@ -535,7 +539,10 @@ def import_from_grammar_into_namespace(grammar, namespace, aliases): def rule_dependencies(symbol): if symbol.type != 'RULE': return [] - _, tree, _ = imported_rules[symbol] + try: + _, tree, _ = imported_rules[symbol] + except KeyError: + raise GrammarError("Missing symbol '%s' in grammar %s" % (symbol, namespace)) return tree.scan_values(lambda x: x.type in ('RULE', 'TERMINAL')) def get_namespace_name(name):