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

Add CST tools #252

Merged
merged 8 commits into from Apr 11, 2021
Merged

Add CST tools #252

merged 8 commits into from Apr 11, 2021

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Apr 3, 2021

Closes #207

This builds on top of #253, so the diff includes its changes as well.

This renames the tokens namespace as CST and adds the following functions. See the updated docs for more on their usage.

import { CST } from 'yaml'
  • CST.createScalarToken(value, ctx) – create a new token
  • CST.isCollection(token) – check for block or flow collection
  • CST.isScalar(token) – check for block or flow scalar
  • CST.resolveAsScalar(token, strict, onError) – get the value of a token
  • CST.setScalarValue(token, value, ctx) – set the value of a token
  • CST.stringify(cst) – stringify any CST content
  • CST.visit(cst, visitor) – custom visitor for walking through the CST
  • CST.visit.itemAtPath(cst, path) – Find the item at path from cst as the root.
  • CST.visit.parentCollection(cst, path) – Get the immediate parent collection of the item at path from cst as the root.

TODO:

  • Add documentation
  • Add tests

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.
BREAKING CHANGE: The public export is renamed from `tokens` to `CST`.
Adds:
- `CST.isCollection(token)`
- `CST.isScalar(token)`
- `CST.stringify(cst)`
- `CST.visit(cst, visitor)`
@eemeli eemeli marked this pull request as ready for review April 3, 2021 17:54
@eemeli eemeli merged commit db48520 into master Apr 11, 2021
@eemeli eemeli deleted the moar-cst branch April 11, 2021 16:47
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.

Allow source modifications with minimal changes
1 participant