Hi! I just hit this again for a project I'm working on, too. A chore.
On Feb 2, 2010, at 4:31 AM, Gerald Rosenberg wrote:
On 2/1/2010 6:52 PM, Terence Parr wrote:Should I think about a (...)^[1] construct or something for v4?Yes, just please don't further overload the caret and brackets with completely different contextually dependent meaning! Also, its ambiguous without the parens and if a space is put between the ")" and "^" it might form a completely different valid construct.
+1
Perl-like would be (...){n,m} -- if n and optional m must be ints, then it is space tolerant and cannot be confused with an action (actually use of the parens is conceptually consistent with use of parens for actions- here defining a function applicable to the preceding element).
I somewhat agree, but would also hate to overload the action meaning of '{…}'. Even though 'n,m' would be integers, what tells you that it is not a valid statement in the target language? I think it would be tricky to get right and could potentially be confusing.
Since you are making a clean break from everything v2, maybe (...)#1 --makes the construct read very literally.
What are the semantics of the # operator? Allow each alternative exactly once? Allow each alternative zero or one time?How about making this thing an option, like greedy? For one thing, this use case isn't all that common and usually constrained to one or just a few rules, like type modifiers or optional blocks like in ANTLR.
Example:
prequelConstructs
options { altsMaxOnce = true; }
: ( ^(o+=OPTIONS .*)
| ^(i+=IMPORT .*)
| ^(t+=TOKENS .*)
)*
/* wouldn't actually be necessary:
{BasicSemanticChecks.checkNumPrequels(gtype, $o, $i, $t);} */
;
or even better:
prequelConstructs
: (options { altsCardinality = 1; } : /* could also be > 1, = 0 would
be an error as it couldn't match anything. */
^(o+=OPTIONS .*)
| ^(i+=IMPORT .*)
| ^(t+=TOKENS .*)
)*
/* wouldn't actually be necessary:
{BasicSemanticChecks.checkNumPrequels(gtype, $o, $i, $t);} */
;
This way the meaning is spelled out, no extra syntax needs to be
introduced, and you can see it clearly _before_ reading a block ('you'
as in grammar authoring/reading human).
cheers, -k -- Kay Röpke
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ antlr-dev mailing list [email protected] http://www.antlr.org/mailman/listinfo/antlr-dev
