Giter Site home page Giter Site logo

Comments (7)

josevalim avatar josevalim commented on July 28, 2024

Yes, we need to improve the API around this. Today defparsec and defparsecp actually serve different purposes, we probably need a more explicit API for exporting and importing parsecs.

Although it is very important to note that traversing between modules requires creating binary references.

from nimble_parsec.

josevalim avatar josevalim commented on July 28, 2024

@meox btw, if you want to break parsing apart, the suggestion is to actually compose on the combinators, since changing between modules will slow down parsing.

from nimble_parsec.

meox avatar meox commented on July 28, 2024

Hi @josevalim,
I use the composition but in my case is not enough, because I'd like to have a way to define a "macro" to generate a very similar parser.

Immagine that you have to parse two different kinds of data structure:

  • list: [a, b, c, d]
  • tuple: {:x, 1, "Jose", 10}

if you try to write a parser you will end up to have more or less the same code.
So I saw two way:

  • we can try to define the macro in the same module of the parser, but the problem here is that we need to force the compiler to compile the things in our order
  • we can define the macro in a different parser but we have to permit the usage of defparsec from a different module.

from nimble_parsec.

josevalim avatar josevalim commented on July 28, 2024

@meox if you break it at this level of granularity, then parsing will end-up being slow. Both of the issues you have mentioned are addressable with what parsec provides today.

Imagine you have a MyHelper module. The thing that is shared in both list and tuple to into collection_contents combinator.

defmodule MyHelper do
  import NimbleParsec

  def collection_contents do
    string() |> ... |> ...
  end
end

Now with the combinators defined, you can include them in the final module:

defparsecp :collection_contents, MyHelper.collectiion_contents()

list = string("[") |> parsec(:collection_contents) |> string("]")
tuple = string("{") |> parsec(:collection_contents) |> string("}")

What am I missing?

from nimble_parsec.

meox avatar meox commented on July 28, 2024

Probably you are right.
My analysis started here:
#27

from nimble_parsec.

josevalim avatar josevalim commented on July 28, 2024

@meox maybe it is better to compose combinators with regular functions then, rather than doing so with macros. Since you are encapsulating everything in macros, you are struggling with composing it, but if you rely on the combinators you should be fine.

from nimble_parsec.

meox avatar meox commented on July 28, 2024

ok thanks, I'll try to put in practice your suggestion

from nimble_parsec.

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.