Javascript 使用Require.js时发生XML分析错误

Javascript 使用Require.js时发生XML分析错误,javascript,xml-parsing,antlr,antlr4,codemirror,Javascript,Xml Parsing,Antlr,Antlr4,Codemirror,我正在尝试将JavaScript Antl4解析器与基于CodeMirror的文本编辑器集成。我研究了如何集成解析器,并编写了以下代码: // Parser var antlr4 = require('antlr4/index'); // load nodejs compatible require var ace_require = require; require = undefined; var Honey = { 'requirePath': [

我正在尝试将JavaScript Antl4解析器与基于CodeMirror的文本编辑器集成。我研究了如何集成解析器,并编写了以下代码:

// Parser
    var antlr4 = require('antlr4/index');

    // load nodejs compatible require
    var ace_require = require;
    require = undefined;
    var Honey = { 'requirePath': [] }; // walk up to js folder, see Honey docs
    importScripts("lib/require.js");
    var antlr4_require = require;
    require = ace_require;

    // load antlr4 and myLanguage
    var antlr4, Lexer ,Parser;
    try {
        require = antlr4_require;
        antlr4 = require('antlr4/index');
        Lexer = require('generated-parser/SparkS_v2Lexer');
        Parser = require('generated-parser/SparkS_v2Parser');
    } finally {
        require = ace_require;
    }

    // class for gathering errors and posting them to the editor
    var AnnotatingErrorListener = function(annotations) {
        antlr4.error.ErrorListener.call(this);
        this.annotations = annotations;
        return this;
    };

    AnnotatingErrorListener.prototype = Object.create(antlr4.error.ErrorListener.prototype);
    AnnotatingErrorListener.prototype.constructor = AnnotatingErrorListener;

    AnnotatingErrorListener.prototype.syntaxError = function(recognizer, offendingSymbol, line, column, msg, e) {
        this.annotations.push({
            row: line - 1,
            column: column,
            text: msg,
            type: "error"
    });
    };

    var validate = function(input) {
        var stream = new antlr4.InputStream(input);
        var lexer = new Lexer.SparkS_v2Lexer(stream);
        var tokens = new antlr4.CommonTokenStream(lexer);
        var parser = new Parser.SparkS_v2Parser(tokens);
        var annotations = [];
        var listener = new AnnotatingErrorListener(annotations)
        parser.removeErrorListeners();
        parser.addErrorListener(listener);
        parser.parseMyRule();
        return annotations;
    };

    editor.on("keyup", function() {
        console.log(validate(editor.getValue()));
    })
为了加载解析器,我使用了TorbenHaase基于教程的蜂蜜项目的“require.js”库。但是,对于每个“必需”文件,我都会遇到以下和其他XML解析错误:

那么,我如何解决这些错误呢

提前感谢…

请不要使用标签来指代除此之外的任何内容。
Uncaught Error: Honey: unable to load 0:antlr4/index (0 )
XML Parsing Error: not well-formed Location: file:///home/enes/Desktop/git/text_editor_mirror/antlr4/index.js Line Number 1, Column 1:
ReferenceError: importScripts is not defined