Skip to content

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

47 Commits

Folders and files

Repository files navigation

yaml-reference-parser-clj

Pure Clojure YAML 1.2 reference parser, packaged for Maven/Clojars as:

org.yamlstar/yaml-parser {:mvn/version "0.2.6"}

Leiningen:

[org.yamlstar/yaml-parser "0.2.6"]

Usage

(require '[yaml-parser.core :as yaml-parser])

(yaml-parser/parse "name: YAML\nitems: [1, 2]\n")

The parser returns YAML event maps such as stream_start, document_start, mapping_start, scalar, and stream_end.

Performance

The grammar is generated directly from the machine-readable YAML 1.2 spec and keeps its ordered-choice structure for spec parity. The engine makes that fast with packrat memoization of the flow-context rules, so the backtracking that is inherent to the spec grammar costs a table lookup instead of a re-parse. Set YAML_PARSER_NO_MEMO=1 to disable memoization (useful for A/B verification that event streams are identical). bench/run-bench times the parser over a small synthetic corpus.

Development

make deps
make grammar
make test
make jar
VERSION=0.2.6 make deploy

The Makefile uses https://github.com/makeplus/makes to install local bb, clojure, lein, maven, and perl tools under .cache/local. make test runs both focused API tests and the upstream yaml-test-suite TAP runner. make deploy publishes to Clojars through deps-deploy; make deploy-lein uses Leiningen.

Production replacements

parse accepts an optional :productions map keyed by the specification's hyphenated production keywords. Each replacement receives the same parser and arguments as the original production and returns its normal result or parser combinator. Unknown productions and non-function values are rejected.

(yaml-parser/parse input {:productions {:s-separate-in-line my-separation}})

Replacements belong to one parser instance and retain receiver callback identities. Parses with replacements use the generated canonical grammar, bypassing fused scanners and lookahead gates that embed the standard productions. make grammar generates both grammars from the same specification.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages