@Override
    public Object visitPattern_source_chain(@NotNull SiddhiQLParser.Pattern_source_chainContext ctx) {
//    pattern_source_chain
//    : '('pattern_source_chain')' 
//    | pattern_source_chain  '->' pattern_source_chain
//    | pattern_source 
//    ;

        if (ctx.pattern_source_chain().size() == 1) {
            StateElement stateElement = ((StateElement) visit(ctx.pattern_source_chain(0)));
            populateQueryContext(stateElement, ctx);
            return stateElement;
        } else if (ctx.pattern_source_chain().size() == 2) {
            NextStateElement nextStateElement = new NextStateElement((
                    (StateElement) visit(ctx.pattern_source_chain(0))),
                    ((StateElement) visit(ctx.pattern_source_chain(1))));
            populateQueryContext(nextStateElement, ctx);
            return nextStateElement;
        } else if (ctx.pattern_source() != null) {
            StateElement stateElement = ((StateElement) visit(ctx.pattern_source()));
            populateQueryContext(stateElement, ctx);
            return stateElement;
        } else {
            throw newSiddhiParserException(ctx);
        }
    }
{@inheritDoc}
<p>The default implementation returns the result of calling
{@link #visitChildren} on {@code ctx}.</p>

@param ctx
modules/siddhi-query-compiler/src/main/java/io/siddhi/query/compiler/internal/SiddhiQLBaseVisitorImpl.java