Browse Source

Remove default values on type declarations and mark ClassVars

gm/2021-09-23T00Z/github.com--lark-parser-lark/1.0b
Chanic Panic 3 years ago
parent
commit
804114d1ff
3 changed files with 15 additions and 15 deletions
  1. +6
    -6
      lark/common.py
  2. +4
    -4
      lark/grammar.py
  3. +5
    -5
      lark/lexer.py

+ 6
- 6
lark/common.py View File

@@ -17,12 +17,12 @@ class LexerConf(Serialize):

terminals: Collection[TerminalDef]
re_module: ModuleType
ignore: Collection[str] = ()
postlex: 'Optional[PostLex]' = None
callbacks: Dict[str, _Callback] = {}
g_regex_flags: int = 0
skip_validation: bool = False
use_bytes: bool = False
ignore: Collection[str]
postlex: 'Optional[PostLex]'
callbacks: Dict[str, _Callback]
g_regex_flags: int
skip_validation: bool
use_bytes: bool

def __init__(self, terminals: Collection[TerminalDef], re_module: ModuleType, ignore: Collection[str]=(), postlex: 'Optional[PostLex]'=None, callbacks: Optional[Dict[str, _Callback]]=None, g_regex_flags: int=0, skip_validation: bool=False, use_bytes: bool=False):
self.terminals = terminals


+ 4
- 4
lark/grammar.py View File

@@ -3,13 +3,13 @@ from .utils import Serialize

###{standalone

from typing import Optional, Tuple
from typing import Optional, Tuple, ClassVar

class Symbol(Serialize):
__slots__ = ('name',)

name: str
is_term: bool = NotImplemented
is_term: ClassVar[bool] = NotImplemented

def __init__(self, name: str) -> None:
self.name = name
@@ -33,7 +33,7 @@ class Symbol(Serialize):
class Terminal(Symbol):
__serialize_fields__ = 'name', 'filter_out'

is_term = True
is_term: ClassVar[bool] = True

def __init__(self, name, filter_out=False):
self.name = name
@@ -47,7 +47,7 @@ class Terminal(Symbol):
class NonTerminal(Symbol):
__serialize_fields__ = 'name',

is_term = False
is_term: ClassVar[bool] = False


class RuleOptions(Serialize):


+ 5
- 5
lark/lexer.py View File

@@ -13,7 +13,7 @@ from copy import copy
from types import ModuleType
from typing import (
TypeVar, Type, Tuple, List, Dict, Iterator, Collection, Callable, Optional, FrozenSet, Any,
Pattern as REPattern, TYPE_CHECKING
Pattern as REPattern, ClassVar, TYPE_CHECKING
)

if TYPE_CHECKING:
@@ -23,8 +23,8 @@ class Pattern(Serialize, ABC):

value: str
flags: Collection[str]
raw: Optional[str] = None
type: Optional[str] = None
raw: Optional[str]
type: ClassVar[str]

def __init__(self, value: str, flags: Collection[str]=(), raw: Optional[str]=None) -> None:
self.value = value
@@ -73,7 +73,7 @@ class Pattern(Serialize, ABC):
class PatternStr(Pattern):
__serialize_fields__ = 'value', 'flags'

type: str = "str"
type: ClassVar[str] = "str"

def to_regexp(self) -> str:
return self._get_flags(re.escape(self.value))
@@ -90,7 +90,7 @@ class PatternStr(Pattern):
class PatternRE(Pattern):
__serialize_fields__ = 'value', 'flags', '_width'

type: str = "re"
type: ClassVar[str] = "re"

def to_regexp(self) -> str:
return self._get_flags(self.value)


Loading…
Cancel
Save