فهرست منبع

MPIDE-27: add flag to return original AST

Allows the user to specify whether the parse result should include the
original AST in addition to the normal model. Defaults to false.
Austin Meagher 10 سال پیش
والد
کامیت
59845cc35d
1فایلهای تغییر یافته به همراه4 افزوده شده و 1 حذف شده
  1. 4 1
      src/lib/parser/modellang.pegjs

+ 4 - 1
src/lib/parser/modellang.pegjs

@@ -3,7 +3,8 @@
     var opts = arguments[2] || options,
     var opts = arguments[2] || options,
         fileName = opts.fileName || "NOFILENAME",
         fileName = opts.fileName || "NOFILENAME",
         locations = opts.locations !== undefined ? opts.locations : true,
         locations = opts.locations !== undefined ? opts.locations : true,
-        comments = opts.comments !== undefined ? opts.comments : false;
+        comments = opts.comments !== undefined ? opts.comments : false,
+        showAst = opts.showAst !== undefined ? opts.showAst : false;
 
 
     var err = function err(msg, suffix, opts) {
     var err = function err(msg, suffix, opts) {
         opts = opts || {};
         opts = opts || {};
@@ -39,6 +40,8 @@
             init: [],
             init: [],
         };
         };
 
 
+        if (showAst) model.ast = statements;
+
         // accumulate varying statements into a flatter structure
         // accumulate varying statements into a flatter structure
         for (var s in statements) {
         for (var s in statements) {
             var statement = statements[s];
             var statement = statements[s];