Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn the Lexer, Parser & Composer into generators #253

Merged
merged 3 commits into from Apr 11, 2021
Merged

Turn the Lexer, Parser & Composer into generators #253

merged 3 commits into from Apr 11, 2021

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Apr 3, 2021

In retrospect, this seems so obvious.

All of the parsing stages now provide generators, so that their output may be iterated, rather than needing to provide them with a callback function. As a convenience, a compose() method is also added:

import { Composer, Parser } from 'yaml'

const src = 'foo: bar\nfee: [24, "42"]'
const tokens = new Parser().parse(src)
const docs = new Composer().compose(tokens)

Array.from(docs, doc => doc.toJS())
> [{ foo: 'bar', fee: [24, '42'] }]

This is a breaking change to the API provided for these classes in the preceding 2.0.0-4 release.

BREAKING CHANGE: The `push` argument of `new Lexer()` is dropped, and
instead its `lex()` method is now a Generator<string> that allows for
the lexemes to be iterated.
BREAKING CHANGE: The `push` argument of `new Parser()` is dropped, and
instead its `parse()`, `next()` and `end()` methods are now generators
that allow for the parsed tokens to be iterated.
Adds a convenience method `composer.compose(tokens)`.

BREAKING CHANGE: The `push` argument of `new Composer()` is dropped, and
instead its `next()` and `end()` methods are now generators that allow
for the parsed documents to be iterated.
@eemeli eemeli mentioned this pull request Apr 3, 2021
2 tasks
@eemeli eemeli merged commit 10687c3 into master Apr 11, 2021
@eemeli eemeli deleted the yield branch April 11, 2021 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant