mirror of https://github.com/lark-parser/lark.git
Make mypy happy
This commit is contained in:
parent
c919cc17fa
commit
9d83094c1e
|
@ -12,7 +12,7 @@ import warnings
|
|||
try:
|
||||
import interegular
|
||||
except ImportError:
|
||||
interegular = None
|
||||
pass
|
||||
if TYPE_CHECKING:
|
||||
from .common import LexerConf
|
||||
|
||||
|
@ -24,10 +24,10 @@ from .grammar import TOKEN_DEFAULT_PRIORITY
|
|||
###{standalone
|
||||
from copy import copy
|
||||
|
||||
try: # For the standalone parser, we need to make sure that interegular is set to None to avoid NameErrors later on
|
||||
interegular
|
||||
try: # For the standalone parser, we need to make sure that has_interegular is False to avoid NameErrors later on
|
||||
has_interegular = bool(interegular)
|
||||
except NameError:
|
||||
interegular = None
|
||||
has_interegular = False
|
||||
|
||||
class Pattern(Serialize, ABC):
|
||||
|
||||
|
@ -490,7 +490,7 @@ class BasicLexer(Lexer):
|
|||
if not (set(conf.ignore) <= {t.name for t in terminals}):
|
||||
raise LexError("Ignore terminals are not defined: %s" % (set(conf.ignore) - {t.name for t in terminals}))
|
||||
|
||||
if interegular:
|
||||
if has_interegular:
|
||||
if not comparator:
|
||||
comparator = interegular.Comparator.from_regexes(terminal_to_regexp)
|
||||
for group in classify(terminal_to_regexp, lambda t:t.priority).values():
|
||||
|
@ -592,7 +592,7 @@ class ContextualLexer(Lexer):
|
|||
trad_conf = copy(conf)
|
||||
trad_conf.terminals = terminals
|
||||
|
||||
if interegular and not conf.skip_validation:
|
||||
if has_interegular and not conf.skip_validation:
|
||||
comparator = interegular.Comparator.from_regexes({t: t.pattern.to_regexp() for t in terminals})
|
||||
else:
|
||||
comparator = None
|
||||
|
|
|
@ -8,8 +8,9 @@ import warnings
|
|||
from lark import Lark, logger
|
||||
try:
|
||||
from interegular import logger as interegular_logger
|
||||
has_interegular = True
|
||||
except ImportError:
|
||||
interegular_logger = None
|
||||
has_interegular = False
|
||||
|
||||
lalr_argparser = ArgumentParser(add_help=False, epilog='Look at the Lark documentation for more info on the options')
|
||||
|
||||
|
@ -44,7 +45,7 @@ for flag in flags:
|
|||
|
||||
def build_lalr(namespace):
|
||||
logger.setLevel((ERROR, WARN, INFO, DEBUG)[min(namespace.verbose, 3)])
|
||||
if interegular_logger is not None:
|
||||
if has_interegular:
|
||||
interegular_logger.setLevel(logger.getEffectiveLevel())
|
||||
if len(namespace.start) == 0:
|
||||
namespace.start.append('start')
|
||||
|
|
|
@ -3,7 +3,7 @@ import os
|
|||
from functools import reduce
|
||||
from itertools import product
|
||||
from collections import deque
|
||||
from typing import Callable, Iterator, List, Optional, Tuple, Type, TypeVar, Union, Dict, Any, Sequence
|
||||
from typing import Callable, Iterator, List, Optional, Tuple, Type, TypeVar, Union, Dict, Any, Sequence, Iterable
|
||||
|
||||
###{standalone
|
||||
import sys, re
|
||||
|
@ -21,7 +21,7 @@ NO_VALUE = object()
|
|||
T = TypeVar("T")
|
||||
|
||||
|
||||
def classify(seq: Sequence, key: Optional[Callable] = None, value: Optional[Callable] = None) -> Dict:
|
||||
def classify(seq: Iterable, key: Optional[Callable] = None, value: Optional[Callable] = None) -> Dict:
|
||||
d: Dict[Any, Any] = {}
|
||||
for item in seq:
|
||||
k = key(item) if (key is not None) else item
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
interegular>=0.2.2
|
||||
interegular>=0.2.3
|
||||
Js2Py==0.68
|
||||
regex
|
||||
|
|
Loading…
Reference in New Issue