瀏覽代碼

Fixes to typing and tests

gm/2021-09-23T00Z/github.com--lark-parser-lark/1.0b
Erez Sh 3 年之前
父節點
當前提交
1457e01e7e
共有 10 個檔案被更改,包括 42 行新增39 行删除
  1. +4
    -4
      lark/common.py
  2. +3
    -5
      lark/exceptions.py
  3. +1
    -2
      lark/grammar.py
  4. +1
    -2
      lark/indenter.py
  5. +12
    -12
      lark/lark.py
  6. +7
    -8
      lark/lexer.py
  7. +7
    -0
      lark/tools/standalone.py
  8. +5
    -4
      lark/tree.py
  9. +1
    -1
      lark/visitors.py
  10. +1
    -1
      tests/test_tools.py

+ 4
- 4
lark/common.py 查看文件

@@ -1,14 +1,14 @@
from copy import deepcopy from copy import deepcopy
from types import ModuleType from types import ModuleType
from typing import Callable, Collection, Dict, Optional, TYPE_CHECKING

if TYPE_CHECKING:
from .lark import PostLex


from .utils import Serialize from .utils import Serialize
from .lexer import TerminalDef, Token from .lexer import TerminalDef, Token


###{standalone ###{standalone
from typing import Any, Callable, Collection, Dict, Optional, TYPE_CHECKING

if TYPE_CHECKING:
from .lark import PostLex


_Callback = Callable[[Token], Token] _Callback = Callable[[Token], Token]




+ 3
- 5
lark/exceptions.py 查看文件

@@ -1,16 +1,14 @@
from .utils import logger, NO_VALUE from .utils import logger, NO_VALUE


###{standalone
from collections.abc import Sequence

from typing import Dict, Iterable, Callable, Union, TypeVar, Tuple, Any, List, Set, Optional, TYPE_CHECKING from typing import Dict, Iterable, Callable, Union, TypeVar, Tuple, Any, List, Set, Optional, TYPE_CHECKING
from collections.abc import Sequence


if TYPE_CHECKING: if TYPE_CHECKING:
from .lexer import Token from .lexer import Token
from .parsers.lalr_interactive_parser import InteractiveParser from .parsers.lalr_interactive_parser import InteractiveParser
from .tree import Tree from .tree import Tree


###{standalone

class LarkError(Exception): class LarkError(Exception):
pass pass




+ 1
- 2
lark/grammar.py 查看文件

@@ -1,10 +1,9 @@
from typing import Optional, Tuple, ClassVar


from .utils import Serialize from .utils import Serialize


###{standalone ###{standalone


from typing import Optional, Tuple, ClassVar

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




+ 1
- 2
lark/indenter.py 查看文件

@@ -1,19 +1,18 @@
"Provides Indentation services for languages with indentation similar to Python" "Provides Indentation services for languages with indentation similar to Python"


from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import List, Iterator


from .exceptions import LarkError from .exceptions import LarkError
from .lark import PostLex from .lark import PostLex
from .lexer import Token from .lexer import Token


###{standalone ###{standalone
from typing import List, Iterator


class DedentError(LarkError): class DedentError(LarkError):
pass pass


class Indenter(PostLex, ABC): class Indenter(PostLex, ABC):

paren_level: int paren_level: int
indent_level: List[int] indent_level: List[int]




+ 12
- 12
lark/lark.py 查看文件

@@ -1,7 +1,18 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
import sys, os, pickle, hashlib import sys, os, pickle, hashlib
import tempfile import tempfile

from typing import (
TypeVar, Type, List, Dict, Iterator, Callable, Union, Optional,
Tuple, Iterable, IO, Any, TYPE_CHECKING
)
if TYPE_CHECKING:
from .parsers.lalr_interactive_parser import InteractiveParser
from .visitors import Transformer
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
from .exceptions import ConfigurationError, assert_config, UnexpectedInput from .exceptions import ConfigurationError, assert_config, UnexpectedInput
from .utils import Serialize, SerializeMemoizer, FS, isascii, logger from .utils import Serialize, SerializeMemoizer, FS, isascii, logger
from .load_grammar import load_grammar, FromPackageLoader, Grammar, verify_used_files, PackageResource from .load_grammar import load_grammar, FromPackageLoader, Grammar, verify_used_files, PackageResource
@@ -21,18 +32,7 @@ except ImportError:




