components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/js/source-editor/antlr-worker.js
/**
     * ANTLR worker prototype
     * The instance created will handle all ANTLR related tasks
     *
     * @constructor
     */
ANTLR worker prototype
The instance created will handle all ANTLR related tasks

@constructor
ANTLR worker prototype The instance created will handle all ANTLR related tasks @constructor
function ANTLRWalker() {
        var walker = this;
        var lastParseTree;
        walker.syntaxErrorList = [];
        walker.completionData = {
            streamsList: {},
            partitionsList: [],
            eventTablesList: {},
            eventTriggersList: {},
            evalScriptsList: {},
            eventWindowsList: {},
            aggregationsList: {}
        };
        walker.incompleteData = {
            streams: [],
            partitions: [],
            aggregationDefinitions: []
        };
        walker.statementsList = [];
        walker.tokenToolTipData = [];
        walker.queries = [];
        function clearData() {
            walker.syntaxErrorList = [];
            walker.completionData = {
                streamsList: {},
                partitionsList: [],
                eventTablesList: {},
                eventTriggersList: {},
                evalScriptsList: {},
                eventWindowsList: {},
                aggregationsList: {}
            };
            walker.incompleteData = {
                streams: [],
                partitions: [],
                aggregationDefinitions: []
            };
            walker.statementsList = [];
            walker.queries = [];
        }
        function clearTokenTooltipData() {
            walker.tokenToolTipData = [];
        }
        var antlr4 = require(SiddhiEditor.constants.antlr.INDEX);                                                                          
        var SiddhiQLLexer = require(SiddhiEditor.constants.antlr.ROOT + SiddhiEditor.constants.antlr.SIDDHI_LEXER).SiddhiQLLexer;
        var SiddhiQLParser = require(SiddhiEditor.constants.antlr.ROOT + SiddhiEditor.constants.antlr.SIDDHI_PARSER).SiddhiQLParser;
        var DataPopulationListener = require(SiddhiEditor.constants.antlr.ROOT + SiddhiEditor.constants.antlr.SIDDHI_DATA_POPULATION_LISTENER).DataPopulationListener;
        var SyntaxErrorListener = require(SiddhiEditor.constants.antlr.ROOT + SiddhiEditor.constants.antlr.SYNTAX_ERROR_LISTENER).SyntaxErrorListener;
        var TokenTooltipPointRecognitionListener = require(SiddhiEditor.constants.antlr.ROOT + SiddhiEditor.constants.antlr.SIDDHI_TOKEN_TOOL_TIP_UPDATE_LISTENER).TokenTooltipPointRecognitionListener;
        walker.onEditorChange = function (editorText) {
            var errorListener = new SyntaxErrorListener(walker);
            var txt = new antlr4.InputStream(editorText);       
            var lexer = new SiddhiQLLexer(txt);                 
            lexer._listeners = [];
            lexer._listeners.push(errorListener);
            var tokens = new antlr4.CommonTokenStream(lexer);   
            var parser = new SiddhiQLParser(tokens);            
            parser._listeners = [];
            parser._listeners.push(errorListener);
            parser.buildParseTrees = true;
            lastParseTree = parser.parse();
            renderer.notifyParseTreeWalkingCompletion(walker.syntaxErrorList);
            var dataPopulationListener = new DataPopulationListener(walker);
            antlr4.tree.ParseTreeWalker.DEFAULT.walk(dataPopulationListener, lastParseTree);
            renderer.notifyDataPopulationCompletion(
                walker.completionData,
                walker.incompleteData,
                walker.statementsList,
                walker.queries
            );
            clearData();
        };
        walker.recognizeTokenTooltipPoints = function () {
            var tokenTooltipPointRecognitionListener = new TokenTooltipPointRecognitionListener(walker);
            antlr4.tree.ParseTreeWalker.DEFAULT.walk(tokenTooltipPointRecognitionListener, lastParseTree);
            renderer.notifyTokenTooltipPointRecognitionCompletion(walker.tokenToolTipData);
            clearTokenTooltipData();
        };
        walker.utils = (function () {
            var utils = {};
            utils.getTextFromANTLRCtx = function (ctx) {
                return ctx.start.getInputStream().getText(ctx.start.start, ctx.stop.stop);
            };
            utils.getQueryMetaData = function (ctx) {
                var queryInfo = {
                    start: ctx.children[0].start.line,
                    end: ctx.children[0].stop.line,
                    query: ctx.start.getInputStream().getText(ctx.start.start, ctx.stop.stop)
                };
                if(ctx.query() != null){
                    for (var i = 0; i < ctx.query().children.length; i++) {
                        var childCtx = ctx.query().getChild(i);
                        switch(childCtx.constructor.name) {
                            case 'Query_inputContext':
                                queryInfo.in = childCtx.start.line;
                                break;
                            case 'Query_outputContext':
                                queryInfo.out = childCtx.start.line;
                                break;
                            default:
                                break;
                        }
                    }
                }else{
                    queryInfo.in = ctx.children[0].start.line;
                    queryInfo.out = ctx.children[0].stop.line;
                }
                return queryInfo;
            };
            return utils;
        })();
    }
