Tweaking the Skip Parser, was RE: [Boost-users] Spirit 1.6 with VC6
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.
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
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
Take a look at:
http://www.boost.org/libs/spirit/doc/faq.html#scanner_business
You don't want the skip parser to be a phrase level scanner.
parse(str, rules, space_p | comment_p( "/*", "*/" ) | comment_p( "//" ) )
may work for you?
Jeff F
"Mark Storer"
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
blockComment = comment_p( "/*", "*/" ); rule lineComment = comment_p( "//" ); rule comment = blockComment | lineComment; Spraying the "comment" rule liberally through my rules is an option...
rule
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.
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. 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.
C:\SDKs\boost_1_31_0\boost\spirit\core\non_terminal\impl\rule.ipp(190):
error C2664:
'boost::spirit::impl::abstract_parser
with [
ScannerT=boost::spirit::ruleboost::spirit::phrase_scanner_t::scanner_t,
AttrT=boost::spirit::ruleboost::spirit::phrase_scanner_t::attr_t
] and [ T0=boost::spirit::phrase_scanner_t ]
Pointing me to the relevant section of the docs is an acceptable answer,
though I wouldn't mind a little more info than that. ;)
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.
--Mark Storer Senior Software Engineer Verity, Inc.
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
Mark,
I didn't mean to imply this was the only way to accomplish what you want to
do. You can create a full fledged grammar and use it as your skip parser.
Or, create a functor_parser, which works for me.
struct SkipperDct
{
typedef int result_t;
template< typename ScannerT >
int operator()( ScannerT const& scan, result_t& )const
{
match<> m = ( +space_p
| lexeme_d[ comment_p("//")
| comment_nest_p("/*","*/")
]
).parse( scan );
return m? m.length() : -1;
}
};
functor_parser<SkipperDct> SkipperDct_p;
};
Also note the use of 'comment_nest_p'.
Jeff F
"Mark Storer"
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
blockComment = comment_p( "/*", "*/" ); rule lineComment = comment_p( "//" ); rule comment = blockComment | lineComment; Spraying the "comment" rule liberally through my rules is an option...
rule
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.
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. 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.
C:\SDKs\boost_1_31_0\boost\spirit\core\non_terminal\impl\rule.ipp(190):
error C2664:
'boost::spirit::impl::abstract_parser
with [
ScannerT=boost::spirit::ruleboost::spirit::phrase_scanner_t::scanner_t,
AttrT=boost::spirit::ruleboost::spirit::phrase_scanner_t::attr_t
] and [ T0=boost::spirit::phrase_scanner_t ]
Pointing me to the relevant section of the docs is an acceptable answer,
though I wouldn't mind a little more info than that. ;)
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.
--Mark Storer Senior Software Engineer Verity, Inc.
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
participants (3)
-
Jeff Flinn
-
Joel de Guzman
-
Mark Storer