-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Refactor parsing completely #203
Conversation
Hi, I am interested in a specific use case:
Is the CST-API something that you would recommend for this use case? |
Never mind, I wrote a separate issue about whitespace preservation: #207 I needed to keep CST-nodes, although I did not really touch the CST-API. |
Got stuck/sidetracked around flow collection composition for ages, but that looks like it's starting to work now. |
… from those in root
For now with separate build steps: npx rollup -c rollup.dev-config.js npx tsc
…r of YAMLParseError
I'm going to merge this, and update the docs later. I'm also not quite sure yet of the stream API, so that's getting left out for now. My current draft of that is available here: https://gist.github.com/eemeli/2436bda974549eb24ee0696bd8f6368b The new CST level API is included, though, as the |
This PR will effectively replace everything in
/src/cst/
and/src/resolve/
with new code, and redefine the CST level API. As such, I'm guessing that at least @ikatyang and @iann0036 might be interested in getting an early heads-up. This is a work in progress, and not complete yet. I'll update this PR & description as the work continues over the next few weeks (not promising anything about a timetable here).There are three main reasons and starting points for this change.
To that end,
/src/parse/parser
is a new parser that generates CST node trees from its input, internally using/src/parse/lexer
to split the input into tokens. They're both capable of dealing with input coming in chunks, and/src/parse/parse-stream
is a possible Node.js stream wrapper for the parser. See the parser source for TypeScript interfaces for the tokens.Internally, "parsing" now means producing the CST from string input, while the Document object creation is called "composing". That should more closely match the language used in the YAML spec & other implementations. Currently, this composition starts from
/src/compose/compose-doc
, and/src/compose/parse-docs
is a possible wrapper for connecting the parser outputs to the composition.Thanks to all these changes, this finally fixes #116 and makes sure that the
null
nodes mentioned in #170 are removed from both the CST and AST levels.As a point of interest, it should be pretty easy to use the lexer in order to build a really fast basic YAML highlighter. If you want to do fancier things like color-coding depending on the level of logical indentation, you'll probably need the parser as well, and for errors the composer too.
If you'd like to try this out, check out the
stream
branch and run these commands in the repo root:TODO
YAML.Document
API change)Fix self-referential aliases on custom collections(see Anchors are lost when their position is assigned a Node value #229)