From 8762a514fda9820357f571360ca0308ae9c7f139 Mon Sep 17 00:00:00 2001 From: Jason Larke Date: Mon, 16 Dec 2019 11:39:17 +0800 Subject: [PATCH] Added positional offsets to each YangStatement This allows the parse results to be used in applications like syntax highlighting / code folding / etc. --- src/yang-parser.litcoffee | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/yang-parser.litcoffee b/src/yang-parser.litcoffee index 140d70c..80ad607 100644 --- a/src/yang-parser.litcoffee +++ b/src/yang-parser.litcoffee @@ -221,12 +221,21 @@ The result of the `statement` parser is an initialized `YangStatement` object. If no argument is present, the object's `arg` property is set to `false`. - statement = keyword.bind (kw) -> + rawStatement = keyword.bind (kw) -> (sep.bind -> argument).option(false).bind (arg) -> strict = true if kw[1] is 'yang-version' and arg is '1.1' optSep.bind -> semiOrBlock.bind (sst) -> P.unit new YangStatement kw[0], kw[1], arg, sst + statement = new P (offset) -> + res = rawStatement.pf offset + + if res[0] != null + res[0].sp = offset + res[0].ep = res[1] + + res + A statement block is a sequence of statements enclosed in braces. Whitespace or comments are permitted before or after any statement in the block.