https://github.com/stagas/minipratt-js
port of https://github.com/matklad/minipratt to JavaScript
https://github.com/stagas/minipratt-js
operator-precedence parser pratt recursive-descent recursive-descent-parser tdop top-down
Last synced: 8 months ago
JSON representation
port of https://github.com/matklad/minipratt to JavaScript
- Host: GitHub
- URL: https://github.com/stagas/minipratt-js
- Owner: stagas
- Created: 2021-11-22T19:23:23.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-30T16:37:26.000Z (over 4 years ago)
- Last Synced: 2025-02-11T08:44:53.003Z (over 1 year ago)
- Topics: operator-precedence, parser, pratt, recursive-descent, recursive-descent-parser, tdop, top-down
- Language: TypeScript
- Homepage:
- Size: 215 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
minipratt-js
port of matklad/minipratt to JavaScript
```ts
s = parse('1')
expect(to_string(s)).toEqual('1')
s = parse('+1')
expect(to_string(s)).toEqual('(+ 1)')
s = parse('1 + +-1')
expect(to_string(s)).toEqual('(+ 1 (+ (- 1)))')
s = parse('1 + 2 * 3')
expect(to_string(s)).toEqual('(+ 1 (* 2 3))')
s = parse('a + b * c * d + e')
expect(to_string(s)).toEqual('(+ (+ a (* (* b c) d)) e)')
s = parse('f . g . h')
expect(to_string(s)).toEqual('(. f (. g h))')
s = parse('1 + 2 + f . g . h * 3 * 4')
expect(to_string(s)).toEqual('(+ (+ 1 2) (* (* (. f (. g h)) 3) 4))')
s = parse('--1 * 2')
expect(to_string(s)).toEqual('(* (- (- 1)) 2)')
s = parse('--f . g')
expect(to_string(s)).toEqual('(- (- (. f g)))')
s = parse('-9!')
expect(to_string(s)).toEqual('(- (! 9))')
s = parse('f . g !')
expect(to_string(s)).toEqual('(! (. f g))')
s = parse('(((0)))')
expect(to_string(s)).toEqual('0')
s = parse('x[0][1]')
expect(to_string(s)).toEqual('([ ([ x 0) 1)')
s = parse(`
a ? b :
c ? d
: e
`)
expect(to_string(s)).toEqual('(? a b (? c d e))')
s = parse('a = 0 ? b : c = d')
expect(to_string(s)).toEqual('(= a (= (? 0 b c) d))')
```