Git Product home page Git Product logo

pry-parser's Introduction

Pry

On the surface Pry is a PEG-inspired parser combinator library. The focus of development is pragmatic qualities such as achieving performance on par with handwritten parsers, at the expense of idealistic goals to e.g. support the most features of the PEG grammars.

Special bits are:

  • completely generic input via "Stream", a thin wrapper on top of D ranges
  • compile-time optimized building blocks for things like 'one of a set values', 'given value'
  • support for parsing TLV (type, length, value) style records commonly found in binary formats

pry-parser's People

Contributors

dmitryolshansky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pry-parser's Issues

Question: procedural sequence generation

I'm writing a parser for ruby, as an experiment in D, and was considering Pry as an option for parsing due to my preference for in-language DSLs.

Ruby has an interesting rule for string literals, essentially, you can define a string literal according to the following grammar, where char is any printable non-alphanumeric ASCII character - STRING2 : %(Q|q|x|r|S|s) char {any_char} char. For example, "a string", %{a string} and %q{a string} are equivalent for our intents.

Declaring each variant separately and explicitly would result in a huge number of rules to write, and then maintain.

Pry's lack of documentation, outside of the examples, has currently led me to believe that there is no Pry-idiomatic expression to match all of these variants as well as ensure they are terminated with the same delimiter.

I'm left with a few options, assuming that what I what is not expressible within the framework of Pry:

  • Use CTFE to generate a sequence for every possible variant

  • Find a way to write a custom parser which is compatible with Pry

Feature request: Case-insensitive versions of tk/stk/literal?

I'm writing a parser for a case-insensitive language. Though I could just enumerate all possible permutations of keywords, this seems like it'd create code smell more than anything else. (I could also just do .map(x => ...), but again, this seems like unnecessary bloat.) Please add case-insensitive versions of tk/stk/literal.

Some features seems not released in the current version

So, simply by adding pry as a dependency on a virgin project, and using features that are present in the documentation and examples, dub indicates that these features are non-existent. I have identified the following combinators that were not recognized: delimited, optional, skipWs, slice, utfString and also the stk atom. There may be others.

Searching in the code and in the different versions, it seems that the combinators I quoted are not part of the old versions (under 0.3.2), but it is indeed this version that I included in the blank project...

Here is a simple example (by the way, the examples in the "example" folder don't work for me either):

import pry;
import std.stdio;

void main()
{
    alias S = SimpleStream!string;
    with(parsers!S)
    {
        auto p = delimited(range!('0', '9').rep, tk!',');
        auto s = "1,2,3".stream;
        string[] values;
        S.Error err;
        auto r = p.parse(s, values, err);
        writeln(r);
    }
}

With the following dub.sdl :

name "test"
dependency "pry" version="~>0.3.2"

By building, I get:

$ dub build
pry 0.3.2: target for configuration "library" is up to date.
test ~master: building configuration "application"...
source\app.d(9,12): Error: undefined identifier delimited

What's wrong with all this? How come I'm using the "newest" version of pry, but an older version of the library seems to be used instead? Perhaps a new version should be updated?

SEGFAULT instead of proper error handling with wrong grammar

auto makeParser(){
  with(parsers!S) {
    auto expr = dynamic!int;
    auto primary = any(
      range!('0', '9').rep.map!(x => x.to!int),
      seq(tk!'(', expr, tk!')').map!(x => x[1])
    );
    auto term = dynamic!int;
    term = any(
      seq(primary, tk!'*', term).map!(x => x[0] * x[2]),
      seq(primary, tk!'/', term).map!(x => x[0] / x[2]),
      primary
    );
    //expr = any(
    //  seq(term, tk!'+', expr).map!(x => x[0] + x[2]),
    //  seq(term, tk!'-', expr).map!(x => x[0] - x[2]),
    //  term
    //);
    return expr;
  }
}

running modified calc example as above yields a SEGFAULT ; could we improve error msg in this case?

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.