function ANTLRWalker ( ) { var walker = this ; var lastParseTree ; walker . syntaxErrorList = [ ] ; walker . completionData = { streamsList : { } , partitionsList : [ ] , eventTablesList : { } , eventTriggersList : { } , evalScriptsList : { } , eventWindowsList : { } , aggregationsList : { } } ; walker . incompleteData = { streams : [ ] , partitions : [ ] , aggregationDefinitions : [ ] } ; walker . statementsList = [ ] ; walker . tokenToolTipData = [ ] ; walker . queries = [ ] ; function clearData ( ) { walker . syntaxErrorList = [ ] ; walker . completionData = { streamsList : { } , partitionsList : [ ] , eventTablesList : { } , eventTriggersList : { } , evalScriptsList : { } , eventWindowsList : { } , aggregationsList : { } } ; walker . incompleteData = { streams : [ ] , partitions : [ ] , aggregationDefinitions : [ ] } ; walker . statementsList = [ ] ; walker . queries = [ ] ; } function clearTokenTooltipData ( ) { walker . tokenToolTipData = [ ] ; } var antlr4 = require ( SiddhiEditor . constants . antlr . INDEX ) ; var SiddhiQLLexer = require ( SiddhiEditor . constants . antlr . ROOT + SiddhiEditor . constants . antlr . SIDDHI_LEXER ) . SiddhiQLLexer ; var SiddhiQLParser = require ( SiddhiEditor . constants . antlr . ROOT + SiddhiEditor . constants . antlr . SIDDHI_PARSER ) . SiddhiQLParser ; var DataPopulationListener = require ( SiddhiEditor . constants . antlr . ROOT + SiddhiEditor . constants . antlr . SIDDHI_DATA_POPULATION_LISTENER ) . DataPopulationListener ; var SyntaxErrorListener = require ( SiddhiEditor . constants . antlr . ROOT + SiddhiEditor . constants . antlr . SYNTAX_ERROR_LISTENER ) . SyntaxErrorListener ; var TokenTooltipPointRecognitionListener = require ( SiddhiEditor . constants . antlr . ROOT + SiddhiEditor . constants . antlr . SIDDHI_TOKEN_TOOL_TIP_UPDATE_LISTENER ) . TokenTooltipPointRecognitionListener ; walker . onEditorChange = function ( editorText ) { var errorListener = new SyntaxErrorListener ( walker ) ; var txt = new antlr4 . InputStream ( editorText ) ; var lexer = new SiddhiQLLexer ( txt ) ; lexer . _listeners = [ ] ; lexer . _listeners . push ( errorListener ) ; var tokens = new antlr4 . CommonTokenStream ( lexer ) ; var parser = new SiddhiQLParser ( tokens ) ; parser . _listeners = [ ] ; parser . _listeners . push ( errorListener ) ; parser . buildParseTrees = true ; lastParseTree = parser . parse ( ) ; renderer . notifyParseTreeWalkingCompletion ( walker . syntaxErrorList ) ; var dataPopulationListener = new DataPopulationListener ( walker ) ; antlr4 . tree . ParseTreeWalker . DEFAULT . walk ( dataPopulationListener , lastParseTree ) ; renderer . notifyDataPopulationCompletion ( walker . completionData , walker . incompleteData , walker . statementsList , walker . queries ) ; clearData ( ) ; } ; walker . recognizeTokenTooltipPoints = function ( ) { var tokenTooltipPointRecognitionListener = new TokenTooltipPointRecognitionListener ( walker ) ; antlr4 . tree . ParseTreeWalker . DEFAULT . walk ( tokenTooltipPointRecognitionListener , lastParseTree ) ; renderer . notifyTokenTooltipPointRecognitionCompletion ( walker . tokenToolTipData ) ; clearTokenTooltipData ( ) ; } ; walker . utils = ( function ( ) { var utils = { } ; utils . getTextFromANTLRCtx = function ( ctx ) { return ctx . start . getInputStream ( ) . getText ( ctx . start . start , ctx . stop . stop ) ; } ; utils . getQueryMetaData = function ( ctx ) { var queryInfo = { start : ctx . children [ 0 ] . start . line , end : ctx . children [ 0 ] . stop . line , query : ctx . start . getInputStream ( ) . getText ( ctx . start . start , ctx . stop . stop ) } ; if ( ctx . query ( ) != null ) { for ( var i = 0 ; i < ctx . query ( ) . children . length ; i ++ ) { var childCtx = ctx . query ( ) . getChild ( i ) ; switch ( childCtx . constructor . name ) { case 'Query_inputContext' : queryInfo . in = childCtx . start . line ; break ; case 'Query_outputContext' : queryInfo . out = childCtx . start . line ; break ; default : break ; } } } else { queryInfo . in = ctx . children [ 0 ] . start . line ; queryInfo . out = ctx . children [ 0 ] . stop . line ; } return queryInfo ; } ; return utils ; } ) ( ) ; }
ANTLR worker prototype
 The instance created will handle all ANTLR related tasks
