This project has moved and is read-only. For the latest updates, please go here.

Need advice on how to handle a special situation

Jan 31, 2008 at 8:24 PM
I have 2 special situations that I am not sure how to handle in my grammer.

1. My grammer allows for quotes to be a part of identifiers. Which Irony does fine with using:

Terminal variableName = new IdentifierTerminal("name", "'", "");

The problem is if I have a quoted identifier ('Test'), it seems to be treating the last quote as part of the identifier and not the closing quote. Any ideas on what I might be doing wrong?

2. In my grammer comments are inclosed in double quotes(e.g. "This is a comment"). The problem with this is strings also are in double quotes. To determine if it is a string or comment you need to look at what is preceding it. I am not sure how to handle this with Irony.

Here is an example, the first quoted segment is a string and the second is a comment.

DEFINE U'STATUS(X) "(*U BITSINWORD*)(REP(!X))"; "status to unsigned"

Feb 7, 2008 at 6:10 PM
For #1 I would suggest defining two identifier terminals: normal (IdentifierTerminal) and quoted (based on StringLiteral terminal, with quote as start/end symbols). Then define nonterminal Identifier:
Identifier.Rule = NormalIdentifier | QuotedIdentifier;

#2: not clear what is the criteria to recognize the second string in your example as comment. Whatever it is, based on my quess, you could recognize all quoted strings as StringLiteral, and then in token filter recognize which are comments and filter them out (or change to comment tokens)