Browse Source

Pylint

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan 7 years ago
parent
commit
d230e7744c
10 changed files with 14 additions and 16 deletions
  1. +2
    -1
      examples/reconstruct_json.py
  2. +1
    -1
      lark/common.py
  3. +1
    -1
      lark/indenter.py
  4. +1
    -1
      lark/lark.py
  5. +2
    -2
      lark/lexer.py
  6. +2
    -2
      lark/load_grammar.py
  7. +2
    -3
      lark/parser_frontends.py
  8. +1
    -1
      lark/parsers/nearley.py
  9. +1
    -3
      lark/reconstruct.py
  10. +1
    -1
      lark/utils.py

+ 2
- 1
examples/reconstruct_json.py View File

@@ -6,11 +6,12 @@
#

import json
from .json_parser import json_grammar

from lark import Lark
from lark.reconstruct import Reconstructor

from .json_parser import json_grammar

def test():

test_json = '''


+ 1
- 1
lark/common.py View File

@@ -24,7 +24,7 @@ class UnexpectedToken(ParseError):
"Expected: %s\n"
"Context: %s" % (token, self.line, self.column, expected, context))

super(ParseError, self).__init__(message)
super(UnexpectedToken, self).__init__(message)





+ 1
- 1
lark/indenter.py View File

@@ -8,7 +8,7 @@ class Indenter:
self.indent_level = [0]

def handle_NL(self, token):
if (self.paren_level > 0):
if self.paren_level > 0:
return

yield token


+ 1
- 1
lark/lark.py View File

@@ -7,7 +7,7 @@ from collections import defaultdict
from .utils import STRING_TYPE
from .load_grammar import load_grammar
from .tree import Tree
from .common import GrammarError, LexerConf, ParserConf
from .common import LexerConf, ParserConf

from .lexer import Lexer
from .parse_tree_builder import ParseTreeBuilder


+ 2
- 2
lark/lexer.py View File

@@ -2,7 +2,7 @@

import re

from .utils import Str, classify, STRING_TYPE
from .utils import Str, classify
from .common import is_terminal, PatternStr, PatternRE, TokenDef

class LexError(Exception):
@@ -13,7 +13,7 @@ class UnexpectedInput(LexError):
context = seq[lex_pos:lex_pos+5]
message = "No token defined for: '%s' in %r at line %d" % (seq[lex_pos], context, line)

super(LexError, self).__init__(message)
super(UnexpectedInput, self).__init__(message)

self.line = line
self.column = column


+ 2
- 2
lark/load_grammar.py View File

@@ -3,7 +3,7 @@ from itertools import chain
import re
from ast import literal_eval

from .lexer import Lexer, Token, UnexpectedInput
from .lexer import Token, UnexpectedInput

from .parse_tree_builder import ParseTreeBuilder
from .parser_frontends import LALR
@@ -526,7 +526,7 @@ class GrammarLoader:
token_tree = dict(g.token_defs)[dotted_path[-1]]
token_defs.append([name.value, token_tree])
else:
assert False, command
assert False, stmt


# Verify correctness 1


+ 2
- 3
lark/parser_frontends.py View File

@@ -5,7 +5,6 @@ from .lexer import Lexer, ContextualLexer, Token

from .common import is_terminal, GrammarError, ParserConf
from .parsers import lalr_parser, earley, nearley
from .parsers.grammar_analysis import Rule
from .tree import Transformer

class WithLexer:
@@ -126,7 +125,7 @@ class Nearley_NoLex:
if is_terminal(sym):
regexp = self.token_by_name[sym].pattern.to_regexp()
width = sre_parse.parse(regexp).getwidth()
if not width == (1,1):
if width != (1,1):
raise GrammarError('Dynamic lexing requires all tokens to have a width of 1 (%s is %s)' % (regexp, width))
yield sym, re.compile(regexp)
else:
@@ -168,7 +167,7 @@ class Earley_NoLex:
if is_terminal(sym):
regexp = self.token_by_name[sym].pattern.to_regexp()
width = sre_parse.parse(regexp).getwidth()
if not width == (1,1):
if width != (1,1):
raise GrammarError('Scanless parsing (lexer=None) requires all tokens to have a width of 1 (terminal %s: %s is %s)' % (sym, regexp, width))
yield (re.compile(regexp).match, regexp)
else:


+ 1
- 1
lark/parsers/nearley.py View File

@@ -1,6 +1,6 @@
"My name is Earley"

from ..utils import classify, STRING_TYPE
from ..utils import classify
from ..common import ParseError, UnexpectedToken

try:


+ 1
- 3
lark/reconstruct.py View File

@@ -5,7 +5,6 @@ from .tree import Tree
from .common import is_terminal, ParserConf, PatternStr
from .lexer import Token
from .parsers import earley
from .lark import Lark



@@ -68,7 +67,7 @@ class Reconstructor:
return to_write

d = defaultdict(list)
for name, (expansions, options) in parser.rules.items():
for name, (expansions, _o) in parser.rules.items():
for expansion, alias in expansions:
if alias:
d[alias].append(expansion)
@@ -104,4 +103,3 @@ class Reconstructor:
def reconstruct(self, tree):
return ''.join(self._reconstruct(tree))



+ 1
- 1
lark/utils.py View File

@@ -60,7 +60,7 @@ def inline_args(f):
return _f_func
elif isinstance(f, (type, types.BuiltinFunctionType)):
@functools.wraps(f)
def _f_builtin(self, args):
def _f_builtin(_self, args):
return f(*args)
return _f_builtin
else:


Loading…
Cancel
Save