add updates libs
This commit is contained in:
@@ -1,51 +1,55 @@
|
||||
import string
|
||||
import io
|
||||
import re
|
||||
import string
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from tclint.commands import CommandArgError
|
||||
from tclint.commands import builtin as _builtin
|
||||
from tclint.commands.checks import check_command
|
||||
from tclint.lexer import (
|
||||
Lexer,
|
||||
TclSyntaxError,
|
||||
STATE_BRACEDWORD,
|
||||
TOK_ALPHA_CHARS,
|
||||
TOK_ARG_EXPANSION,
|
||||
TOK_BACKSLASH_NEWLINE,
|
||||
TOK_DOLLAR,
|
||||
TOK_EOF,
|
||||
TOK_HASH,
|
||||
TOK_LBRACE,
|
||||
TOK_LBRACKET,
|
||||
TOK_LPAREN,
|
||||
TOK_NAMESPACE_SEP,
|
||||
TOK_NEWLINE,
|
||||
TOK_NUM_CHARS,
|
||||
TOK_QUOTE,
|
||||
TOK_RBRACE,
|
||||
TOK_RBRACKET,
|
||||
TOK_RPAREN,
|
||||
TOK_SEMI,
|
||||
TOK_WS,
|
||||
TOK_QUOTE,
|
||||
TOK_ARG_EXPANSION,
|
||||
TOK_LBRACE,
|
||||
TOK_RBRACE,
|
||||
TOK_LBRACKET,
|
||||
TOK_RBRACKET,
|
||||
TOK_DOLLAR,
|
||||
TOK_LPAREN,
|
||||
TOK_RPAREN,
|
||||
TOK_HASH,
|
||||
TOK_ALPHA_CHARS,
|
||||
TOK_NUM_CHARS,
|
||||
TOK_NAMESPACE_SEP,
|
||||
TOK_EOF,
|
||||
Lexer,
|
||||
TclSyntaxError,
|
||||
)
|
||||
from tclint.syntax_tree import (
|
||||
Script,
|
||||
Comment,
|
||||
ArgExpansion,
|
||||
BareWord,
|
||||
BinaryOp,
|
||||
BracedExpression,
|
||||
BracedWord,
|
||||
Command,
|
||||
CommandSub,
|
||||
ArgExpansion,
|
||||
VarSub,
|
||||
BareWord,
|
||||
BracedWord,
|
||||
QuotedWord,
|
||||
Comment,
|
||||
CompoundBareWord,
|
||||
List,
|
||||
Expression,
|
||||
BracedExpression,
|
||||
ParenExpression,
|
||||
UnaryOp,
|
||||
BinaryOp,
|
||||
TernaryOp,
|
||||
Function,
|
||||
List,
|
||||
Node,
|
||||
ParenExpression,
|
||||
QuotedWord,
|
||||
Script,
|
||||
TernaryOp,
|
||||
UnaryOp,
|
||||
VarSub,
|
||||
)
|
||||
from tclint.commands import CommandArgError, get_commands
|
||||
from tclint.commands.checks import check_command
|
||||
from tclint.violations import Rule, Violation
|
||||
|
||||
|
||||
@@ -98,22 +102,26 @@ class _Word:
|
||||
|
||||
|
||||
class Parser:
|
||||
def __init__(self, debug=False, command_plugins=None):
|
||||
def __init__(self, debug=False, commands: Optional[dict] = None):
|
||||
self._debug = debug
|
||||
self._debug_indent = 0
|
||||
# TODO: better way to handle this?
|
||||
self.violations = []
|
||||
self.violations: list[Violation] = []
|
||||
|
||||
if command_plugins is None:
|
||||
command_plugins = []
|
||||
self._commands = get_commands(command_plugins)
|
||||
if commands is None:
|
||||
commands = _builtin.commands
|
||||
self._commands = commands
|
||||
|
||||
# Used to normalize newlines consistently with open()'s universal newlines mode.
|
||||
self._decoder = io.IncrementalNewlineDecoder(None, True)
|
||||
|
||||
def debug(self, *msg):
|
||||
if self._debug:
|
||||
print(" " * self._debug_indent, end="")
|
||||
print(*msg)
|
||||
|
||||
def parse(self, script, pos=None):
|
||||
def parse(self, script: str, pos: Optional[Tuple[int, int]] = None):
|
||||
script = self._decoder.decode(script, True)
|
||||
lexer = Lexer(pos=pos)
|
||||
lexer.input(script)
|
||||
tree = self._parse_script(lexer, in_command_sub=False)
|
||||
@@ -191,6 +199,7 @@ class Parser:
|
||||
self._debug_indent += 1
|
||||
pos = ts.pos()
|
||||
|
||||
script: Script | CommandSub
|
||||
if in_command_sub:
|
||||
script = CommandSub(pos=pos)
|
||||
else:
|
||||
@@ -520,7 +529,7 @@ class Parser:
|
||||
self._debug_indent -= 1
|
||||
return script
|
||||
|
||||
def parse_list(self, node):
|
||||
def parse_list(self, node: Node) -> List:
|
||||
"""Parse contents of node as Tcl list. This is a distinct entry point
|
||||
that doesn't get used when generating the main syntax tree, but is used
|
||||
in command-specific argument parsing.
|
||||
@@ -756,9 +765,14 @@ class Parser:
|
||||
operator = ts.value()
|
||||
ts.next()
|
||||
else:
|
||||
raise TclSyntaxError(
|
||||
f"invalid operator in expression: {ts.value()}", pos, ts.pos()
|
||||
)
|
||||
message = "invalid operator in expression: "
|
||||
if ts.value() == "\\ ":
|
||||
message += (
|
||||
"\\ (check for trailing whitespace if it's the end of the line)"
|
||||
)
|
||||
else:
|
||||
message += ts.value()
|
||||
raise TclSyntaxError(message, pos, ts.pos())
|
||||
|
||||
return BareWord(operator, pos=pos, end_pos=ts.pos())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user