Author Topic: AST: Possible to printout the AST-tree?  (Read 2493 times)

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
AST: Possible to printout the AST-tree?
« on: August 24, 2013, 02:44:10 am »
Now a bunch of questions, but they're not probably too very "advanced" for experienced nBNF developers.

Q1: Print tree - Is it possible to print out the AST-tree to file or to clipboard?

Q2: Expand tree - Is it possible to auto-expand the AST-tree after new parsing (it kills me to open the AST-treeview Xxx times a day while designing the rules...)

Q3: Script - Can the AST-tree be accessed via script?

Q4: MDG remnant is stuck - How can I remove an old MDG which seems to have got stuck. When I uppdate new versions I can uninstall the MDGs and install them again, except for one (the first with this name/id) which seems to have got stuck. It won't let go when I untick the MDG and drop the path to its location. Some caching problem I guess.

Q5: Two legs in the Parse tree? - I notice that one can parse a source file along two "legs", flat FILE level and/or drill down the PACKAGE path. Can both be parsed, or do I have to chose one, and if so, which one to go? I know in advance that I will need to lump several classes together into one file, which gives me the gut feeling that it's the PACKAGE path I want to trod. Is this assumption correct, or does it matter which path to parse? or are both needed for different scenarios? I will generate both belonging to functions classes ("methods") and flat "freestanding" functions ("functions") with only the package as the "owning parent".

Q6: Method ownership - How do I "bind" a method to a class regarding the fact that several classes can (will) be located in the same source file. Example:

[size=12]
// Type def:
// ----------------------------------------------------------------------
type ClassOne struct {
    AttributeOne int
    /* SomeMethodOne() string */
}

type ClassTWO struct {
    AttributeTWO int
    /* SomeMethodTWO() string */
}

// Implement:
// ----------------------------------------------------------------------
func (self *ClassOne) SomeMethodOne() string {
    // ...
}

func (self *ClassTWO) SomeMethodTWO() string {
    // ...
}[/size]


The Q again more clearly - In regular imperative code one would keep track of the class names and then match the method with the class somehow, but I guess that's not how it's done in nBNF. But METHOD's doesn't seem to have a "parent" or "owner" property, so how do I match a method to the right class?

// Rolf
« Last Edit: August 24, 2013, 02:54:50 am by Rolf_Lampa »
-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7731
  • Karma: +103/-18
    • View Profile
Re: AST: Possible to printout the AST-tree?
« Reply #1 on: August 26, 2013, 09:07:00 am »
Firstly, as far as I know you're the only user who has attempted to use this feature since it's introduction. Either that's true or you're the only one who has stuck with it enough to ask questions.

1. No.
2. No. Probably the easiest way around this is to parse a small subset instead of the full file by selecting the rule to start on in the debug window.
3. It hasn't been exposed/documented yet.
4. Not sure what you're descibing.
5. From your question it sounds like you have something similar to the Java idea. Declare the package at the top then continue. If that's the case then I recommend creating a PACKAGE node that contains everything else in the file.
6. You can mark the class name with the QUALIFIER attribute. Unfortunately I don't remember if it needs to be declared in the class itself for EA to look for the matching method.
Eve

support@sparxsystems.com

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: AST: Possible to printout the AST-tree?
« Reply #2 on: August 28, 2013, 11:22:11 am »
Quote
4. Not sure what you're descibing.
With "MDG remnant is stuck" I refer to the list of available MDG technologies ( Settings > MDG Technologies > [list of check boxes to activate/deactivate]). In that list I managed to get my first version of MDG technology to show up containing the AST etc, and I could tick the check box to activate it. And it actually worked fairly well but the first version contained only a subset of the AST rules, so I made changes to the MDG and tried to update. But then my problems started. The new version of the MDG was ADDED instead of REPLACED, so now I had two MDG Technologies although different versions.

The first version then simply wouldn't go away.

Well, I didn't have the time to wrestle that stubborn first version MDG so I went about making more changes and updated the MDG again and this time the second MDG Technology (version 2) updated neatly to version 3. And so on, aso. But the first version I simply don't get rid of.

I tried unticking the checkbox in the list of MDGs, and I also tried to remove the path to it via the "Advanced" button under the list, but no luck. It's "stuck". No clue as to how to get rid of it. There's no "delete" button to press.

But perhaps there's some XML config file somewhere where I can manually remove any reference to this stubborn MDG remnant? (it's "dead" but it confuses EA when ticking the activation checkbox, but nothing more serious than that. Except for irritating me.

Quote
5. (...legs in the Parse tree) From your question it sounds like you have something similar to the Java idea...
Unfortunately I'm not fluent with Java so I can't tell, but what I want to achieve is that from for example the code snippet above (containing two classes, or "structs" in this Golang case) I want the source code import to result in that all the classes defined in the file would go into one individual model Package in EA, with the same Package name as the file's package name located at the top of the file (like if the unit name in Delphi would result in the same model Package name in EA. In Delphi you can also have multiple classes, both their declarations and implementations, in one file). In this case I'm wrestling Golang which can have package names spanning over several different files (same package name inside different filenames.go ).

Quote
6. You can mark the class name with the QUALIFIER attribute. Unfortunately I don't remember if it needs to be declared in the class itself for EA to look for the matching method.

Oki, I'll play around with that. I'll probably find my way with this info.

Thank you again Simon, this is fun!

// Rolf
« Last Edit: August 28, 2013, 11:28:15 am by Rolf_Lampa »
-- There's always a solution --

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2901
  • Karma: +52/-3
    • View Profile
Re: AST: Possible to printout the AST-tree?
« Reply #3 on: August 28, 2013, 11:36:07 am »
Quote
The first version then simply wouldn't go away.
Go Settings > MDG Technologies and select this mystery technology. Over on the right somewhere, it will tell you the location of it. If it says "Location: Project", open the Resources window (Alt+6) and delete it from there. If it just says "Location: MyFilename.xml" then look in the MDG Technologies folder under the EA program files path. If it says "Location: Extensions (MyAddin)" then remove it from your addin. Otherwise it will tell you the full file path.
The Sparx Team
support@sparxsystems.com