Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--ast is missing information #177

Open
atsepkov opened this issue Oct 13, 2012 · 5 comments
Open

--ast is missing information #177

atsepkov opened this issue Oct 13, 2012 · 5 comments

Comments

@atsepkov
Copy link

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.

satyr added a commit that referenced this issue Oct 13, 2012
@satyr
Copy link
Owner

satyr commented Oct 13, 2012

Added function names there. Any other missing?

@atsepkov
Copy link
Author

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

satyr added a commit that referenced this issue Oct 13, 2012
@satyr
Copy link
Owner

satyr commented Oct 13, 2012

Done.

@atsepkov
Copy link
Author

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.

@satyr
Copy link
Owner

satyr commented Oct 13, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants