Comments (6)
@jhugman Thanks for reporting! For my testing, what is the exact version of pratt
you are depending on?
from pratt.
One thing to try, is that with the new ParseOpts
, BP can be passed with {terminals: bp}
. So you could transform that example to:
import { test } from 'tap';
import Lexer from 'perplex'
import { Parser } from 'pratt'
const lex = new Lexer('1 + -2 * 3^4')
.token('NUM', /\d+/)
.token('+', /\+/)
.token('-', /-/)
.token('*', /\*/)
.token('/', /\//)
.token('^', /\^/)
.token('(', /\(/)
.token(')', /\)/)
.token('$SKIP_WS', /\s+/, true)
const parser = new Parser(lex)
.builder()
.nud('NUM', 100, ({ token }) => parseInt(token.match))
.nud('-', 10, ({ t, bp }) => -parser.parse({ terminals: bp }))
.nud('(', 10, ({ t, bp }) => {
const expr = parser.parse({ terminals: bp })
lex.expect(')')
return expr
})
.bp(')', 0)
.led('^', 20, ({ left, t, bp }) => Math.pow(left, parser.parse({ terminals: bp - 1 })))
.led('+', 30, ({ left, t, bp }) => left + parser.parse({ terminals: bp }))
.led('-', 30, ({ left, t, bp }) => left - parser.parse({ terminals: bp }))
.led('*', 40, ({ left, t, bp }) => left * parser.parse({ terminals: bp }))
.led('/', 40, ({ left, t, bp }) => left / parser.parse({ terminals: bp }))
.build()
test('example works', t => {
t.equal(-161, parser.parse());
});
from pratt.
@jhugman I just wanted to check in and see if you had a chance to try my suggestions?
from pratt.
@jrop Gosh, I'm so sorry I haven't been back to you.
I should've looked at your examples:
.led('*', 40, ({ left, t, bp }) => left * parser.parse({ terminals: [ bp ] }))
(note the [bp]
).
I'm not sure I understand pratt
or Pratt Parsers to know why multiple Array<BP>
is needed, or why they're called terminals. I also don't understand why the ts
type declarations complain more about this :(
Thanks for responding!
from pratt.
@jhugman This is probably due to weak documentation in this module, TBH. Traditionally, you pass parse(bp)
, and the provided bp
is "when to stop parsing" (what I am calling a "terminal", as it terminates the parse run). As I was writing a more sophisticated parser, it became convenient, in certain cases, to provide multiple conditions on which to stop the current parse run, so I modified this library to accept an array of terminals.
from pratt.
@jrop Gosh, I'm so sorry I haven't been back to you.
I should've looked at your examples:
.led('*', 40, ({ left, t, bp }) => left * parser.parse({ terminals: [ bp ] }))
(note the [bp]
).
I'm not sure I understand pratt
or Pratt Parsers to know why multiple Array<BP>
is needed, or why they're called terminals. I also don't understand why the ts
type declarations complain more about this :(
Thanks for responding!
from pratt.
Related Issues (3)
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 pratt.