Procházet zdrojové kódy

Python2.7 compatibility

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.11.2
MegaIng1 před 3 roky
rodič
revize
d676df9b88
2 změnil soubory, kde provedl 6 přidání a 7 odebrání
  1. +1
    -1
      lark/grammars/common.lark
  2. +5
    -6
      lark/load_grammar.py

+ 1
- 1
lark/grammars/common.lark Zobrazit soubor

@@ -55,5 +55,5 @@ NEWLINE: (CR? LF)+
// Comments
SH_COMMENT: /#[^\n]*/
CPP_COMMENT: /\/\/[^\n]*/
C_COMMENT: "/*" /.*?/s "*/"
C_COMMENT: "/*" /(.|\n)*?/ "*/"
SQL_COMMENT: /--[^\n]*/

+ 5
- 6
lark/load_grammar.py Zobrazit soubor

@@ -6,6 +6,7 @@ from copy import copy, deepcopy
from io import open
import pkgutil
from ast import literal_eval
from numbers import Integral

from .utils import bfs, Py36, logger, classify_bool, is_id_continue, is_id_start
from .lexer import Token, TerminalDef, PatternStr, PatternRE
@@ -1177,7 +1178,7 @@ class GrammarBuilder:
args = {}
for i, name in enumerate(names, start=1):
postfix = '' if i == 1 else str(i)
args['name'+ postfix] = name
args['name' + postfix] = name
args['type' + postfix] = lowercase_type = ("rule", "terminal")[self._is_term(name)]
args['Type' + postfix] = lowercase_type.title()
raise GrammarError(msg.format(**args))
@@ -1186,8 +1187,9 @@ class GrammarBuilder:
if self._is_term(name):
if options is None:
options = 1
elif not isinstance(options, int):
raise GrammarError("Terminal require a single int as 'options' (e.g. priority)")
# if we don't use Integral here, we run into python2.7/python3 problems with long vs int
elif not isinstance(options, Integral):
raise GrammarError("Terminal require a single int as 'options' (e.g. priority), got %s" % (type(options),))
else:
if options is None:
options = RuleOptions()
@@ -1384,9 +1386,6 @@ class GrammarBuilder:

def check(self):
for name, (params, exp, options) in self._definitions.items():
if self._is_term(name):
assert isinstance(options, int)

for i, p in enumerate(params):
if p in self._definitions:
raise GrammarError("Template Parameter conflicts with rule %s (in template %s)" % (p, name))


Načítá se…
Zrušit
Uložit