Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
96f0dd3c
Commit
96f0dd3c
authored
Jul 24, 2015
by
Damien George
Browse files
py/parse: Fix handling of empty input so it raises an exception.
parent
fa7c61df
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/grammar.h
View file @
96f0dd3c
...
...
@@ -38,7 +38,7 @@
// eval_input: testlist NEWLINE* ENDMARKER
DEF_RULE
(
single_input
,
nc
,
or
(
3
),
tok
(
NEWLINE
),
rule
(
simple_stmt
),
rule
(
compound_stmt
))
DEF_RULE
(
file_input
,
n
c
,
and
(
1
),
opt_rule
(
file_input_2
))
DEF_RULE
(
file_input
,
c
(
generic_all_nodes
)
,
and
(
1
),
opt_rule
(
file_input_2
))
DEF_RULE
(
file_input_2
,
c
(
generic_all_nodes
),
one_or_more
,
rule
(
file_input_3
))
DEF_RULE
(
file_input_3
,
nc
,
or
(
2
),
tok
(
NEWLINE
),
rule
(
stmt
))
DEF_RULE
(
eval_input
,
nc
,
and
(
2
),
rule
(
testlist
),
opt_rule
(
eval_input_2
))
...
...
py/parse.c
View file @
96f0dd3c
...
...
@@ -720,6 +720,11 @@ memory_error:
goto
syntax_error
;
}
// check that parsing resulted in a parse node (can fail on empty input)
if
(
parser
.
result_stack_top
==
0
)
{
goto
syntax_error
;
}
//result_stack_show(parser);
//printf("rule stack alloc: %d\n", parser.rule_stack_alloc);
//printf("result stack alloc: %d\n", parser.result_stack_alloc);
...
...
tests/basics/parser.py
0 → 100644
View file @
96f0dd3c
# parser tests
# completely empty string
# uPy and CPy differ for this case
#try:
# compile("", "stdin", "single")
#except SyntaxError:
# print("SyntaxError")
try
:
compile
(
""
,
"stdin"
,
"eval"
)
except
SyntaxError
:
print
(
"SyntaxError"
)
compile
(
""
,
"stdin"
,
"exec"
)
# empty continued line
try
:
compile
(
"
\\\n
"
,
"stdin"
,
"single"
)
except
SyntaxError
:
print
(
"SyntaxError"
)
try
:
compile
(
"
\\\n
"
,
"stdin"
,
"eval"
)
except
SyntaxError
:
print
(
"SyntaxError"
)
compile
(
"
\\\n
"
,
"stdin"
,
"exec"
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment