[phc-general] I am getting keywords confused with identifiers
Satyam
Satyam at satyam.com.ar
Wed Aug 30 22:03:17 CEST 2006
One of the statements in my extensions is the TAG statement that produces an
XML tag:
<something;
will produce:
echo "<something />";
On purpose I made the tag name an unquoted string, if for nothing else, to
type a little less. The problem is that:
<if;
produces and error´, the parser expects an XML_IDENT (which is a IDENT plus
some extra characters) and it gets a K_IF instead.
So, I can do (and actually tried) some of the following:
a) Use a function similar to PHP_lexer::return_to_complex_syntax() to change
the state of the lexer.
b) add a flag to the lexer so that in the action for the rule <PHP>{IDENT} I
don't go looking for keywords, just return the IDENT found as such.
These two didn't work, actually a) crashed the flex code while b) always got
a step behind (the flag got set after the token had already been read)
c) make the tag a plain string:
< "something";
I don't like this because that wasn't mean to be the way
d) make the quoting optional, mandatory for keywords
somewhat better but I am still leaving the door open to any sort of string,
meaning that I would have variable expansion within quotes and I would be
accepting all sorts of characters which would have to be (as much as
possible) checked out in the parser.
e) add all the keywords to the syntax for an xml_tag_name so that I would
accept an IDENT, an XML_IDENT, a K_IF, a K_WHILE and so on and so forth.
The parser source would look a little long, but this would work and, after
all, I can pick the list of keywords from php.gperf without much trouble.
Nevertheless, I would still like solutions a) or b), the last one better, I
think, but some printf()s that I have placed here and there consistently
shows me that the flag to ignore keywords gets set after I already processed
the next token as a keyword and can't change the meaning back to a IDENT.
Any hint on how I could do this? Otherwise, it will have to be e), which is
not elegant, but should work fine.
Thanks
Satyam
More information about the phc-general
mailing list