diff options
author | alandonovan <adonovan@google.com> | 2019-01-04 13:48:12 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-04 13:48:12 -0500 |
commit | 30e71c6b16e7cb4257d5436cb317ee1e989f1774 (patch) | |
tree | 12973d93ac3a8722fe92d52f149b15cc2abbd199 /syntax/scan_test.go | |
parent | 9d9777168d883df01c5a74800b807e5315fb9850 (diff) | |
download | starlark-go-30e71c6b16e7cb4257d5436cb317ee1e989f1774.tar.gz |
syntax: improve REPL parsing (#98)
Previously, the REPL used a heuristic: it would consume a single line
and attempt to parse it; if that failed, it would consume lines up to
a blank line then parse the whole as a file. This was suboptimal for
various reasons: it failed to parse lines ending with an unfinished
multi-line string literal, for example, and it would prematurely
stop reading even while parentheses were open.
This change integrates the REPL with the scanner and parser (as Python
does). The REPL invokes a new parser entry point, ParseCompoundStmt,
that consumes only enough input to parse a compound statement, defined
as (a) blank line, (b) a semicolon-separated list of simple statements
all on one line, or (c) a complex statement such as def, if or for.
If the 'src' value provided to the scanner is a function of type
func() ([]byte, error), then the scanner will call it each time
it runs out of input.
Fixes #81
Diffstat (limited to 'syntax/scan_test.go')
-rw-r--r-- | syntax/scan_test.go | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/syntax/scan_test.go b/syntax/scan_test.go index e01a1c9..9de610e 100644 --- a/syntax/scan_test.go +++ b/syntax/scan_test.go @@ -208,6 +208,7 @@ pass`, "pass newline pass EOF"}, // consecutive newlines are consolidated {"x ! 0", "foo.star:1:3: unexpected input character '!'"}, // github.com/google/starlark-go/issues/80 {"([{<>}])", "( [ { < > } ] ) EOF"}, + {"f();", "f ( ) ; EOF"}, } { got, err := scan(test.input) if err != nil { |