當前位置: 首頁>>代碼示例>>Java>>正文


Java CommonTokenStream.getTokens方法代碼示例

本文整理匯總了Java中org.antlr.runtime.CommonTokenStream.getTokens方法的典型用法代碼示例。如果您正苦於以下問題:Java CommonTokenStream.getTokens方法的具體用法?Java CommonTokenStream.getTokens怎麽用?Java CommonTokenStream.getTokens使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.antlr.runtime.CommonTokenStream的用法示例。


在下文中一共展示了CommonTokenStream.getTokens方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTokens

import org.antlr.runtime.CommonTokenStream; //導入方法依賴的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

示例2: testLexerOutput

import org.antlr.runtime.CommonTokenStream; //導入方法依賴的package包/類
public void testLexerOutput() throws IOException
{
    String str = "~woof^2";
    CharStream input = new ANTLRInputStream(new ByteArrayInputStream(str.getBytes("UTF-8")));
    FTSLexer lexer = new FTSLexer(input);
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    for(CommonToken token : (List<CommonToken>)tokenStream.getTokens())
    {
        System.out.println(token.toString());
    }
    
}
 
開發者ID:Alfresco,項目名稱:alfresco-data-model,代碼行數:13,代碼來源:CMIS_FTSTest.java

示例3: testLexerError_01

import org.antlr.runtime.CommonTokenStream; //導入方法依賴的package包/類
@Test public void testLexerError_01() throws Exception {
      String model = "a /* incomplete comment *";
      InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
      lexer.setCharStream(new ANTLRStringStream(model));
      CommonTokenStream stream = new CommonTokenStream(lexer);
      @SuppressWarnings("unchecked")
List<CommonToken> tokens = stream.getTokens();
      assertEquals(tokens.toString(), 3, tokens.size());
      assertEquals("a", tokens.get(0).getText());
      assertEquals(" ", tokens.get(1).getText());
      assertEquals("/* incomplete comment *", tokens.get(2).getText());
      assertEquals(0, tokens.get(2).getType());
  }
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:14,代碼來源:LexerErrorTest.java

示例4: testLexerError_02

import org.antlr.runtime.CommonTokenStream; //導入方法依賴的package包/類
@Test public void testLexerError_02() throws Exception {
	String model = "a 'incomplete string";
	InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
	lexer.setCharStream(new ANTLRStringStream(model));
	CommonTokenStream stream = new CommonTokenStream(lexer);
	@SuppressWarnings("unchecked")
	List<CommonToken> tokens = stream.getTokens();
       assertEquals(tokens.toString(), 3, tokens.size());
       assertEquals("a", tokens.get(0).getText());
       assertEquals(" ", tokens.get(1).getText());
       assertEquals("'incomplete string", tokens.get(2).getText());
       assertEquals(0, tokens.get(2).getType());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:14,代碼來源:LexerErrorTest.java

示例5: testLexerError_03

import org.antlr.runtime.CommonTokenStream; //導入方法依賴的package包/類
@Test public void testLexerError_03() throws Exception {
	String model = "a '\\ incomplete string with bad escape sequence";
	InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
	lexer.setCharStream(new ANTLRStringStream(model));
	CommonTokenStream stream = new CommonTokenStream(lexer);
	@SuppressWarnings("unchecked")
	List<CommonToken> tokens = stream.getTokens();
       assertEquals(tokens.toString(), 3, tokens.size());
       assertEquals("a", tokens.get(0).getText());
       assertEquals(" ", tokens.get(1).getText());
       assertEquals("'\\ incomplete string with bad escape sequence", tokens.get(2).getText());
       assertEquals(0, tokens.get(2).getType());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:14,代碼來源:LexerErrorTest.java

示例6: testLexerError_04

import org.antlr.runtime.CommonTokenStream; //導入方法依賴的package包/類
@Test public void testLexerError_04() throws Exception {
	String model = "a 'incomplete string with bad escape sequence \\";
	InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
	lexer.setCharStream(new ANTLRStringStream(model));
	CommonTokenStream stream = new CommonTokenStream(lexer);
	@SuppressWarnings("unchecked")
	List<CommonToken> tokens = stream.getTokens();
	assertEquals(tokens.toString(), 3, tokens.size());
	assertEquals("a", tokens.get(0).getText());
	assertEquals(" ", tokens.get(1).getText());
	assertEquals("'incomplete string with bad escape sequence \\", tokens.get(2).getText());
	assertEquals(0, tokens.get(2).getType());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:14,代碼來源:LexerErrorTest.java

示例7: testLexerError_05

import org.antlr.runtime.CommonTokenStream; //導入方法依賴的package包/類
@Test public void testLexerError_05() throws Exception {
	String model = "a 'incomplete string \\'";
	InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
	lexer.setCharStream(new ANTLRStringStream(model));
	CommonTokenStream stream = new CommonTokenStream(lexer);
	@SuppressWarnings("unchecked")
	List<CommonToken> tokens = stream.getTokens();
	assertEquals(tokens.toString(), 3, tokens.size());
	assertEquals("a", tokens.get(0).getText());
	assertEquals(" ", tokens.get(1).getText());
	assertEquals("'incomplete string \\'", tokens.get(2).getText());
	assertEquals(0, tokens.get(2).getType());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:14,代碼來源:LexerErrorTest.java

示例8: testLexerError_06

import org.antlr.runtime.CommonTokenStream; //導入方法依賴的package包/類
@Test public void testLexerError_06() throws Exception {
	String model = "a '";
	InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
	lexer.setCharStream(new ANTLRStringStream(model));
	CommonTokenStream stream = new CommonTokenStream(lexer);
	@SuppressWarnings("unchecked")
	List<CommonToken> tokens = stream.getTokens();
	assertEquals(tokens.toString(), 3, tokens.size());
	assertEquals("a", tokens.get(0).getText());
	assertEquals(" ", tokens.get(1).getText());
	assertEquals("'", tokens.get(2).getText());
	assertEquals(InternalSimpleExpressionsTestLanguageParser.RULE_ANY_OTHER, tokens.get(2).getType());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:14,代碼來源:LexerErrorTest.java


注:本文中的org.antlr.runtime.CommonTokenStream.getTokens方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。