Просмотр исходного кода

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 лет назад
Родитель
Сommit
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,
         fileName = opts.fileName || "NOFILENAME",
         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) {
         opts = opts || {};
@@ -39,6 +40,8 @@
             init: [],
         };
 
+        if (showAst) model.ast = statements;
+
         // accumulate varying statements into a flatter structure
         for (var s in statements) {
             var statement = statements[s];