ANTLR worker prototype The instance created will handle all ANTLR related tasks
/*
         * Variables used for storing temporary data
         */ /**
         * Clear all the temporary data held after data population by the ANTLR walker
         */ /**
         * Clear all the tooltip point data held by the ANTLR worker
         */ /*
         * Loading ANTLR related modules
         */ // ANTLR4 JS runtime /**
         * Run on editor change tasks
         * Creates the parse tree and walks it for recognizing syntax errors and completion engine's data
         * Syntax errors list will be passed to the main js after finding them
         * Completion Engine's data will be passed to the main js after finding them
         *
         * @param {string} editorText Text in the editor for which the parse tree will be generated
         */ // Following code segment parse the input query using antlr4's parser and lexer // Input stream // Generating lexer // Generated a token stream // Using the token stream , generate the parser // Syntax errors in parsing are stored in  editor.state.syntaxErrorList // Adding the syntax errors identified into the editor gutter // Walking the parse tree to generate completion data // Notify the main js and clear completion data /**
         * Recognize all the points at which the tooltips should be added
         * Walks the parse tree to recognize the points
         * Position of the tooltip, type of the tooltip and other data required by the tooltip will be passed back to the main js
         */ // Walking the parse tree to identify the token tooltip points // Actually adding the tooltips in done in the main.js // Notify the main js and clear data /**
             * Get the text in the parse tree relevant for the ANTLR context provided
             *
             * @param ctx The context for which the text is returned
             * @return {string} The text relevant to the context provided
             */