|
Boost Users : |
From: Joel de Guzman (joel_at_[hidden])
Date: 2004-06-25 21:07:43
Mark Storer wrote:
>>No chance of switching to 7.1? :-)
>
>
> Things are looking up. We just did a project-wide upgrade
to... VC7.1. Problem solved. I'm now merrily writing rules for
my JavaScript parser. It doesn't have to support the whole
language (not for a while, maybe never), I just need to be able
to parse out the names and locations of all the functions in a
file. It's for a JavaScript editor built into one of our
products, and later we'll be adding auto-completion. That'll
require a more thorough parser, but for now, I'm just after
funciton locations.
Great! Nice to hear.
> So far so good... though I'll undoubtedly be quite familiar
with the BOOST_SPIRIT_DEBUG* macros before I'm done.
>
> I've got another Spirit question: I've been adding "*comment"
throughout the rules and it's getting tiresome:
>
> rule<phrase_scanner_t> blockComment = comment_p( "/*", "*/" );
> rule<phrase_scanner_t> lineComment = comment_p( "//" );
> rule<phrase_scanner_t> comment = blockComment | lineComment;
>
> Spraying the "comment" rule liberally through my rules is an
option...
>
> rule<phrase_scanner_t> codeBlock = ch_p('{') >>
*(comment | codeBlock | ~ch_p('}')) >> ch_p('}');
>
> ... but not an appealing one. This becomes particularly true
once I start working on the auto- completion parser.
Certainly not appealing.
> It just occured to me that if the skip parser ate comments
for me, it would greatly simplify my rules. I'd like to tweak the
skip parser so it skips over my "comment" rule as well as white
space.
That's the way to go. See the C-parser, for example:
http://tinyurl.com/29mcn
I just took a stab at this, but didn't get very far. I
tried:
>
> parse(str, rules, space_p | comment)
>
> but that resulted in a compiler error. 7.1's errors are MUCH
easier to read that 6's. I'm going to like this new compiler. >
[...]
>
> Pointing me to the relevant section of the docs is an
acceptable answer, though I wouldn't mind a little more info than
that. ;)
It's the no. 1 FAQ. See the Scanner Business:
http://tinyurl.com/3abgf
In general, put your "rules" in a grammar.
> I'll keep plugging away. If I come up with an answer, I'll
post it to the list. I'd expect this to be useful to other
beginners at the very least.
Well, HTH... If you have further questions, please post them to
Spirit's mailing list where other Spirit folks can help:
Spirit-general mailing list
Spirit-general_at_[hidden]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Cheers,
-- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net