-
-
Notifications
You must be signed in to change notification settings - Fork 106
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 keepSoureToken parse option, adding srcToken values to Nodes #309
Conversation
Might it make sense to use an empty pseudotoken for that case instead of Or provide an API like setKeyScalarValue(item: CollectionItem, value: string, context?): void;
setValueScalarValue(item: CollectionItem, value: string, context?): void; for setting Or an API that returns the a new makeScalarValue(token: Token | undefined, value: string, context?): Token; For the last two ideas, the user needs access to the |
The problem with that approach is that in this case the source of the Node is not just
I don't think these are necessary, as they'd end up as rather minimal wrappers around
The accessor you're looking for is Adding |
An empty sequence is still a sequence. The suggestion was that you could invent a “token” corresponding to an empty string of source characters:
My goal was to find an API that would automatically work for the if (item.value === undefined)
item.value = CST.createScalarToken(value, context);
else
CST.setScalarValue(item.value, value, context); But if you’re content with the existing API, don’t let me stop you from merging this. |
If you can find a clean way of adding appropriate empty value tokens into the CST during the parse, then I might be interested in considering a PR for it. However, even that won't solve all cases, as explicit Assigning a Similarly, I'd be happy to consider a PR for |
Right, the first idea was that the parser would insert these empty tokens into the CST tree. Without an object to represent the empty token, it’s not possible for |
Fixes #308
This allows for usage like this:
The
srcToken
value isn't available on nodes that are created from empty contents, as those do not have a matching CST token. This means that for example the above would fail if thesrc
was'foo:\n'
, as thennode.srcToken
is undefined.To handle that case, you'd probably need to
CST.visit
the parent collection, identify the right CollectionItem, and then useCST.createScalarToken()
when setting itsvalue
. At which point it might be more straightforward to keep all of the operations in the CST, and to never even compose it into documents.