###{standalone ###{standalone
from typing import (
TypeVar, Type, List, Dict, Iterator, Callable, Union, Optional,
Tuple, Iterable, IO, Any, TYPE_CHECKING
)


if TYPE_CHECKING:
from .parsers.lalr_interactive_parser import InteractiveParser
from .visitors import Transformer
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal


class PostLex(ABC): class PostLex(ABC):
@abstractmethod @abstractmethod


+ 7
- 8
lark/lexer.py 查看文件

@@ -3,6 +3,13 @@
from abc import abstractmethod, ABC from abc import abstractmethod, ABC
import re import re
from contextlib import suppress from contextlib import suppress
from typing import (
TypeVar, Type, List, Dict, Iterator, Collection, Callable, Optional, FrozenSet, Any,
Pattern as REPattern, ClassVar, TYPE_CHECKING
)
from types import ModuleType
if TYPE_CHECKING:
from .common import LexerConf


from .utils import classify, get_regexp_width, Serialize from .utils import classify, get_regexp_width, Serialize
from .exceptions import UnexpectedCharacters, LexError, UnexpectedToken from .exceptions import UnexpectedCharacters, LexError, UnexpectedToken
@@ -10,14 +17,6 @@ from .exceptions import UnexpectedCharacters, LexError, UnexpectedToken
###{standalone ###{standalone
from copy import copy 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, ClassVar, TYPE_CHECKING
)

if TYPE_CHECKING:
from .common import LexerConf


class Pattern(Serialize, ABC): class Pattern(Serialize, ABC):




+ 7
- 0
lark/tools/standalone.py 查看文件

@@ -25,6 +25,13 @@
# #


from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections.abc import Sequence
from types import ModuleType
from typing import (
TypeVar, Generic, Type, Tuple, List, Dict, Iterator, Collection, Callable, Optional, FrozenSet, Any,
Union, Iterable, IO, TYPE_CHECKING,
Pattern as REPattern, ClassVar, Set,
)
###} ###}


import sys import sys


+ 5
- 4
lark/tree.py 查看文件

@@ -1,3 +1,4 @@

try: try:
from future_builtins import filter # type: ignore from future_builtins import filter # type: ignore
except ImportError: except ImportError:
@@ -6,10 +7,7 @@ except ImportError:
import sys import sys
from copy import deepcopy from copy import deepcopy



###{standalone
from collections import OrderedDict
from typing import List, Callable, Iterator, Union, Optional, Any, TYPE_CHECKING
from typing import List, Callable, Iterator, Union, Optional, TYPE_CHECKING


if TYPE_CHECKING: if TYPE_CHECKING:
from .lexer import TerminalDef from .lexer import TerminalDef
@@ -18,6 +16,9 @@ if TYPE_CHECKING:
else: else:
from typing_extensions import Literal from typing_extensions import Literal


###{standalone
from collections import OrderedDict

class Meta: class Meta:


empty: bool empty: bool


+ 1
- 1
lark/visitors.py 查看文件

@@ -1,3 +1,4 @@
from typing import TypeVar, Tuple, List, Callable, Generic, Type, Union, Optional
from abc import ABC from abc import ABC
from functools import wraps from functools import wraps


@@ -8,7 +9,6 @@ from .lexer import Token


###{standalone ###{standalone
from inspect import getmembers, getmro from inspect import getmembers, getmro
from typing import TypeVar, Tuple, List, Callable, Generic, Type, Union, Optional


_T = TypeVar('_T') _T = TypeVar('_T')
_R = TypeVar('_R') _R = TypeVar('_R')


+ 1
- 1
tests/test_tools.py 查看文件

@@ -24,7 +24,7 @@ class TestStandalone(TestCase):
standalone.gen_standalone(Lark(grammar, parser='lalr'), out=code_buf, compress=compress) standalone.gen_standalone(Lark(grammar, parser='lalr'), out=code_buf, compress=compress)
code = code_buf.getvalue() code = code_buf.getvalue()


context = {'__doc__': None}
context = {'__doc__': None, '__name__': 'test_standalone'}
exec(code, context) exec(code, context)
return context return context




Loading…
取消
儲存