Example usage for org.antlr.v4.runtime CommonToken setChannel

List of usage examples for org.antlr.v4.runtime CommonToken setChannel

Introduction

In this page you can find the example usage for org.antlr.v4.runtime CommonToken setChannel.

Prototype

@Override
    public void setChannel(int channel) 

Source Link

Usage

From source file:PhpBaseLexer.java

License:Open Source License

@Override
public Token nextToken() {
    CommonToken token = (CommonToken) super.nextToken();

    if (token.getType() == PhpLexer.PHPEnd || token.getType() == PhpLexer.PHPEndSingleLineComment) {
        if (_mode == PhpLexer.SingleLineCommentMode) {
            // SingleLineCommentMode for such allowed syntax:
            // <?php echo "Hello world"; // comment ?>
            popMode(); // exit from SingleLineComment mode.
        }//from   w  ww.  jav a 2s . co m
        popMode(); // exit from PHP mode.

        if (token.getText().equals("</script>")) {
            _phpScript = false;
            token.setType(PhpLexer.ScriptClose);
        } else {
            // Add semicolon to the end of statement if it is absente.
            // For example: <?php echo "Hello world" ?>
            if (_prevTokenType == PhpLexer.SemiColon || _prevTokenType == PhpLexer.Colon
                    || _prevTokenType == PhpLexer.OpenCurlyBracket
                    || _prevTokenType == PhpLexer.CloseCurlyBracket) {
                token.setChannel(PhpLexer.SkipChannel);
            } else {
                token = new CommonToken(PhpLexer.SemiColon);
            }
        }
    } else if (token.getType() == PhpLexer.HtmlName) {
        _htmlNameText = token.getText();
    } else if (token.getType() == PhpLexer.HtmlDoubleQuoteString) {
        if (token.getText().equals("php") && _htmlNameText.equals("language")) {
            _phpScript = true;
        }
    } else if (_mode == PhpLexer.HereDoc) {
        // Heredoc and Nowdoc syntax support: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
        switch (token.getType()) {
        case PhpLexer.StartHereDoc:
        case PhpLexer.StartNowDoc:
            _heredocIdentifier = token.getText().substring(3).trim().replace("\'", "");
            break;

        case PhpLexer.HereDocText:
            if (CheckHeredocEnd(token.getText())) {
                popMode();

                String heredocIdentifier = GetHeredocIdentifier(token.getText());
                if (token.getText().trim().endsWith(";")) {
                    token = new CommonToken(PhpLexer.SemiColon, heredocIdentifier + ";\n");
                } else {
                    token = (CommonToken) super.nextToken();
                    token.setText(heredocIdentifier + "\n;");
                }
            }
            break;
        }
    } else if (_mode == PhpLexer.PHP) {
        if (_channel != PhpLexer.HIDDEN) {
            _prevTokenType = token.getType();
        }
    }

    return token;
}

From source file:com.github.jknack.handlebars.internal.MustacheSpec.java

License:Apache License

/**
 * Move tokens to the hidden channel if necessary.
 *//*  ww w. ja  v  a2s.  c o  m*/
private void stripSpaces() {
    boolean hasTag = this.hasTag == null ? false : this.hasTag.booleanValue();
    if (hasTag && !nonSpace) {
        for (CommonToken space : spaces) {
            space.setChannel(Token.HIDDEN_CHANNEL);
        }
    } else {
        spaces.clear();
    }

    this.hasTag = null;
    nonSpace = false;
    line.setLength(0);
}

From source file:com.github.jknack.handlebars.internal.WhiteSpaceControl.java

License:Apache License

/** Move space tokens to the hidden channel. */
private void hideSpaces() {
    for (CommonToken space : spaces) {
        space.setChannel(Token.HIDDEN_CHANNEL);
    }//  w w  w  .ja  v  a2 s.  c  o  m
}