-
I'm looking for a way to parse that would also get me line number information for a specific area in the YAML. Would the Documents or CST parsers allow that? To give an example, I'm working on a validator for a specific kind of YAML and I'd like to give the location of the problem along with information about the problem. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Look for "linecounter" in the docs: https://eemeli.org/yaml/ |
Beta Was this translation helpful? Give feedback.
-
@eemeli do you have any examples of using |
Beta Was this translation helpful? Give feedback.
-
Here is how I solved the problem let lineCounter = new yaml.LineCounter();
let docs = yaml.parseAllDocuments(Buffer.from(bytes.buffer).toString(), { keepSourceTokens: true, lineCounter: lineCounter});
let api = doc.get('apiVersion') as yaml.Scalar;
let line = lineCounter.linePos(api.range![1]);
console.log("API is " + api.value + " on line " + line[0]); |
Beta Was this translation helpful? Give feedback.
Look for "linecounter" in the docs: https://eemeli.org/yaml/