Giter Site home page Giter Site logo

Comments (8)

yoe avatar yoe commented on August 17, 2024

apparently part of the input I gave had some special meaning to github, syntax-wise. Please just look at the source.

from pegged.

PhilippeSigaud avatar PhilippeSigaud commented on August 17, 2024

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.

yoe avatar yoe commented on August 17, 2024

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.

yoe avatar yoe commented on August 17, 2024

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.

PhilippeSigaud avatar PhilippeSigaud commented on August 17, 2024

I'm not that well-versed in Perl. It scans the module itself, looking
for some patterns?

from pegged.

yoe avatar yoe commented on August 17, 2024

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 posd ~ 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.

PhilippeSigaud avatar PhilippeSigaud commented on August 17, 2024

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.

veelo avatar veelo commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.