mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
getting closer
This commit is contained in:
parent
363cb35bfe
commit
aa97b5a333
4 changed files with 38 additions and 15 deletions
|
@ -720,7 +720,7 @@ def test_rshift_eq():
|
|||
yield check_stmts, 'x = 42; x >>= 2'
|
||||
|
||||
def test_assert():
|
||||
yield check_stmts, 'assert True'
|
||||
yield check_stmts, '1assert True'
|
||||
|
||||
def test_assert():
|
||||
yield check_stmts, 'assert True'
|
||||
|
@ -875,11 +875,10 @@ def test_return_x_comma():
|
|||
def test_return_x_y():
|
||||
yield check_stmts, 'return x, y', False
|
||||
|
||||
def test_if_true():
|
||||
yield check_stmts, 'if True:\n pass'
|
||||
|
||||
|
||||
|
||||
|
||||
#DEBUG_LEVEL = 1
|
||||
DEBUG_LEVEL = 1
|
||||
#DEBUG_LEVEL = 100
|
||||
|
||||
|
||||
|
|
|
@ -8,4 +8,4 @@ from ast import Module, Num, Expr, Str, Bytes, UnaryOp, UAdd, USub, Invert, \
|
|||
Assign, AugAssign, BitXor, BitAnd, BitOr, LShift, RShift, Assert, Delete, \
|
||||
Del, Pass, Raise, Import, alias, ImportFrom, Continue, Break, Yield, \
|
||||
YieldFrom, Return, IfExp, Lambda, arguments, arg, Call, keyword, \
|
||||
Attribute, Global, Nonlocal
|
||||
Attribute, Global, Nonlocal, If
|
|
@ -31,11 +31,15 @@ class Lexer(object):
|
|||
self.fname = ''
|
||||
self.last = None
|
||||
self.lexer = None
|
||||
#self.indent = '\n'
|
||||
self.indent = ''
|
||||
|
||||
def build(self, **kwargs):
|
||||
"""Part of the PLY lexer API."""
|
||||
self.lexer = lex.lex(object=self, **kwargs)
|
||||
self.lexer.lineno = 1
|
||||
#self.indent = '\n'
|
||||
self.indent = ''
|
||||
|
||||
@property
|
||||
def lineno(self):
|
||||
|
@ -91,7 +95,7 @@ class Lexer(object):
|
|||
#
|
||||
tokens = pykeywords + (
|
||||
# Misc
|
||||
'NAME', 'INDENT', 'NEWLINE', 'ENDMARKER', 'WHITESPACE',
|
||||
'NAME', 'INDENT', 'DEDENT', 'NEWLINE', 'ENDMARKER', 'WHITESPACE',
|
||||
'NONE', 'TRUE', 'FALSE',
|
||||
|
||||
# literals
|
||||
|
@ -154,13 +158,33 @@ class Lexer(object):
|
|||
#
|
||||
# Rules
|
||||
#
|
||||
t_INDENT = r'^[ \t]+'
|
||||
t_ignore_WHITESPACE = r'[ \t]+'
|
||||
def t_INDENT(self, t):
|
||||
r'[ \t]+'
|
||||
if self.last.type != 'NEWLINE':
|
||||
t.lexer.skip(1)
|
||||
return
|
||||
i = self.indent
|
||||
v = t.value
|
||||
if len(i) > len(v):
|
||||
if not i.startswith(v):
|
||||
self._error("indentation level does not match previous level", t)
|
||||
t.type = 'DEDENT'
|
||||
elif not v.startswith(i):
|
||||
self._error("indentation level does not match previous level", t)
|
||||
self.indent = v
|
||||
t.lexer.lineno += 1
|
||||
return t
|
||||
|
||||
#t_ignore_WHITESPACE = r'[ \t]+'
|
||||
#t_ignore_WHITESPACE = r'[^\n][ \t]+'
|
||||
t_ENDMARKER = r'\x03'
|
||||
|
||||
# Newlines
|
||||
def t_NEWLINE(self, t):
|
||||
r'\n+'
|
||||
#if self.indent != '':
|
||||
# self.indent = ''
|
||||
# t.type = 'DEDENT'
|
||||
t.lexer.lineno += t.value.count("\n")
|
||||
return t
|
||||
|
||||
|
|
|
@ -286,11 +286,11 @@ class Parser(object):
|
|||
p[0] = p0
|
||||
|
||||
def p_file_input(self, p):
|
||||
#"""file_input : newline_or_stmt
|
||||
# | file_input newline_or_stmt
|
||||
"""file_input : newline_or_stmt ENDMARKER
|
||||
| file_input newline_or_stmt ENDMARKER
|
||||
"""file_input : newline_or_stmt
|
||||
| file_input newline_or_stmt
|
||||
"""
|
||||
#"""file_input : newline_or_stmt ENDMARKER
|
||||
# | file_input newline_or_stmt ENDMARKER
|
||||
if len(p) == 3:
|
||||
# newline_or_stmt ENDMARKER
|
||||
p[0] = p[1]
|
||||
|
@ -880,9 +880,9 @@ class Parser(object):
|
|||
|
||||
def p_suite(self, p):
|
||||
"""suite : simple_stmt
|
||||
| NEWLINE INDENT stmt_list
|
||||
| NEWLINE INDENT stmt DEDENT
|
||||
| NEWLINE INDENT stmt_list DEDENT
|
||||
"""
|
||||
# | NEWLINE INDENT stmt_list DEDENT
|
||||
p[0] = p[1:]
|
||||
|
||||
def p_test(self, p):
|
||||
|
|
Loading…
Add table
Reference in a new issue