From 7373993102a89415fb6b95d17c666050d6ab1871 Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Wed, 23 Aug 2017 00:40:27 +0300 Subject: [PATCH] Oops!! Important bugfix to last commit --- examples/python3.g | 3 ++- lark/__init__.py | 2 +- lark/lark.py | 2 +- lark/lexer.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/python3.g b/examples/python3.g index a382d0b..61dc1ee 100644 --- a/examples/python3.g +++ b/examples/python3.g @@ -166,7 +166,8 @@ string: STRING | LONG_STRING NAME: /[a-zA-Z_]\w*/ COMMENT: /\#[^\n]*/ -_NEWLINE: /(\r?\n[\t ]*|${COMMENT})+/ +_NEWLINE: ( /\r?\n[\t ]*/ | COMMENT )+ + %ignore /[\t \f]+/ // WS %ignore /\\\\[\t \f]*\r?\n/ // LINE_CONT diff --git a/lark/__init__.py b/lark/__init__.py index b892073..65a318c 100644 --- a/lark/__init__.py +++ b/lark/__init__.py @@ -3,4 +3,4 @@ from .common import ParseError, GrammarError from .lark import Lark from .utils import inline_args -__version__ = "0.3.3" +__version__ = "0.3.4" diff --git a/lark/lark.py b/lark/lark.py index 005fb4d..4adabcc 100644 --- a/lark/lark.py +++ b/lark/lark.py @@ -36,7 +36,7 @@ class LarkOptions(object): debug - Affects verbosity (default: False) keep_all_tokens - Don't automagically remove "punctuation" tokens (default: False) cache_grammar - Cache the Lark grammar (Default: False) - postlex - Lexer post-processing (Default: None) + postlex - Lexer post-processing (Requires standard lexer. Default: None) start - The start symbol (Default: start) profile - Measure run-time usage in Lark. Read results from the profiler proprety (Default: False) propagate_positions - Experimental. Don't use yet. diff --git a/lark/lexer.py b/lark/lexer.py index eb1fede..3dabd95 100644 --- a/lark/lexer.py +++ b/lark/lexer.py @@ -131,7 +131,7 @@ class Lexer(object): self.newline_types = [t.name for t in tokens if _regexp_has_newline(t.pattern.to_regexp())] self.ignore_types = [t for t in ignore] - tokens.sort(key=lambda x:(-x.priority, -x.pattern.max_width, x.name)) + tokens.sort(key=lambda x:(-x.priority, -x.pattern.max_width, -len(x.pattern.value), x.name)) tokens, self.callback = _create_unless(tokens) assert all(self.callback.values())