Comments (7)
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.
@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.
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.
@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.
Probably you are right.
My analysis started here:
#27
from nimble_parsec.
@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.
ok thanks, I'll try to put in practice your suggestion
from nimble_parsec.
Related Issues (20)
- Is such a grammar supported? HOT 3
- Can't use remote combinators defined with defparsec HOT 7
- Library Abuse or Slow Compilation Times HOT 1
- `repeat_while` passing the wrong `context` in nested context
- Warning emitted by integer combinator HOT 3
- Add a default value to `optional` combinator HOT 2
- "Combinators are built during runtime" HOT 1
- When choice after repeat, not work HOT 2
- Fail to create combinator of consecutive repeats HOT 2
- No combinator for the beginning of a string
- MatchError from choice with integer and string. HOT 1
- Accept atoms as labels HOT 2
- Unexpected behaviour in the `post_traverse/3` combinator HOT 2
- return of the partial accumulator when returning an error HOT 4
- Only last element from choice is reported in error reason HOT 6
- Support anonymous functions HOT 1
- Eventually gives unexpected result HOT 1
- Bug with lookahead handling
- Parsing empty string raises `MatchError` for `integer(min: 0)` HOT 4
- Opaque type mismatch on `lookahead/2` since 1.2.0 HOT 5
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 nimble_parsec.