I’m trying to make a textx grammar that will include a the ability to have single line comments like a c/c++ source file. e.g.
//this is a comment
This is the grammar I have developed to test this. Eventually ‘Entry’ will contain more than just comment.
Ledger:entries+=Entry;
Entry: Comment;
Comment:///.*$/;
However when I try to parse the following file
//comment 1
//comment 2
I get this error
textx.exceptions.TextXSyntaxError: file.txt:3:1: Expected Comment => 'omment 2 *'
This is the debug output of the parser
*** PARSING MODEL ***
>> Matching rule Model=Sequence at position 0 => *//comment
>> Matching rule Ledger=Sequence in Model at position 0 => *//comment
>> Matching rule __asgn_oneormore=OneOrMore[entries] in Ledger at position 0 => *//comment
?? Try match rule Comment=RegExMatch(//.*$) in __asgn_oneormore at position 0 => *//comment
?? Try match rule Comment=RegExMatch(//.*$) in __asgn_oneormore at position 0 => *//comment
' at 0 => '*//comment 1*'ent 1
?? Try match rule Comment=RegExMatch(//.*$) in __asgn_oneormore at position 13 => omment 1 *//comment
' at 13 => 'omment 1 *//comment 2*'
?? Try match rule Comment=RegExMatch(//.*$) in __asgn_oneormore at position 26 => omment 2 *
-- NoMatch at 26
-- NoMatch at 26
<<- Not matched rule __asgn_oneormore=OneOrMore[entries] in __asgn_oneormore at position 0 => *//comment
<<- Not matched rule Ledger=Sequence in Ledger at position 0 => *//comment
<<- Not matched rule Model=Sequence in Model at position 0 => *//comment
If I add another option to the Entry rule e.g.
Ledger:entries+=Entry;
Entry: Comment | FLOAT;
Comment:///.*$/;
and add that entry to the file e.g.
//comment 1
//comment 2
7
Then I don’t get an exception thrown but comments aren’t parsed ( they don’t show up in my model). Parser debug output is as follows.
>> Matching rule Model=Sequence at position 0 => *//comment
>> Matching rule Ledger=Sequence in Model at position 0 => *//comment
>> Matching rule __asgn_oneormore=OneOrMore[entries] in Ledger at position 0 => *//comment
>> Matching rule Entry=OrderedChoice in __asgn_oneormore at position 0 => *//comment
?? Try match rule Comment=RegExMatch(//.*$) in Entry at position 0 => *//comment
?? Try match rule Comment=RegExMatch(//.*$) in Entry at position 0 => *//comment
' at 0 => '*//comment 1*'omment 1
?? Try match rule Comment=RegExMatch(//.*$) in Entry at position 13 => omment 1 *//comment
' at 13 => 'omment 1 *//comment 2*'
?? Try match rule Comment=RegExMatch(//.*$) in Entry at position 26 => omment 2 *7
-- NoMatch at 26
-- NoMatch at 26
?? Try match rule FLOAT=RegExMatch([+-]?(d+(.d*)?|.d+)([eE][+-]?d+)?(?<=[w.])(?![w.])) in Entry at position 0 => *//comment
++ Match '7' at 26 => 'omment 2 *7*'
<<+ Matched rule Entry=OrderedChoice in Entry at position 27 => mment 2 7*
>> Matching rule Entry=OrderedChoice in __asgn_oneormore at position 27 => mment 2 7*
?? Try match rule Comment=RegExMatch(//.*$) in Entry at position 27 => mment 2 7*
?? Try match rule Comment=RegExMatch(//.*$) in Entry at position 27 => mment 2 7*
-- NoMatch at 27
-- NoMatch at 27
?? Try match rule FLOAT=RegExMatch([+-]?(d+(.d*)?|.d+)([eE][+-]?d+)?(?<=[w.])(?![w.])) in Entry at position 27 => mment 2 7*
-- NoMatch at 27
<<- Not matched rule Entry=OrderedChoice in Entry at position 27 => mment 2 7*
<<+ Matched rule __asgn_oneormore=OneOrMore[entries] in __asgn_oneormore at position 27 => mment 2 7*
<<+ Matched rule Ledger=Sequence in Ledger at position 27 => mment 2 7*
?? Try match rule EOF in Model at position 27 => mment 2 7*
<<+ Matched rule Model=Sequence in Model at position 27 => mment 2 7*
Can anyone help me add c style comments to my grammar that end up in the model?
Thanks!
TextX Grammer Rule for CStyle Comments
I’m trying to make a textx grammar that will include a the ability to have single line comments like a c/c++ source file. e.g.
//this is a comment
This is the grammar I have developed to test this. Eventually ‘Entry’ will contain more than just comment.
However when I try to parse the following file
I get this error
This is the debug output of the parser
If I add another option to the Entry rule e.g.
and add that entry to the file e.g.
Then I don’t get an exception thrown but comments aren’t parsed ( they don’t show up in my model). Parser debug output is as follows.
Can anyone help me add c style comments to my grammar that end up in the model?
Thanks!
Filed under: Kiến thức lập trình - @ 02:53
Thẻ: commentsdsltextx
« Encountered this error message when trying to open index file ⇐ More Pages ⇒ Code to do webcam capturing using the windows native API in Python’s ctypes library not working as intended »