Permalink
Browse files

Update to new boost for bugfix, minor parser fixes.

  • Loading branch information...
1 parent 26abb67 commit 5e6deb25912fa04bfcb18a1330417fa960433450 Matt Hellige committed May 18, 2012
Showing with 20 additions and 11 deletions.
  1. +1 −0 Makefile
  2. +1 −1 package.fig
  3. +10 −7 src/parser/parser.cpp
  4. +8 −3 test/parser/parser_test.cpp
View
@@ -138,6 +138,7 @@ spotless: clean
-$(RM) $(FIG_MAIN)
-$(RM) $(FIG_TEST)
-$(RM) -r dist out lib include
+ -$(RM) -r .fig
echo:
@echo "******************************************"
View
@@ -10,7 +10,7 @@ config default
end
config build
- include boost/1.47.0.ubuntu
+ include boost/1.49.0.redhat5
end
config test
View
@@ -33,6 +33,9 @@ namespace ccs {
namespace {
+// MMH it really might be better at this point to ditch spirit's 'skipper'
+// stuff entirely and go with explicit optional/required whitespace, as in
+// the java version.
template <typename Iterator>
struct ccs_grammar : qi::grammar<Iterator, ast::Nested(), qi::rule<Iterator>> {
typedef Iterator I;
@@ -84,7 +87,7 @@ struct ccs_grammar : qi::grammar<Iterator, ast::Nested(), qi::rule<Iterator>> {
strng = qi::lexeme['\'' >> *(char_ - ('\'' | eol)) >> '\'']
| qi::lexeme['"' >> *(char_ - ('"' | eol)) >> '"'];
- val %= lit("0x") >> qi::hex [bind(&Value::setInt, _val, _1)]
+ val = lit("0x") >> qi::hex [bind(&Value::setInt, _val, _1)]
| qi::long_long [bind(&Value::setInt, _val, _1)] >> !lit('.')
| qi::double_ [bind(&Value::setDouble, _val, _1)]
| qi::bool_ [bind(&Value::setBool, _val, _1)]
@@ -94,9 +97,9 @@ struct ccs_grammar : qi::grammar<Iterator, ast::Nested(), qi::rule<Iterator>> {
// properties...
modifiers =
-((lit("@override")
- [bind(&ast::PropDef::override_, _r1) = true] >> skipper) ^
+ [bind(&ast::PropDef::override_, _r1) = true] >> +skipper) ^
(lit("@local")
- [bind(&ast::PropDef::local_, _r1) = true ] >> skipper));
+ [bind(&ast::PropDef::local_, _r1) = true ] >> +skipper));
property = modifiers(_val)
>> ident [bind(&ast::PropDef::name_, _val) = _1]
>> '=' > val [bind(&ast::PropDef::value_, _val) = _1];
@@ -120,17 +123,17 @@ struct ccs_grammar : qi::grammar<Iterator, ast::Nested(), qi::rule<Iterator>> {
selector = (sum >> -qi::string(">")) [_val = bind(branch, _1, _2)];
// rules, rulesets...
- import %= lit("@import") > strng;
- constraint %= lit("@constrain")
- > singlestep(bind(&ast::Constraint::key_, _val));
+ import %= qi::lexeme[lit("@import") > +skipper > strng];
+ constraint %= qi::lexeme[lit("@constrain") > +skipper
+ > singlestep(bind(&ast::Constraint::key_, _val))];
nested = selector [bind(&ast::Nested::selector_, _val) = _1] >>
((':' > (import | constraint | property)
[bind(&ast::Nested::addRule, _val, _1)])
| ('{' > *rule > '}')
[bind(&ast::Nested::rules_, _val) = _1]);
rulebody = import | constraint | property | nested;
rule = qi::skip(skipper.alias())[rulebody] >>
- (lit(';') | skipper | &lit('}') | eoi);
+ ((+skipper || lit(';')) | &lit('}') | eoi);
auto context = lit("@context") > '(' > selector > ')' > -lit(';');
ruleset %= -context > *rule > eoi;
}
@@ -19,7 +19,7 @@ struct P {
TEST(ParserTest, BasicPhrases) {
P parser;
- EXPECT_FALSE(parser.parse("")); // TODO why?
+ EXPECT_TRUE(parser.parse(""));
EXPECT_TRUE(parser.parse("\n"));
EXPECT_TRUE(parser.parse("@import 'file'"));
EXPECT_TRUE(parser.parse("@context (foo.bar > baz)"));
@@ -35,6 +35,7 @@ TEST(ParserTest, BasicPhrases) {
EXPECT_FALSE(parser.parse("a.class. class > elem.id {prop=\"val\"}"));
EXPECT_FALSE(parser.parse("blah"));
EXPECT_FALSE(parser.parse("@import 'file'; @context (foo)"));
+ EXPECT_TRUE(parser.parse("@import 'file' ; @constrain foo"));
EXPECT_TRUE(parser.parse("a.class { @import 'file' }"));
EXPECT_FALSE(parser.parse("a.class { @context (foo) }"));
EXPECT_TRUE(parser.parse("elem.id { prop = 'val'; prop2 = 31337 }"));
@@ -67,8 +68,12 @@ TEST(ParserTest, UglyAbutments) {
EXPECT_FALSE(parser.parse("foo{@overridep=1}"));
EXPECT_FALSE(parser.parse("foo{@override@localp=1}"));
EXPECT_TRUE(parser.parse("foo{@override @local p=1}"));
- EXPECT_TRUE(parser.parse("@import'asdf'")); // TODO
- EXPECT_TRUE(parser.parse("@constrainasdf")); // TODO
+ EXPECT_TRUE(parser.parse("foo{@override /*hi*/ @local /*there*/ p=1}"));
+ EXPECT_FALSE(parser.parse("@import'asdf'"));
+ EXPECT_FALSE(parser.parse("@constrainasdf"));
+ EXPECT_TRUE(parser.parse(
+ "@import 'asdf' \n ; \n @constrain asdf \n ; @import 'foo' "));
+ EXPECT_TRUE(parser.parse("@import /*hi*/ 'asdf'"));
}
TEST(ParserTest, SelectorSections) {

0 comments on commit 5e6deb2

Please sign in to comment.