Source: AlphaTab/ProcessAlphaTab.js

const antlr4 = require('antlr4');
const AlphaTexLexer = require('../target/AlphaTexLexer.js').AlphaTexLexer;
const AlphaTexParser = require('../target/AlphaTexParser.js').AlphaTexParser;
const AlphaTexListener = require('../target/AlphaTexListener.js').AlphaTexListener;
const ParserOutput = require("../Parser/ParserOutput.js");
const Visitor = require("./Visitor.js");

/**
 * Processes the provided alphaTex and returns the parsed object
 * @param {string} input AlphaTex to be parsed
 * @param {object} lyricsPerStaff Relates Staff indexes to lyric strings. 
 * @return {ParserOutput} The parsed object form of the alphaTex
 */
const processAlphaTab = (input, lyricsPerStaff) => {
    let chars = new antlr4.InputStream(input);
    let lexer = new AlphaTexLexer(chars);
    let tokens  = new antlr4.CommonTokenStream(lexer);
    let parser = new AlphaTexParser(tokens);
    parser.buildParseTrees = true;
    let tree = parser.alphaTex();

    let alphaTexStructure = tree.accept(new Visitor());

//console.log(alphaTexStructure.toString())

    let parserOutput = new ParserOutput(alphaTexStructure);
    parserOutput.parse(lyricsPerStaff);
    return parserOutput;
    //console.log(parserOutput.toPrettyString());
//console.log(parserOutput.toString());
}

module.exports = {process: processAlphaTab};