Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nixpulvis/parser-combinator
CFG Parser Combinators for Racket
https://github.com/nixpulvis/parser-combinator
json library parser
Last synced: 9 days ago
JSON representation
CFG Parser Combinators for Racket
- Host: GitHub
- URL: https://github.com/nixpulvis/parser-combinator
- Owner: nixpulvis
- License: other
- Created: 2014-11-03T22:31:56.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-05-05T01:07:10.000Z (over 5 years ago)
- Last Synced: 2024-10-18T23:38:39.686Z (18 days ago)
- Topics: json, library, parser
- Language: Racket
- Homepage: https://nixpulvis.com/projects/parser-combinator
- Size: 172 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# parser-combinator
Simple Racket parser library, and default (tested) JSON implementation.
## Install
```sh
raco pkg install parser-combinator
```## JSON Usage
```racket
#lang racket
(require parser-combinator/json)(string->json "[]")
;=> '()
(string->json "[1, {\"foo\": false}, 2]")
;=> (list 1 (list (json-pair "foo" #f)) 2)
```## Parser Usage
```racket
#lang racket
(require parser-combinator/parse)(define-parser DIGIT+ (alt* (lit "0")
(lit "1")
(lit "2")
(lit "3")
(lit "4")
(lit "5")
(lit "6")
(lit "7")
(lit "8")
(lit "9")))(define-parser DIGIT (alt* (lit "0") DIGIT+))
(define-parser NUMBER (seq* 'number
(opt (lit "-"))
(alt* (lit "0") (seq* 'significand
DIGIT+
(star DIGIT))))); (seq-node 'number AST AST) -> Number
(define (parse-number ast)
(string->number (string-append "#e" (flatten-ast ast)))); String -> Number
(define (parse str)
(parse-number (parse NUMBER str)))(println (parse "0"))
(println (parse "-0"))
(println (parse "1"))
(println (parse "140"))
```## Tests
Run all of the tests.
```sh
raco test *tests.rkt
```