aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
Commit message (Collapse)AuthorAge
* Improve logging for parsing skylark files.Gravatar twerth2018-07-09
| | | | | | | Also add preconditions check. RELNOTES: None. PiperOrigin-RevId: 203731929
* Use Identifiers instead of StringsGravatar Taras Tsugrii2018-06-08
| | | | | | | | | | | | The high level summary of the changes: - use `Identifier` instead of `name` in `Keyword` and `Parameter`. - construct `Identifier` through a factory method in case future interning is desired. These changes are in preparation for using `Identifier` instead of `name` for environment lookups. Closes #5304. PiperOrigin-RevId: 199869171
* Reject files when the first line is indented.Gravatar laurentlb2018-05-24
| | | | | | | | | | | | A bug in the lexer ignored indentation on the first line of a file. This now causes an error. Also, remove the COMMENT token from the lexer. Comments are now accessed separately. This will allow further optimizations in the lexer. It also aligns the code a bit more with the Go implementation. RELNOTES[INC]: Indentation on the first line of a file was previously ignored. This is now fixed. PiperOrigin-RevId: 197889775
* Make the parser look at only one Token at a time.Gravatar laurentlb2018-05-22
| | | | | | | | | Remove all references to `Token` (except one) in the parser. In particular, remove the mechanism to push tokens back. This change will make possible for the lexer to reuse tokens instead of allocating new objects each time. RELNOTES: None. PiperOrigin-RevId: 197585185
* Skylark: do not eagerly scan the whole fileGravatar laurentlb2018-05-22
| | | | | | | | With this change, the parser explicitly asks the lexer to give the next token. To avoid changing the lexer too much, the tokenize() method populates a queue (it may add multiple tokens at the same time). While this reduces the peak memory usage, further work is needed to actually improve the performance. RELNOTES: None. PiperOrigin-RevId: 197576326
* Clarify parser error for load() statementsGravatar brandjon2018-02-22
| | | | | RELNOTES: None PiperOrigin-RevId: 186693205
* Skylark: SlicingExpression: do not create new nodes for optional expressionsGravatar laurentlb2018-02-12
| | | | | RELNOTES: None. PiperOrigin-RevId: 185353994
* Replace all usages of Blaze's Preconditions class with guava.Gravatar tomlu2017-11-09
| | | | | | | | Blaze had its own class to avoid GC from varargs array creation for the precondition happy path. Guava now (mostly) implements these, making it unnecessary to maintain our own. This change was almost entirely automated by search-and-replace. A few BUILD files needed fixing up since I removed an export of preconditions from lib:util, which was all done by add_deps. There was one incorrect usage of Preconditions that was caught by error prone (which checks Guava's version of Preconditions) that I had to change manually. PiperOrigin-RevId: 175033526
* Parser: fix incorrect end location for statement suites.Gravatar fzaiser2017-10-24
| | | | | | | This used to be annoying for Skylint. RELNOTES: none PiperOrigin-RevId: 173249428
* Preserve `pass` statements in the Skylark AST.Gravatar fzaiser2017-10-23
| | | | | RELNOTES: none PiperOrigin-RevId: 173125138
* Fix the location of load statements in Skylark.Gravatar fzaiser2017-10-10
| | | | | | | Previously, the closing parenthesis was not included in the location. RELNOTES: none PiperOrigin-RevId: 171527078
* Reduce iterator usage on hot code pathsGravatar michajlo2017-10-07
| | | | | | | | Micro-optimize a few hot code paths which have a habit of iterating over short O(1)-access lists. RELNOTES: None PiperOrigin-RevId: 171347524
* Fix end offset of expressions in Skylark parserGravatar fzaiser2017-09-26
| | | | | | | | | | | | | This CL doesn't fix all of the problems. The end location of blocks after an if, elif, else and for is still wrong. (I added TODOs for them) The latter is not easy to fix: One might think that one could just set the end location of a block to the end location of the last statement. However, if the last statement is a "pass" statement, this is not preserved in the AST, in particular, there's no location for it. In the future, we probably want to preserve "pass" statements. RELNOTES: none PiperOrigin-RevId: 170028466
* skylark/syntax: Move flow statement check to the validation pass.Gravatar laurentlb2017-09-04
| | | | | | | Mutiple other cleanups in the parser, update code documentation. RELNOTES: None. PiperOrigin-RevId: 167501136
* Remove the Dialect type from the Parser.Gravatar laurentlb2017-09-01
| | | | | | | | Let's use the same parser. Dialect differences are checked in a separate validation pass. RELNOTES: None. PiperOrigin-RevId: 167280201
* Refactor: Parse return statements without an expression properlyGravatar fzaiser2017-08-24
| | | | | | | | This is an internal refactoring necessary for the Skylark linter. It does not change any behavior. RELNOTES: None PiperOrigin-RevId: 166199367
* Remove dialect distinction from the parser.Gravatar laurentlb2017-08-22
| | | | | RELNOTES: None. PiperOrigin-RevId: 166058718
* Fix Skylark parsing of call expressions.Gravatar fzaiser2017-08-14
| | | | | | | | This allows more complex expressions to be called, not just identifiers. For example, "x[0]()" is not a syntax error anymore. RELNOTES: None PiperOrigin-RevId: 165157981
* Refactor FuncallExpression to allow for complex function terms later.Gravatar fzaiser2017-08-14
| | | | | RELNOTES: None. PiperOrigin-RevId: 164981071
* Minor optimization to function arg parsingGravatar michajlo2017-08-07
| | | | | | | No need for the intermediate collection/objects when we can go direct to ImmutableList, which has a good chance of doing something more efficient anyway... PiperOrigin-RevId: 164294883
* Misc cleanups of AST node APIGravatar brandjon2017-07-12
| | | | | | | | | - changed field names and a couple accessors to consistently use full words ("statement" instead of "stmt") - applied several local analyzers (from IntelliJ) to remove redundant modifiers, unnecessary explicit types (yay Java 8), etc. RELNOTES: None PiperOrigin-RevId: 161551096
* Prohibit multiple load() statements from appearing on the same lineGravatar brandjon2017-07-07
| | | | | | | | This is an incompatible change, but it's an obvious bug. RELNOTES[INC]: Fixed a bug whereby multiple load() statements could appear on the same line PiperOrigin-RevId: 161070399
* Make 'load' a keywordGravatar laurentlb2017-07-05
| | | | | | | RELNOTES[INC]: `load` is now a language keyword, it cannot be used as an identifier PiperOrigin-RevId: 160944121
* Automated conversion to Java 8Gravatar laurentlb2017-06-30
| | | | | | | With a few manual fixes for readability. RELNOTES: None. PiperOrigin-RevId: 160582556
* Lambda cleanupGravatar laurentlb2017-06-29
| | | | | RELNOTES: None. PiperOrigin-RevId: 160516183
* Add more helpers to ParserGravatar brandjon2017-06-28
| | | | | | | This simplifies parsing a lone statement or expression in unit tests. RELNOTES: None PiperOrigin-RevId: 160276410
* Turn unary minus into a proper AST nodeGravatar brandjon2017-06-28
| | | | | | | This unifies unary minus with NotExpression, and moves the minus logic from a fake builtin function into the interpreter proper. RELNOTES: None PiperOrigin-RevId: 160266266
* Make equality, comparison and 'in' operators not associative.Gravatar laurentlb2017-06-19
| | | | | | | | | | | | I'm not using a --incompatible-change flag because it's not available in the parser. We could pass it, but I think this is trivial to fix and unlikely to happen in real code (if it does, there was most likely a bug). RELNOTES[INC]: Operators for equality, comparison, 'in' and 'not in' are no longer associative, e.g. x < y < z is now a syntax error. Before, it was parsed as: (x < y) < z. PiperOrigin-RevId: 159422042
* Require parentheses around tuple in list comprehension filtering.Gravatar laurentlb2017-06-19
| | | | | | | | | | | This affects only the tuple that appears after 'if' inside a list comprehension. Since a truth value is expected, it's very unlikely to break existing code. It's technically a breaking change, but it's not worth introducing a flag for this. RELNOTES: Parentheses around the tuple are now mandatory in [a for b in c if 1, 2] PiperOrigin-RevId: 159218397
* Refactor AST APIsGravatar brandjon2017-06-13
| | | | | | | Added public visibility to some constructors/accessors, and made child LValue nodes explicitly constructed by the caller rather than hidden inside constructors. This makes it easier to treat nodes as uniform dumb values. Also added some helpers. RELNOTES: None PiperOrigin-RevId: 158761415
* Add operator // for division.Gravatar laurentlb2017-05-22
| | | | | | | | In both Python 2 and Python 3, the operator // is used for int division. With Python 3, operator / is for float division. RELNOTES: None. PiperOrigin-RevId: 156582262
* Refactor comprehensions and other AST nodesGravatar brandjon2017-05-15
| | | | | | | | | | * Cleanup ForClause and IfClause to be static classes * Add missing/non-visible accessors and constructors * Make use of final modifiers more consistent * Make LValue an ASTNode. RELNOTES: None PiperOrigin-RevId: 156050683
* Use skylark-preferred quote char for string literalGravatar Michajlo Matijkiw2017-02-23
| | | | | | | | | | We currently have no need to discern between strings quoted with ' or ". While it could be nice for something one day (and may have been in the past), it's yagni now. Removing the distinction simplifies string concatenation. -- PiperOrigin-RevId: 148273400 MOS_MIGRATED_REVID=148273400
* Require parens around tuple with trailing comma.Gravatar Laurent Le Brun2017-01-17
| | | | | | | | | | RELNOTES[INC]: Tuples that end with a trailing comma must now be inside parens, e.g. (1,) instead of 1, -- PiperOrigin-RevId: 144690953 MOS_MIGRATED_REVID=144690953
* Add a new AST node for augmented assignments in SkylarkGravatar Vladimir Moskva2016-12-19
| | | | | | -- PiperOrigin-RevId: 142438943 MOS_MIGRATED_REVID=142438943
* Cleanup in the parserGravatar Laurent Le Brun2016-10-26
| | | | | | | | | | - Move break/continue check from ValidationEnvironment to the Parser - Remove some differences between BUILD / Skylark parsing mode - Fix location off-by-one error in the break/continue tokens - Remove duplicated error message ('for loops are not allowed on top-level') -- MOS_MIGRATED_REVID=137259929
* Refactoring for LoadStatementGravatar Laurent Le Brun2016-10-13
| | | | | | | | | | Use StringLiteral instead of String+Location. This improves consistency. getRawImports() now returns StringLiterals, which makes possible to show location in error messages. -- MOS_MIGRATED_REVID=136019586
* Automated cleanupGravatar Laurent Le Brun2016-10-12
| | | | | -- MOS_MIGRATED_REVID=135816105
* Improve error message when 'del' keyword is usedGravatar Laurent Le Brun2016-10-11
| | | | | -- MOS_MIGRATED_REVID=135784854
* Remove support for "Python" parsing mode.Gravatar Laurent Le Brun2016-10-07
| | | | | | | It was unused in Bazel. -- MOS_MIGRATED_REVID=135483937
* Index and slice calls are implemented as separate AST nodes rather than specialGravatar Vladimir Moskva2016-09-15
| | | | | | | function calls. -- MOS_MIGRATED_REVID=133259901
* Move SkylarkImport from LoadStatement to BuildFileASTGravatar Miguel Alcon Pinto2016-08-22
| | | | | | | This allow us to skip the import validation in non-build usages. -- MOS_MIGRATED_REVID=130936612
* Remove static checks from the parser.Gravatar Laurent Le Brun2016-08-04
| | | | | -- MOS_MIGRATED_REVID=129313959
* Preliminary cleanup for removing Blaze-specific code from the environmentGravatar Laurent Le Brun2016-08-03
| | | | | | | | The goal is to remove parse and eval functions from Environment, as well as isSkylark boolean. -- MOS_MIGRATED_REVID=129202204
* Fix private symbols, clean up load parsingGravatar Jon Brandvein2016-07-29
| | | | | -- MOS_MIGRATED_REVID=128699330
* Add support for more augmented-assignment operators.Gravatar Googler2016-06-03
| | | | | | | | | based on my limited understanding of python syntax, the only things we don't support is //= and **=, but it looks like skylark doesn't support the corresponding infix operators. RELNOTES[NEW]: add support for the '-=', '*=', '/=', and'%=' operators to skylark. Notably, we do not support '|=' because the semantics of skylark sets are sufficiently different from python sets. -- MOS_MIGRATED_REVID=123889776
* Add error message for skylark for-else statement, and fix error message for ↵Gravatar Yue Gan2016-04-07
| | | | | | | single else statement. -- MOS_MIGRATED_REVID=119260729
* Remove syntactic sugar when assigning to a dict item.Gravatar Laurent Le Brun2016-01-07
| | | | | | | | | | | | | | e.g. a['key'] = value is handled through a proper lvalue, instead of using syntactic sugar. Benefits include: - better error messages (reference to the '+' operator was cryptic) - more robust, e.g. it is compatible with the += operator - can be used in a tuple, e.g. a[1], a[2] = 3, 4 - it is a step towards mutable dict -- MOS_MIGRATED_REVID=111597545
* Add the source location of the import string to the LoadStatement AST node, ↵Gravatar John Field2016-01-04
| | | | | | | for use in tools. -- MOS_MIGRATED_REVID=111142252
* Enable label-based Skylark loading. In particular, such labels may reference ↵Gravatar John Field2015-12-22
| | | | | | | | | | | | | | | | | | | files in external repositories. In addition: - Cleaned up and refactored some tests to reflect the new loading behavior. Deferred to future CLs: - Updating Bazel Skylark documentation to reflect the new load form. - Enabling command-line loading of Aspects via labels. RELNOTES: Skylark load statements may now reference .bzl files via build labels, in addition to paths. In particular, such labels can be used to reference Skylark files in external repositories; e.g., load("@my_external_repo//some_pkg:some_file.bzl", ...). Path-based loads are now deprecated and may be disabled in the future. Caveats: Skylark files currently do not respect package visibility; i.e., all Skylark files are effectively public. Also, loads may not reference the special //external package. -- MOS_MIGRATED_REVID=110786452