aboutsummaryrefslogtreecommitdiffstats
path: root/parser
Commit message (Collapse)AuthorAgeFilesLines
* Emit errors on mixed property syntaxLogan Chien2018-06-262-3/+5
| | | | | | | | | | | | | | This commit refines `compat` condition in `parseProperty()` so that a module definition would either use the new syntax or the old syntax, but not something in the between, such as cc_library { name: "bad_example", srcs= ["bad.c"], } Test: lunch aosp_arm64-userdebug; make # runs unit test Change-Id: If2d3e5d55edccc28d314d99b83b0f54e5c53ac35
* Improve indentation for multi-line expressionsDan Willemsen2018-05-072-1/+48
| | | | | | | | | | | | | | | | | | | | | | When someone used a multiline string: cmd: "..." + "...", bpfmt used to print this out as: cmd: "..." + "...", This change doesn't do the quote alignment like I see in some of our user-created instances of this, but it does indent a single level: cmd: "..." + "...", Test: unit tests Test: Compared bpfmt results before and after across AOSP Change-Id: I61bf790be9d08a187857b2725facf71e8b38e372
* Add Patch and PatchList for making textual changesColin Cross2018-04-102-1/+134
| | | | | | | | | Patch and PatchList provide an API for making changes to substrings of a Blueprint file by parsing the AST and using the token positions to perform text replacements. Test: modify_test.go Change-Id: Ibb8993221982b54602ba5a05486198fab8d35a67
* Make End() return the position after the nodeColin Cross2018-04-103-43/+147
| | | | | | | | | | | | | End() was previously only used to determine if a comment was within a Node, so it used the expedient definition of the position of the last token in the node. In the next patch it will be used for capturing substrings of the Blueprint file, so make it point to the character after the last token instead. Also add tests for it. Test: parser_test.go Change-Id: Icaff3915b41e251ef9d0aad5615021bf37406aee
* Support parsing int64 in Blueprint file.Nan Zhang2017-11-025-13/+468
| | | | | | | | | | | | | | | | | | | | | | | | Support int64 number instead of int to be more fixed to bit size so that the underlying arch won't affect overflow cases. Besides, refection: func (v Value) Int() int64 always cast to int64 no matter the input is int, int16, int32. Currently we always treat "-" as negative sign to bind to next value, and "+" as plus operator to add operands together. So we allow: a = 5 + -4 + 5 or a = -4 + 5 But we don't allow: a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise, a = 5 + +5 would exist which looks pretty weird. In the future, we may want fully support number calculator logic eg, "+"/"-" can be positive/negative sign or operator, and "(" and ")" will be considered to group expressions with a higher precedence. int & uint properties within struct keeps unchanged, which is only allowed when tagged with 'blueprint:mutated'. We only allow *int64 property instead of int64 property within struct since it does't make sense to do prepending or appending to int64. Change-Id: I565e046dbd268af3538aee148cd7300037e56523
* Utils to support removing duplicate shared_libsJeff Gaston2017-06-281-0/+8
| | | | | | Bug: 62957047 Test: m -j Change-Id: I50d61d2c4a15af571d3bd5ca95f8ff7e3f18c382
* Some util functions to support bpfixJeff Gaston2017-05-231-0/+59
| | | | Change-Id: If53f696fbe937e007b902434f62d0d92435846dd
* Fix error messages containing variable typesColin Cross2016-07-151-1/+1
| | | | | | | value.Type and value.Pos changed to methods, change the users that were not caught by error checking to use Type() or Pos(). Change-Id: I295a658c007fa2de68c89fb85ee367fbea5ed1aa
* printer: support multiple skipped commentsColin Cross2016-07-122-10/+25
| | | | | | | There may be multiple skipped comments in a row, convert p.skippedComments to a list and add a test. Change-Id: I30dcff269bee56fd51ef9513dab7c7885c44b7d7
* Add CommentGroupsColin Cross2016-06-146-65/+154
| | | | | | | | | Determining which comments are contiguous is difficult once they have been parsed into an out-of-band comment list, as any intervening nodes are in a separate structure. Group the comments into CommentGroups during the parsing stage instead. Change-Id: I9444c58e75333b7521b58dbfbd36ff29d139b6e3
* Make everything a NodeColin Cross2016-06-142-6/+32
| | | | | | | Make File, Assignment, and Module implement Node. Nodes will be used later for traversing a File. Change-Id: I938a5d39d48aee7fe174180b12a2870ecf756b34
* Rename Pos membersColin Cross2016-06-144-54/+54
| | | | | | | Pos is going to be part of the Node interface, rename the Pos member of structs to be more specific. Change-Id: Ibd31119863b96d38bf8dac216e026200a54bbe18
* Remove blueprint/parser.IdentColin Cross2016-06-144-72/+91
| | | | | | | | It wasn't adding anything useful, and it resulted in Name.Name to get to the identifier. Replace Name Ident with Name string; NamePos scanner.Position. Change-Id: Idf9b18b31dd563a18f27c602c2d14298955af371
* Refactor blueprint parser nodes to an interfaceColin Cross2016-06-087-677/+899
| | | | | | | | | | | Refactor the blueprint parser Value object, which contained a Type enum and members to hold every possible type, into an interface (now called Expression). Rename the existing Expression object that represented a binary operator Operator. Also adds and fixes some new printer test cases with mulitline expressions. Change-Id: Icf4a20f92c8c2a27f18df8ca515a9d7f282ff133
* Fix bugs related to local vs. inherited variablesColin Cross2015-08-031-26/+61
| | | | | | | | | | | | | | | | | | | | The Go race detector found a race condition in the parser, which highlighted a few related bugs. A variable could be defined but not referenced in a Blueprints file, then appended to in multiple subdirs= Blueprints files. The race detector caught the multiple writes to assignment.Referenced from the parsers for the subdirs Blueprints files, but multiple appends would be much more serious. To fix this, keep local and inherited variables separate in the Scope object and export that info to the parser. Disallow appending to non-local variables, which was already the intended behavior. Only update the referenced boolean for local variables. Together, this should prevent all writes to Assignment objects from parsers other than the one that created them. Also improves the error handling code and some error messages. Change-Id: Idb4f7d2e61bbe28d90b93074764e64e60d1eba8f
* Add deep Copy() for parser typesDan Willemsen2015-07-061-0/+42
| | | | Change-Id: I94bca46d6d30da683cacb0f6ea1fdf26a5a46bc8
* Refactor parsing to allow reuseColin Cross2015-06-301-0/+2
| | | | | | | | Refactor parsing Blueprints and walking the Blueprints tree to allow reuse for tasks that don't involve creating moduleInfo structures. Change-Id: I677857a3462999426c8306432074ea97fdcb86c8
* Add convenience methods to Comment objectsColin Cross2015-06-301-0/+50
| | | | | | | | Add String() to print out the Comment, Text() to print out the Comment while stripping /*, //, and */, and EndLine() to return the line number of the last line of the comment. Change-Id: I076bc0990143acfc03c42a8cc569894fced8ee24
* Update import paths to include githubJamie Gennis2015-03-211-10/+10
|
* Allow parsing Blueprints files without evaluatingColin Cross2015-03-202-68/+76
| | | | | | | | | | | Running bpfmt or bpmodify on a Blueprints file that references variables defined in a parent Blueprints file causes parse errors on unknown variables. Modify the parser to parse in two modes, parser.Parse and parser.ParseAndEval. The first parses without attempting to evaluate variables and expressions, the second performs a full evaluation. Change-Id: Ic11948ea77c8e65379d7260591ada15db0e4f5b9
* Simplify printer whitespace and newline handlingColin Cross2015-03-204-142/+224
| | | | | | | | | | | | | | | Trying to handle all the whitespace and newline printing inside printToken got overly complicated, and resulted in a few bugs in the layout around comments and indentation that were hard to fix. Rewrite the whitespace and newline handling to be handled directly by the object printers, using requestSpace() to ensure whitespace is inserted and requestNewline() to ensure a newline is inserted. Also fixes unnecessarily left aligning all comments that contain indentation, and fixes accidentally unindenting comments that are the last token in their indented block. Change-Id: I18707802726107cf0b6ec7de9b542d0ec1d2c0dd
* Fix whitespace in parser/parser.goColin Cross2015-03-101-4/+4
| | | | Change-Id: I75875cbf60efc9aaf7c2df5709533c2c04b6fba4
* Go back to the old Blueprints file formatColin Cross2015-03-042-76/+64
| | | | | | | | | | | | | | | | | | Switch back to: moduleType { name: value, arch: { x86: { name: value, }, }, } This provides better consistency between properties defined at the top level of a module and properties defined inside a map. The parser will continue to support the other format for now, but the printer will only produce the original format.
* Allow adding mapsColin Cross2015-03-041-0/+47
| | | | | | | | Add support for + operator on maps. The semantics are that keys that exist in both maps are added with the + operator, and keys that exist in one map are copied to the resulting map. Change-Id: Iba9a6f886477a1eb7311272d07944800c806e368
* Support += assignmentsColin Cross2015-03-044-25/+209
| | | | | | | | | Support += assignments to variables. Variables are now mutable up until they are referenced, then they become immutable. This will allow variables to be modified in a conditional, or allow better commenting on why parts of a variable are set. Change-Id: Iad964da7206b493365fe3686eedd7954e6eaf9a2
* Modify printer to be stricter about extra newlinesColin Cross2015-03-042-67/+161
| | | | | | | The printer was allowing extra newlines in odd places, for example between a property name and the '=' in a module definition. Make newline location stricter by explicitly allowing newlines or line comments.
* Add license headers and LICENSE fileColin Cross2015-01-236-0/+84
| | | | Change-Id: I6f7c7374093c0745ee4aa677480376a06648b358
* Move blueprint/* up a directoryColin Cross2015-01-236-0/+1642
Make integrating with go tools easier by putting the blueprint package files in the top level directory of the git project instead of in a subdirectory called blueprint. Change-Id: I35c144c5fe7ddf34e478d0c47c50b2f6c92c2a03