当前位置: 首页>>代码示例>>Java>>正文


Java Lexer类代码示例

本文整理汇总了Java中org.antlr.runtime.Lexer的典型用法代码示例。如果您正苦于以下问题:Java Lexer类的具体用法?Java Lexer怎么用?Java Lexer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Lexer类属于org.antlr.runtime包,在下文中一共展示了Lexer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createParser

import org.antlr.runtime.Lexer; //导入依赖的package包/类
/** Creates a parser for a given term, generating trees of this kind. */
public <P extends Parser> P createParser(Class<P> parserType, I info, String term) {
    try {
        // find the lexer type
        String parserName = parserType.getName();
        String lexerName = parserName.substring(0, parserName.indexOf("Parser"))
            .concat("Lexer");
        @SuppressWarnings("unchecked") Class<? extends Lexer> lexerType =
            (Class<? extends Lexer>) Class.forName(lexerName);
        Lexer lexer = createLexer(lexerType, info, term);
        // instantiate the parser
        CommonTokenStream tokenStream = new CommonTokenStream(lexer);
        Constructor<P> parserConstructor = parserType.getConstructor(TokenStream.class);
        P result = parserConstructor.newInstance(tokenStream);
        Method adaptorSetter = parserType.getMethod("setTreeAdaptor", TreeAdaptor.class);
        adaptorSetter.invoke(result, new ParseTreeAdaptor<>(this, info, tokenStream));
        callInitialise(result, info);
        return result;
    } catch (Exception e) {
        throw toRuntime(e);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:23,代码来源:ParseTree.java

示例2: getTokens

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public static List<Token> getTokens(String sourceCode, String language)
        throws Exception {
    Lexer lexer = null;
    if (language.compareTo("C++") == 0) {
        lexer = new PlagiCOJCppLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("Java") == 0) {
        lexer = new PlagiCOJJavaLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("C#") == 0) {
        lexer = new PlagiCOJCSharpLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("C") == 0) {
        lexer = new PlagiCOJCLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("Python") == 0) {
        lexer = new PlagiCOJPythonLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("Pascal") == 0) {
        lexer = new PlagiCOJPascalLexer(new ANTLRStringStream(sourceCode));
    } else {
        throw new PlagiCOJUnsupportedLanguageException();
    }
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    return tokens.getTokens();
}
 
开发者ID:dovier,项目名称:coj-web,代码行数:22,代码来源:Utils.java

示例3: CompiledFileModelV4

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public CompiledFileModelV4(@NullAllowed Grammar grammar, @NullAllowed GrammarRootAST result, @NonNull List<? extends SyntaxError> syntaxErrors, @NonNull FileObject fileObject, @NullAllowed CommonToken[] tokens) {
    super(fileObject, tokens);
    Parameters.notNull("syntaxErrors", syntaxErrors);

    this.grammar = grammar;
    this.result = result;
    this.syntaxErrors = syntaxErrors;
    this.importedResults = new ArrayList<>();
    if (grammar != null && grammar.importedGrammars != null) {
        for (Grammar imported : grammar.importedGrammars) {
            CommonTokenStream importedTokenStream = (CommonTokenStream)imported.ast.tokenStream;
            String fileName = ((Lexer)importedTokenStream.getTokenSource()).getCharStream().getSourceName();
            FileObject importedFileObject = FileUtil.toFileObject(new File(fileName));
            List<? extends Token> importedTokensList = importedTokenStream.getTokens();
            CommonToken[] importedTokens = importedTokensList.toArray(new CommonToken[0]);
            importedResults.add(new CompiledFileModelV4(imported, imported.ast, Collections.<SyntaxError>emptyList(), importedFileObject, importedTokens));
        }
    }
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:20,代码来源:CompiledFileModelV4.java

示例4: testCaseInsensivityOfSomeAtTokens

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public void testCaseInsensivityOfSomeAtTokens() throws Exception {
    String source = "@FONT-face @charset @CHARSET @charSeT ";

    Lexer lexer = createLexer(source);

    assertANTLRToken("@FONT-face" ,Css3Lexer.FONT_FACE_SYM, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.WS, lexer.nextToken());
    assertANTLRToken("@charset" ,Css3Lexer.CHARSET_SYM, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.WS, lexer.nextToken());
    assertANTLRToken("@CHARSET" ,Css3Lexer.CHARSET_SYM, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.WS, lexer.nextToken());
    assertANTLRToken("@charSeT" ,Css3Lexer.CHARSET_SYM, lexer.nextToken());

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:Css3LexerTest.java

示例5: testExtendOnlySelector2

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public void testExtendOnlySelector2() throws Exception {
    String source = "#context a%extreme {";
    Lexer lexer = createLexer(source);
    assertANTLRToken(null ,Css3Lexer.HASH, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.WS, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.IDENT, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.SASS_EXTEND_ONLY_SELECTOR, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.WS, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.LBRACE, lexer.nextToken());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:Css3LexerTest.java

示例6: testSASS_Else

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public void testSASS_Else() throws Exception {
    String source = "@else cau";
    Lexer lexer = createLexer(source);
    assertANTLRToken(null ,Css3Lexer.SASS_ELSE, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.WS, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.IDENT, lexer.nextToken());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:Css3LexerTest.java

示例7: testLineComment

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public void testLineComment() throws Exception {
    String source = "//comment\na";
    Lexer lexer = createLexer(source);
    assertANTLRToken("//comment" ,Css3Lexer.LINE_COMMENT, lexer.nextToken());
    assertANTLRToken(null ,Css3Lexer.NL, lexer.nextToken());
    assertANTLRToken("a",Css3Lexer.IDENT, lexer.nextToken());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:Css3LexerTest.java

示例8: testLexingOfPercentageWithoutNumberPrefix

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public void testLexingOfPercentageWithoutNumberPrefix() throws Exception {
    String source = "font: %/20 ";
    Lexer lexer = createLexer(source);
    assertANTLRToken("font" ,Css3Lexer.IDENT, lexer.nextToken());
    assertANTLRToken(":" ,Css3Lexer.COLON, lexer.nextToken());
    assertANTLRToken(" " ,Css3Lexer.WS, lexer.nextToken());
    assertANTLRToken("%" , Css3Lexer.PERCENTAGE_SYMBOL, lexer.nextToken());
    assertANTLRToken("/" ,Css3Lexer.SOLIDUS, lexer.nextToken());
    assertANTLRToken("20" , Css3Lexer.NUMBER, lexer.nextToken());
    assertANTLRToken(" " , Css3Lexer.WS, lexer.nextToken());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:Css3LexerTest.java

示例9: createLexer

import org.antlr.runtime.Lexer; //导入依赖的package包/类
/** Factory method for a lexer generating this kind of tree. */
public Lexer createLexer(Class<? extends Lexer> lexerType, I info, String term) {
    try {
        // instantiate the lexer
        ANTLRStringStream input = new ANTLRStringStream(term);
        Constructor<? extends Lexer> lexerConstructor =
            lexerType.getConstructor(CharStream.class);
        Lexer result = lexerConstructor.newInstance(input);
        callInitialise(result, info);
        return result;
    } catch (Exception e) {
        throw toRuntime(e);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:15,代码来源:ParseTree.java

示例10: enough

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public void enough(PE_MySQL parser, List<List<ExpressionNode>> insertValues) {
	Lexer lexer = (Lexer) parser.getTokenStream().getTokenSource(); 
	if (lexer.getCharIndex() - initialOffset > continuationThreshold) {
		finalOffset = lexer.getCharIndex();
		throw new EnoughException(buildInsertStatement(insertValues,true, (initialOffset == 0 ? TransactionStatement.Kind.START : null),null,false));
	}
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:8,代码来源:TranslatorUtils.java

示例11: Block

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public Block(Architecture arch) {
	this.architecture = arch;
	Lexer lex = null;
	Assembler assembler = null;
	
	switch (architecture) {
		// no parsing necessary if we're writing bytes to memory
		case raw:
			return;
		// arm architectures trickle down
		case armv7:
		case armv9:
			// lex = new armLexer(new ANTLRStringStream(program));
			// assembler = new armAssembler(new CommonTokenStream(lex));
			break;
		case x64:
			lex = new x64Lexer(new ANTLRStringStream(program));
			assembler = new x64Assembler(new CommonTokenStream(lex));
			break;
		case x86:
			break;
		default:
			break;
	}
	
	try {
		if (assembler != null) {
			assembler.start();
			this.instructions = assembler.getMachineCode();
		} else {
			throw new JssemblyException("Assembler not found for architecture: " + this.architecture.name());
		}
	} catch (RecognitionException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:dvx,项目名称:jssembly,代码行数:38,代码来源:Block.java

示例12: getDelegates

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public Lexer[] getDelegates() {
	return new Lexer[] {gLexer};
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:4,代码来源:CqlLexer.java

示例13: get

import org.antlr.runtime.Lexer; //导入依赖的package包/类
@Override
public Lexer get() {
	return new InternalN4JSLexer(null);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:5,代码来源:AbstractSmokeTester.java

示例14: testLexingURLToken

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public void testLexingURLToken() throws Exception {
    String source = "url(http://fonts.googleapis.com/css?family=Syncopate) ";
    Lexer lexer = createLexer(source);
    assertANTLRToken(null ,Css3Lexer.URI, lexer.nextToken());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:Css3LexerTest.java

示例15: testSassVar

import org.antlr.runtime.Lexer; //导入依赖的package包/类
public void testSassVar() throws Exception {
    String source = "$var ";
    Lexer lexer = createLexer(source);
    assertANTLRToken(null ,Css3Lexer.SASS_VAR, lexer.nextToken());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:Css3LexerTest.java


注:本文中的org.antlr.runtime.Lexer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。