Ver a proveniência

Use NotImplemented for __eq__ and use __new__ for LexerThread

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.11.3
Gary Geng há 3 anos
ascendente
cometimento
94e242f51a
2 ficheiros alterados com 5 adições e 7 eliminações
  1. +4
    -6
      lark/lexer.py
  2. +1
    -1
      lark/parsers/lalr_parser.py

+ 4
- 6
lark/lexer.py Ver ficheiro

@@ -188,7 +188,7 @@ class LineCounter:

def __eq__(self, other):
if not isinstance(other, LineCounter):
return False
return NotImplemented
return (self.newline_char == other.newline_char and self.char_pos == other.char_pos
and self.line == other.line and self.column == other.column
and self.line_start_pos == other.line_start_pos)
@@ -414,7 +414,7 @@ class LexerState(object):

def __eq__(self, other):
if not isinstance(other, LexerState):
return False
return NotImplemented

return (self.text == other.text and self.line_ctr == other.line_ctr
and self.last_token == other.last_token)
@@ -481,10 +481,8 @@ class LexerThread(object):
return self.lexer.lex(self.state, parser_state)

def __copy__(self):
copied = type(self)(
self.lexer,
''
)
copied = object.__new__(LexerThread)
copied.lexer = self.lexer
copied.state = copy(self.state)
return copied
###}

+ 1
- 1
lark/parsers/lalr_parser.py Ver ficheiro

@@ -94,7 +94,7 @@ class ParserState(object):
# Necessary for match_examples() to work
def __eq__(self, other):
if not isinstance(other, ParserState):
return False
return NotImplemented
return len(self.state_stack) == len(other.state_stack) and self.position == other.position

def __copy__(self):


Carregando…
Cancelar
Guardar