Comments (8)
apparently part of the input I gave had some special meaning to github, syntax-wise. Please just look at the source.
from pegged.
The problem is here:
Statement <- ( AutoStatement / HotplugStatement / EmptyLine / Comment )
EmptyLine
is tested before Comment
and will always check. So
Statement
on a #...
line will be parsed as an EmptyLine
and
then, as there is no EOL
, Grammar
switch to parsing EOI
.
Use this:
Statement <- AutoStatement / HotplugStatement / Comment / EmptyLine
It works for me.
Tell me if you need help in defining comments and such in your grammar.
from pegged.
Yes, I eventually found that myself, through heavy debugging of the generated code, and now have a working parser for what I need.
This was made much easier after I changed the code (with a Q&D perl script) so it would write a "matched foo" or "failed to match foo", followed by the complete parse tree, to stdout every time a match or fail would occur. This generates a huge amount of data, but allows you to trace the parser as it's running.
Perhaps this might be an interesting feature to have in Pegged itself?
from pegged.
Thought it might make sense to add a pointer to that Q&D perl script:
https://github.com/yoe/ipcfg/blob/06/src/adddebug.pl
This would probably be better implemented in pegged/development/grammarfunctions.d, but I couldn't immediately figure out why it didn't work for me, and the perl script worked...
from pegged.
I'm not that well-versed in Perl. It scans the module itself, looking
for some patterns?
from pegged.
Basically, the script reads the output of the asModule() function one line at a time. When the regex /Output parse/ matches the input line, the variable "$last" is set to "parse", and the variable "counter" is set to 0. When the variable "counter" reaches 2, we output "writeln("attempting " ~ ruleName);\n".
Example class after it ran through this perl script would look like this:
class S : Drop!(Or!(Lit!("\t"),Lit!(" ")))
{
enum grammarName = RULES
;
enum ruleName = S
;
static Output parse(ParseLevel pl = ParseLevel.parsing)(Input input)
{
writeln("attempting " ~ ruleName);
mixin(okfailMixin());
auto p = typeof(super).parse!(pl)(input);
static if (pl == ParseLevel.validating)
p.capture = null;
static if (pl <= ParseLevel.matching)
p.children = null;
static if (pl >= ParseLevel.parsing)
{
if (p.success)
{
writeln(" MATCHED " ~ ruleName ~ "
", p);
static if (pl == ParseLevel.parsing)
p.parseTree = decimateTree(p.parseTree);
if (p.grammarName == grammarName || pl >= ParseLevel.noDecimation)
{
p.children = [p];
}
p.grammarName = grammarName;
p.ruleName = ruleName;
}
else
{
writeln("failed " ~ ruleName ~ "
", p);
return fail(p.parseTree.end,
(grammarName~.
~ruleName ~ failure at pos
d ~ to!dstring(p.parseTree.end) ~ (p.capture.length > 0 ? p.capture[1..$] : p.capture)));
}
}
return p;
}
mixin(stringToInputMixin());
}
like I said, it's quick and dirty :-)
from pegged.
Ah OK, I didn't understand it modified the file itself (as I said, my
Perl knowledge is quite limited).
Why don't you modify one of the wiki pages to link to your script and
explain what it does? Aren't they access-free?
from pegged.
This was made much easier after I changed the code (with a Q&D perl script) so it would write a "matched foo" or "failed to match foo", followed by the complete parse tree, to stdout every time a match or fail would occur. This generates a huge amount of data, but allows you to trace the parser as it's running.
Perhaps this might be an interesting feature to have in Pegged itself?
This is now implemented, see https://github.com/PhilippeSigaud/Pegged/wiki/Grammar-Debugging.
from pegged.
Related Issues (20)
- is it okay for the D grammar to compile in 10 minutes and use 45 gigs of ram? HOT 14
- Run-time parsing of Peg grammars HOT 1
- qualifiedIdentifier in dgrammar.d is not defined HOT 2
- Add equivalent of “important” blocks? HOT 3
- Release 0.4.5 HOT 2
- `pure` and `@safe` grammars/rules? HOT 3
- Can't fix this failure. HOT 2
- Grammar won't parse whole text, it stops short a few lines... HOT 1
- Comment syntax HOT 7
- Unwanted space consumption in rule parameter
- Syntax wrappers HOT 1
- How does one do Intellisense using a Pegged grammar? HOT 3
- Is there a way to break up a grammar into D classes, each with their own data to parse into & thus subgrammar? HOT 2
- I can't find the Wikipedia ParseTree handling code in the Pegged wiki any more... HOT 1
- Will there be a speed-up when using a Dlang switch-case and shorter pegged variable names? HOT 2
- Can we create a grammar induction algorithm based upon expected Pegged parsing failures? HOT 2
- How do you use dub + pegged + asModule? HOT 1
- Bump new version HOT 7
- Remove obsolete CI.
- How do you branch on complex names such as caseSensitiveLiteral!("let") (they get much more complicated) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pegged.