--ast is missing information
Opened this issue · 5 comments
While I haven't examined the AST tree in enough detail to see if anything else is missing, I've noticed that function names seem to be gone from the generated ast when using --ast command. For anonymous functions this doesn't matter, since the actual name is whatever they get assigned to. For functions created using the 'function' keyword, however, this is a problem.
A quick example is to run 'bin/coco --ast src/ast.co', the only function that has a name is 'this$', which I'm guessing is an internally generated function rather than user-defined.
Added function names there. Any other missing?
Thanks. Found another one. The following shorthand also seems to lose information in the ast about the negated side:
!=@negated
The ast only tracks the left portion (this.negated) and not (!this.negated) part
Done.
Thanks, I really appreciate the changes (working on an internal project to auto-standardize the syntax and the AST tree is working great for that), another thing is that for loop representation seems to be inconsistent (when using multiple iteration arguments). For example, a typical loop on line 24 of ast.co, 'for tmp of that' portion is represented as:
For
Var tmp
Var that
Block
While a 2-argument loop on line 1277 of ast.co 'for test, i in items' gets represented as follows, which seems even more odd, since representation of i and test is inconsistent with eachother within the same statement as well:
For i
Var test
Var items
Block
It looks like after parsing the first argument, the logic just skips to the array.
working on an internal project to auto-standardize the syntax
In that case you may want to use --json
:
$ coco -aej 'for t of ts then'
{
"type": "Block",
"lines": [
{
"type": "For",
"item": {
"type": "Var",
"value": "t",
"line": 1
},
"index": "",
"source": {
"type": "Var",
"value": "ts",
"line": 1
},
"body": {
"type": "Block",
"lines": [],
"line": 1
},
"else": null
}
]
}
or directly interact with the compiler:
$ coco -i
coco> Coco.ast 'for t of ts then' .lines
[ { item: { value: 't', line: 1 },
index: '',
source: { value: 'ts', line: 1 },
body: { lines: [], line: 1 },
else: null } ]
coco>
The tree view you're using is for quick debugging and isn't meant to show all the information.