EBNF grammar not recognizing end of file correctly

41 views
Skip to first unread message

Matej Zabsky

unread,
Oct 28, 2016, 6:01:22 AM10/28/16
to Eto.Parse
Hello,
I'm trying to make a CSS parser using ETO Parse. So far I have mostly just translated parts of the official CSS grammar to the W3C EBNF notation supported by Eto - you can see the grammar on GitHub (also the invocation of Eto.Parse and a test case that can run the whole thing). It is nowhere near finished, but it should be able to parse a simple CSS file.

However when I run the test case on a simple string: "div#hash{background:red;}     #someid{padding:1px 1px;}", it returns a GrammarMatch with this ErrorMessage:

Index=57, Context="px 1px;}>>>"
Expected:
S
: Repeat: Unary: Alternative
ident
: Sequence
element_name
: Alternative
hash
: Sequence
class: Sequence
attrib
: Sequence
pseudo
: Sequence
ruleset
: Sequence

Suprisingly, Match.Success is true, but I don't believe I should ignore the message. When I print the syntax tree as contained in the match, I get a tree which seems to be correct:

stylesheet - div#hash{background:red;}     #someid{padding:1px 1px;}
ruleset - div#hash{background:red;}     
selectors - div#hash
selector - div#hash
element_name - div
ident - div
hash - #hash
ident - hash
declarations - background:red;
declaration - background:red
ident - background
expression - red
term - red
ident - red
S -      
ruleset - #someid{padding:1px 1px;}
selectors - #someid
selector - #someid
hash - #someid
ident - someid
declarations - padding:1px 1px;
declaration - padding:1px 1px
ident - padding
expression - 1px 1px
term - 1px
number - 1px
operator -  
S -  
term - 1px
number - 1px

As far as I can tell, the grammar should terminate the match correctly - the top level "stylesheet ::= (ruleset)*" is as simple as it gets and from the error message provided by Eto, it look like it expects another ruleset. I tried adding a newline to the end of the input string, but it didn't help.

Thanks for any assistance
Reply all
Reply to author
Forward
0 new messages