Author Topic: Preserve manual code on codegen  (Read 3038 times)

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Preserve manual code on codegen
« on: July 26, 2013, 01:20:47 am »
Hi,

I made my own code gen templates (= has no reverse enginering of code), and now I wonder:

Q: Is it possible to store the manual code (method bodies) in the model (when tested and fine) as to preserve the manually written code if need be to regenerate the class structure?

-- There's always a solution --

qwerty

  • EA Guru
  • *****
  • Posts: 12828
  • Karma: +366/-295
  • I'm no guru at all
    • View Profile
Re: Preserve manual code on codegen
« Reply #1 on: July 26, 2013, 02:04:14 am »
AFAIK the method body is stored in Behavior/Initial Code of methods.

q.

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: Preserve manual code on codegen
« Reply #2 on: July 26, 2013, 02:34:35 am »
OK, I'll try using that.

Thx.

[edit]Yes, works fine.[/edit]
« Last Edit: July 26, 2013, 04:12:08 am by Rolf_Lampa »
-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7732
  • Karma: +103/-18
    • View Profile
Re: Preserve manual code on codegen
« Reply #3 on: July 26, 2013, 09:04:18 am »
Quote
I made my own code gen templates (= has no reverse enginering of code)

Unless you're really keen. (http://www.sparxsystems.com/enterprise_architect_user_guide/10/extending_uml_models/grammar_editor_for_imported_co.html)
Eve

support@sparxsystems.com

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: Preserve manual code on codegen
« Reply #4 on: July 26, 2013, 02:48:25 pm »
Quote
Quote
I made my own code gen templates (= has no reverse enginering of code)
Unless you're really keen. (http://www.sparxsystems.com/enterprise_architect_user_guide/10/extending_uml_models/grammar_editor_for_imported_co.html)
Thank you very much for this hint!
I managed to parse most of the file level structures for Go, but code body seems to be a little trickier. However, I noticed something that looks like a function call to retrieve a list of keywords in the SSL.nbnf:
Quote
// Lexer rules
<TOKENS>    ::= <WHITESPACE> |
                          <COMMENT> |
                          token(<NUMBER>) |
                          token( keywords() ) |
                          ...
Q1: Where can I define such a list of keywords?  Or, perhaps I have missed a basic point sand should instead just go on extending the above list with keywords?

Q2: Is there any .nbnf file for the existing languages available? The language I'm most familiar with is Delphi, so a delphi.nbnf file would quickly get me going with this.
« Last Edit: July 26, 2013, 02:51:40 pm by Rolf_Lampa »
-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7732
  • Karma: +103/-18
    • View Profile
Re: Preserve manual code on codegen
« Reply #5 on: July 29, 2013, 09:14:56 am »
1. The list of keywords is automatically generated based on the string literals in your grammar.
2. No, but there is a sample grammar at EA\Code Samples\Grammar_Samples\SSL.nbnf with a sample file to be parsed by that grammar.

Also, the easiest way to deal with the code body would be using a skip rule.

Code: [Select]
<functionBody> ::= "{" [attribute("CODE", skipBalanced("{", "}", <codeEscape>))] "}";
<codeEscape> ::= <COMMENT> |
                                <stringLiteral> |
                                <characterLiteral>;
Eve

support@sparxsystems.com

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: Preserve manual code on codegen
« Reply #6 on: July 30, 2013, 06:54:56 am »
Quote
...
Also, the easiest way to deal with the code body would be using a skip rule.[/code]
Yes, thank you for that hint, it will become very useful.

// Rolf Lampa
-- There's always a solution --

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: Preserve manual code on codegen
« Reply #7 on: August 23, 2013, 05:36:48 am »
I'm improving. My nBNF/AST parses entire Go packages with all occuring "main" syntax (although skipping the details of function body content as suggested).  I achieve more and more details out of the sources as I learn how to define terms and rules.  But, how do I know...

Q1: ... which exact node/attribute names to give the terms as to enable EA to pick them up?

On the following page(s) on AST nodes I get the following hints about recognizable terms. Does that mean that these names are the exact names by which CodeGen templates uses later when it reads info from the model?

http://www.sparxsystems.com/enterprise_architect_user_guide/10/extending_uml_models/context_labels.html (example node names below)

Q2: If these identifiers are not the exact ones used by EA internally, is there any mapping table resolving the names used in CodeGen templates or via script access?

Q3: In conclusion: Can I access these AST nodes - by these exact names - by codegen or scripts once they are picked up by EA import?

// Rolf


This perhaps should be obvious, but...
(Q4: Does "CLASS/INTERFACE" below mean "in CLASS and/or INTERFACE" or is "CLASS/INTERFACE" an identifier in its own right?)

Code: [Select]
"Class BODY" Node
Contained in Nodes:     CLASS/INTERFACE
------------------------------------
METHOD
ATTRIBUTE
FIELD
CLASS
SCOPE
PROPERTY
TAG
PARENT
OPEN_POSITION
INSERT_POSITION
« Last Edit: August 23, 2013, 06:24:28 am by Rolf_Lampa »
-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7732
  • Karma: +103/-18
    • View Profile
Re: Preserve manual code on codegen
« Reply #8 on: August 26, 2013, 09:35:19 am »
1. That's the complete list of names EA is looking for when parsing using your grammar. The code templates don't really use them, the code template are generating from your model, not the AST. The AST is only used during generation to synchronize. (eg. Generate new members into a class etc.)
2. In most circumstances it should be self-explanatory what each item on that page corresponds to in the model. If it's not then I'd have deal with those individually.
3. As I said for 1. No, these are used for import into the model. Codegen and scripts will then work on the normal model elements.
4. This allows for nested classes/interfaces.
« Last Edit: August 26, 2013, 09:35:48 am by simonm »
Eve

support@sparxsystems.com

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: Preserve manual code on codegen
« Reply #9 on: August 28, 2013, 01:44:58 am »
Ok, clear enough.

Q: Is it possible to somehow print out the resulting AST for a sourcefile?

[highlight][edit]: Ah, saw that you had answered "no" on this last followup question in the other thread.[/highlight]
« Last Edit: August 28, 2013, 02:13:38 am by Rolf_Lampa »
-- There's always a solution --