aboutsummaryrefslogtreecommitdiff
path: root/syntax/parse_test.go
AgeCommit message (Collapse)Author
2018-10-23rename skylark -> starlarkAlan Donovan
Change-Id: Iebd0e040ff674b2f9da39bf5242c8afaa7f4ddc8
2018-04-02compile: optimize a+b statically for literal string/list/tuple (#97)alandonovan
* compile: optimize a+b statically for literal string/list/tuple Previously, the parser would fold two string literals "a"+"b" into a fake string literal, to avoid quadratic runtime cost when a long chain of strings is added (as often happens due to line length limits). This made the syntax tree unfaithful to the source, preventing the frontend from being used in a reformatting tool. This change does the same optimization in the compiler, and generalizes it to list and tuple expressions too: "a b" + "c d" => "a bc d" [a, b] + [c, d] => [a, b, c, d] (a, b) + (c, d) => (a, b, c, d) It also creates the seam for later addition of the "accumulator" optimization, in which n-ary non-literal additions such as a+b+c are optimized to: acc = start(a) acc.add(b) acc.add(c) acc.done() I evaluated this optimization but it doesn't yet pull its weight on the kinds of builds I can do so far.
2018-02-26Add new node ParenExpr (#65)Laurent Le Brun
This is a no-op for the interpreter, but it adds more information to the AST.
2018-02-22Attach comments to AST nodes. (#64)Laurent Le Brun
* Attach comments to AST nodes. This feature is off by default. More testing will be needed before exposing it to the ParseFile function. Logic is copied from Buildifier (https://github.com/bazelbuild/buildtools/tree/master/build). bug #63 * Fix tests by saving the state of 'blank' in the scanner. * - Rename flattenAST - Add new argument to the Parser and the Scanner - Update tests * Remove global constant keepComments * Update more tests (new argument to the parser) * Add CommentsRef to allow allocating comments Address a few other issues * Remove the COMMENT tokens Parser won't see COMMENT tokens anymore. The list is kept by the scanner. This simplifies the code and reverts some of my previous changes. * Address review comments * - Removed the .Suffix boolean - Renamed CommentsRef to commentsRef - Simplified assignComments function (reversing was not useful) * assignComments leaves early if there is no comments + address other review comments * Address review comments (for -> if, removed useless code about suffix comments)
2018-01-16parser: fix precedence of nested 'if' clauses in list comprehensions (#55)alandonovan
* parser: fix precedence of nested 'if' clauses in list comprehensions Before, the parser would consume an arbitrary expression after the 'if' even though it should reduce after x in [a for b in c if x if y else z] Now it consumes only a precedence zero ("or"-level) expression. The parser similarly reduces after x when parsing [a for b in c if lambda: x if y else z] * fix three comment typos
2017-10-20syntax: make 'load' a reserved word (#31)alandonovan
* syntax: make 'load' a reserved word
2017-10-10syntax: allow newline after expressionAlan Donovan
Change-Id: I3087d84e4be9f85a68ec088ea5935a7d18fd0407
2017-10-02skylark: create GitHub repository from google3@170697745Alan Donovan