Comments (3)
I'm also stuck on this one, I can't seem to find a way to pass a type around through the peg
macro to make the parser into a generic, I'm still hitting walls in what is possible with macros.
Help appreciated!
from npeg.
Ok, got this to work. The syntax is not too pretty due to limitations in Nim generics, but it functions as required. Not yet documented, this is what it looks like:
type Thing* = object
word: string
number: int
let s = peg(Thing, "foo"):
foo <- word * number
word <- >+Alpha:
userdata.word = $1
number <- >+Digit:
userdata.number = parseInt($1)
var t = Thing()
let r = s.match("foo123", t)
echo r
echo t
from npeg.
Documented and merged to master.
from npeg.
Related Issues (20)
- lazy matching HOT 1
- Large grammars break NPeg HOT 9
- Attach line information to generate functions HOT 3
- Print return stack on overflow HOT 4
- `-d:npegTrace` code allocates a number of closures equal to the number of states HOT 1
- Implement slicing operators for captures HOT 10
- PEG section in the Nim book HOT 2
- Just wanted to say npeg is great HOT 1
- More/larger examples of Error reporting HOT 5
- Memorization & Bryan Ford HOT 3
- Prevent code blocks captures from executing HOT 7
- A paper citing Npeg HOT 1
- Implement handling of left recursion HOT 5
- [Question] Parsing comments with two characters limits HOT 2
- Performance and Complexity HOT 1
- push() captures broken? HOT 2
- When defining grammar block parameterized rules block name needed? HOT 1
- [Question] Why is my npeg parser done, then starts backtracking and fails. HOT 8
- FR: Deferred code block captures HOT 1
- Enhancing parser flexibility: improving type parsing with the push template HOT 1
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 npeg.