Giter Site home page Giter Site logo

Infinite loop. about pegged HOT 4 CLOSED

philippesigaud avatar philippesigaud commented on July 18, 2024
Infinite loop.

from pegged.

Comments (4)

PhilippeSigaud avatar PhilippeSigaud commented on July 18, 2024

On Wed, May 30, 2012 at 3:43 AM, meh.
[email protected]
wrote:

import std.stdio : writeln;
import pegged.grammar;

mixin(grammar(`
Test:
       A <- B*
       B <- .*
`));

void main () {
       writeln(Test.A.parse("lol"));
}

This is the reduced testcase for the culprit in my grammar.

The first invocation of B consumes lol and then stops.
The second invocation of B consumes nothing (nothing left), succeeds,
and the stops.
The third, ...

That's because .* can succeed while consuming nothing and you put it
into repetition.

I recently added checkGrammar just for that. Try:

void main () {
writeln(checkGrammar(Test:        A <- B*        B <- .*);
}

It should print a diagnostic saying B might consume nothing and A can
be an infinite loop.

test

Arg, it fails. Damn, it worked quite well last week, I tested it with
all kind of grammars, from JSON to C to D.

from pegged.

meh avatar meh commented on July 18, 2024

But shouldn't it stop when there's nothing left to consume?

I'm adding the checkGrammar thing to peggeden, how should I pretty print the Diagnostic object?

from pegged.

PhilippeSigaud avatar PhilippeSigaud commented on July 18, 2024

On Wed, May 30, 2012 at 6:49 AM, meh.
[email protected]
wrote:

But shouldn't it stop when there's nothing left to consume?

By definition, .* can succeed on an empty string. Use .+ if you
want it to fail at the end.
Or:

EOI / .*

from pegged.

PhilippeSigaud avatar PhilippeSigaud commented on July 18, 2024

I added an introspection module. I'll add diagnoctics while generating the grammar.

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.