Skip to content

Commit

Permalink
Offsets for tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Jul 8, 2022
1 parent 30340f8 commit 8d4cb5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
21 changes: 13 additions & 8 deletions lib/compiler/passes/generate-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function generateJS(ast, options) {
"peg$tracer.trace({",
" type: \"rule.enter\",",
" rule: " + ruleNameCode + ",",
" location: peg$computeLocation(startPos, startPos)",
" location: peg$computeLocation(startPos, startPos, true)",
"});",
""
);
Expand All @@ -249,13 +249,13 @@ function generateJS(ast, options) {
" type: \"rule.match\",",
" rule: " + ruleNameCode + ",",
" result: cached.result,",
" location: peg$computeLocation(startPos, peg$currPos)",
" location: peg$computeLocation(startPos, peg$currPos, true)",
" });",
"} else {",
" peg$tracer.trace({",
" type: \"rule.fail\",",
" rule: " + ruleNameCode + ",",
" location: peg$computeLocation(startPos, startPos)",
" location: peg$computeLocation(startPos, startPos, true)",
" });",
"}",
""
Expand Down Expand Up @@ -290,13 +290,13 @@ function generateJS(ast, options) {
" type: \"rule.match\",",
" rule: " + ruleNameCode + ",",
" result: " + resultCode + ",",
" location: peg$computeLocation(startPos, peg$currPos)",
" location: peg$computeLocation(startPos, peg$currPos, true)",
" });",
"} else {",
" peg$tracer.trace({",
" type: \"rule.fail\",",
" rule: " + ruleNameCode + ",",
" location: peg$computeLocation(startPos, startPos)",
" location: peg$computeLocation(startPos, startPos, true)",
" });",
"}"
);
Expand Down Expand Up @@ -710,7 +710,7 @@ function generateJS(ast, options) {
" }",
" }",
" var s = this.location.start;",
" var offset_s = (typeof this.location.source.offset === \"function\")",
" var offset_s = (this.location.source && (typeof this.location.source.offset === \"function\"))",
" ? this.location.source.offset(s)",
" : s;",
" var loc = this.location.source + \":\" + offset_s.line + \":\" + offset_s.column;",
Expand Down Expand Up @@ -1040,11 +1040,11 @@ function generateJS(ast, options) {
" }",
" }",
"",
" function peg$computeLocation(startPos, endPos) {",
" function peg$computeLocation(startPos, endPos, offset) {",
" var startPosDetails = peg$computePosDetails(startPos);",
" var endPosDetails = peg$computePosDetails(endPos);",
"",
" return {",
" var res = {",
" source: peg$source,",
" start: {",
" offset: startPos,",
Expand All @@ -1057,6 +1057,11 @@ function generateJS(ast, options) {
" column: endPosDetails.column",
" }",
" };",
" if (offset && peg$source && (typeof peg$source.offset === \"function\")) {",
" res.start = peg$source.offset(res.start);",
" res.end = peg$source.offset(res.end);",
" }",
" return res;",
" }",
"",
" function peg$fail(expected) {",
Expand Down
11 changes: 8 additions & 3 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d4cb5f

Please sign in to comment.