소스 검색

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 types import ModuleType
from typing import Callable, Collection, Dict, Optional, TYPE_CHECKING

if TYPE_CHECKING:
from .lark import PostLex

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

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

if TYPE_CHECKING:
from .lark import PostLex

_Callback = Callable[[Token], Token]



+ 3
- 5
lark/exceptions.py 파일 보기

@@ -1,16 +1,14 @@
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 collections.abc import Sequence

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

###{standalone

class LarkError(Exception):
pass



+ 1
- 2
lark/grammar.py 파일 보기

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

from .utils import Serialize

###{standalone

from typing import Optional, Tuple, ClassVar

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



+ 1
- 2
lark/indenter.py 파일 보기

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

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

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

###{standalone
from typing import List, Iterator

class DedentError(LarkError):
pass

class Indenter(PostLex, ABC):

paren_level: int
indent_level: List[int]



+ 12
- 12
lark/lark.py 파일 보기

@@ -1,7 +1,18 @@
from abc import ABC, abstractmethod
import sys, os, pickle, hashlib
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 .utils import Serialize, SerializeMemoizer, FS, isascii, logger
from .load_grammar import load_grammar, FromPackageLoader, Grammar, verify_used_files, PackageResource
@@ -21,18 +32,7 @@ except ImportError:


###{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):
@abstractmethod


+ 7
- 8
lark/lexer.py 파일 보기

@@ -3,6 +3,13 @@
from abc import abstractmethod, ABC
import re
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 .exceptions import UnexpectedCharacters, LexError, UnexpectedToken
@@ -10,14 +17,6 @@ from .exceptions import UnexpectedCharacters, LexError, UnexpectedToken
###{standalone
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):



+ 7
- 0
lark/tools/standalone.py 파일 보기

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

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


+ 5
- 4
lark/tree.py 파일 보기

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

try:
from future_builtins import filter # type: ignore
except ImportError:
@@ -6,10 +7,7 @@ except ImportError:
import sys
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:
from .lexer import TerminalDef
@@ -18,6 +16,9 @@ if TYPE_CHECKING:
else:
from typing_extensions import Literal

###{standalone
from collections import OrderedDict

class Meta:

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 functools import wraps

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

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

_T = TypeVar('_T')
_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)
code = code_buf.getvalue()

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



불러오는 중...
취소
저장