views:

16

answers:

0

Although this question is about JFlex, it probably applies to other scanner generators such as lex, gnu-flex as well.

If I have some rule, how can I create a capturing group in part of that rule and use the result of that captured group as an argument to the code that gets called upon the rule matching?

For example, let's say I had a simple rule to match an SGML tag:

"<"[a-zA-Z]+">"    {return new Token(Type.OPEN_TAG);}

How could I capture the inner character part([a-zA-Z]+) and use it as an argument in my Token constructor?

Edit: I'm aware I could simply use yytext() to get the whole matched value and then separate the parts elsewhere in code, but that seems like it would be making things more complicated than they need to be.