Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: RIL on August 23, 2013, 08:07:10 am

Title: AST - Tokens can't start nodes?
Post by: RIL on August 23, 2013, 08:07:10 am
I'm trying to pick up COMMENT as a node in the AST tree, but it seems like it doesn't even try as long as <COMMENT> is defined as a token (in the beginning of the nBNF file).

I noticed that the Simple Example started with the following declaration for tokens, and, it seems to me, thus suppressing node generation from any of those tokens:

Code: [Select]
<TOKENS>      ::=      <WHITESPACE> |
                  <COMMENT> |            <--- Huh?
                  token(<NUMBER>) |
                  token(<QUOTE>) token(<STRING_BODY>) token(<QUOTE>) |
                  token( keywords() ) |
                  token(<IDENTIFIER>);

What I'm at is that since EA recognizes the term COMMENT as a distinct model element, then why is a comment considered being only a "token" (and thus can't be picked up and stored in the model)?

I might be entirely off track here though. Am I missing the meaning of token vsv terms/named nodes? Something else? Or all of it? :)

I couldn't find a clear description in the help about how EA parser treats tokens compared to named nodes.

// Rolf
Title: Re: AST - Tokens can't start nodes?
Post by: Eve on August 26, 2013, 08:44:18 am
So make it a token?

Code: [Select]
<TOKENS>      ::=      <WHITESPACE> |
                  token(<COMMENT>) |
                  token(<NUMBER>) |
                  token(<QUOTE>) token(<STRING_BODY>) token(<QUOTE>) |
                  token( keywords() ) |
                  token(<IDENTIFIER>);

In your parse statement you then specify that as a language escape.

Code: [Select]
parse(<translationUnit>, <languageEscape>);

<languageEscape> ::= attribute("COMMENT", <COMMENT>);
Title: Re: AST - Tokens can't start nodes?
Post by: RIL on August 28, 2013, 02:17:06 am
Ok, thank you Simon, this really clears up my fog.

I was entirely off track, simply had a "missing link" leading me astray, but now things are getting interesting. :)

// Rolf