Java源码示例:com.sonar.sslr.impl.channel.BlackHoleChannel
示例1
/**
* Creates a Lexer, contains all channels to analyze apex language.
*
* @param config apex configuration.
* @return a lexer instance.
*/
public static Lexer create(ApexConfiguration config) {
return Lexer.builder()
.withCharset(config.getCharset())
.withFailIfNoChannelToConsumeOneCharacter(Boolean.TRUE)
.withChannel(commentRegexp(SINGLE_LINE_PATTERN))
.withChannel(commentRegexp(MULTI_LINE_PATTERN))
.withChannel(regexp(ApexTokenType.DECIMAL_FLOATING_POINT_LITERAL, DECIMAL_FLOATING_POINT_LITERAL_PATTERN))
.withChannel(regexp(ApexTokenType.HEXADECIMAL_FLOATING_POINT_LITERAL, HEXADECIMAL_FLOATING_POINT_LITERAL_PATTERN))
.withChannel(regexp(ApexTokenType.INTEGER_LITERAL, INTEGER_LITERAL_PATTERN))
.withChannel(regexp(ApexTokenType.STRING, STRING_PATTERN))
.withChannel(new IdentifierAndKeywordChannel(IDENTIFIER_PATTERN,
Boolean.FALSE, ApexKeyword.values()))
.withChannel(new PunctuatorChannel(ApexPunctuator.values()))
.withChannel(new BlackHoleChannel(BLACK_HOLE))
.build();
}
示例2
public static Lexer create(LuaConfiguration conf) {
return Lexer.builder()
.withCharset(conf.getCharset())
.withFailIfNoChannelToConsumeOneCharacter(true)
.withChannel(new BomCharacterChannel())
.withChannel(new BlackHoleChannel("\\s++"))
// Comments
.withChannel(commentRegexp("//[^\\n\\r]*+"))
.withChannel(commentRegexp("/\\*[\\s\\S]*?\\*/"))
// String Literals
.withChannel(regexp(GenericTokenType.LITERAL, "\"([^\"\\\\]*+(\\\\[\\s\\S])?+)*+\""))
.withChannel(regexp(GenericTokenType.LITERAL, "\'([^\'\\\\]*+(\\\\[\\s\\S])?+)*+\'"))
// Regular Expression Literal
.withChannel(new LuaRegularExpressionLiteralChannel())
// Numbers
.withChannel(regexp(LuaTokenType.NUMERIC_LITERAL, "0[xX][0-9a-fA-F]++"))
.withChannel(regexp(LuaTokenType.NUMERIC_LITERAL, "[0-9]++\\.([0-9]++)?+" + EXP + "?+"))
.withChannel(regexp(LuaTokenType.NUMERIC_LITERAL, "\\.[0-9]++" + EXP + "?+"))
.withChannel(regexp(LuaTokenType.NUMERIC_LITERAL, "[0-9]++" + EXP + "?+"))
.withChannel(new IdentifierAndKeywordChannel("\\p{javaJavaIdentifierStart}++\\p{javaJavaIdentifierPart}*+", true, LuaKeyword.values()))
.withChannel(new PunctuatorChannel(LuaPunctuator.values()))
.withChannel(new UnknownCharacterChannel())
.build();
}
示例3
/**
* Creates this lexer.
* @param conf
* Configuration for this lexer.
* @return
*/
public static Lexer create(FlowConfiguration conf) {
return Lexer.builder().withCharset(conf.getCharset())
.withFailIfNoChannelToConsumeOneCharacter(true).withChannel(new SaxChannel())
.withChannel(new BlackHoleChannel(".*")).build();
}