class JavaScriptLexer extends JFlexSymbolMatcher
        implements JFlexJointLexer, Resettable {

    private ECMAScriptLexerData data;

    /**
     * Represents the stack of data if substitution is nested.
     */
    private Stack<ECMAScriptLexerData> dataStack;

    public JavaScriptLexer() {
        data = new ECMAScriptLexerData();
        // dataStack is null to begin.
    }

    /**
     * Resets the instance to an initial state.
     */
    @Override
    public void reset() {
        super.reset();
        data = new ECMAScriptLexerData();
        if (dataStack != null) {
            dataStack.clear();
        }
    }

    /**
     * Calls {@link #phLOC()} if the yystate is not COMMENT or SCOMMENT.
     */
    public void chkLOC() {
        if (yystate() != COMMENT() && yystate() != SCOMMENT()) {
            phLOC();
        }
    }

    /**
     * Resets the substitution brace counter to 1.
     */
    protected void substitutionOp() {
        data.nEndBrace = 1;
    }

    /**
     * Determine if template substitution should end based on the first
     * character of {@code capture}, and also recognizing tokens that increase
     * the nesting level alternatively.
     * <p>
     * Calling this method has side effects to possibly modify
     * {@code nEndBrace}.
     * @return {@code true} if the substitution state does not end
     */
    protected boolean notInTemplateOrSubstitutionDoesNotEnd(String capture) throws IOException {<FILL_FUNCTION_BODY>}

    protected void pushData() {
        if (dataStack == null) {
            dataStack = new Stack<>();
        }
        dataStack.push(data);
        data = new ECMAScriptLexerData();
    }

    private void popData() {
        data = dataStack.pop();
    }

    /**
     * Subclasses must override to get the constant value created by JFlex to
     * represent COMMENT.
     */
    protected abstract int COMMENT();

    /**
     * Subclasses must override to get the constant value created by JFlex to
     * represent SCOMMENT.
     */
    protected abstract int SCOMMENT();

    private static class ECMAScriptLexerData {
        /**
         * When interpolating inside `` with ${, the number of remaining '}'
         * characters is stored. It starts at 1, and any nesting increases the
         * value.
         */
        int nEndBrace;
    }
}

        if (data.nEndBrace <= 0) {
            return true;
        }
        if (capture.startsWith("}")) {
            if (--data.nEndBrace <= 0) {
                int nRemaining = capture.length() - 1;
                String opener = capture.substring(0, 1);
                popData();
                yypop();
                disjointSpan(HtmlConsts.STRING_CLASS);
                offer(opener);
                if (nRemaining > 0) {
                    yypushback(nRemaining);
                }
                return false;
            }
        }
        if (capture.startsWith("{")) {
            ++data.nEndBrace;
        }
        return true;
    
<methods>public non-sealed void <init>() ,public void clearNonSymbolMatchedListener() ,public void clearSymbolMatchedListener() ,public void setNonSymbolMatchedListener(org.opengrok.indexer.analysis.NonSymbolMatchedListener) ,public void setSymbolMatchedListener(org.opengrok.indexer.analysis.SymbolMatchedListener) <variables>private java.lang.String disjointSpanClassName,private org.opengrok.indexer.analysis.NonSymbolMatchedListener nonSymbolListener,private org.opengrok.indexer.analysis.SymbolMatchedListener symbolListener