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


Java CharStream類代碼示例

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


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

示例1: parseAnyUnhandled

import org.antlr.runtime.CharStream; //導入依賴的package包/類
/**
 * Just call a parser method in {@link CqlParser} - does not do any error handling.
 */
public static <R> R parseAnyUnhandled(CQLParserFunction<R> parserFunction, String input) throws RecognitionException
{
    // Lexer and parser
    ErrorCollector errorCollector = new ErrorCollector(input);
    CharStream stream = new ANTLRStringStream(input);
    CqlLexer lexer = new CqlLexer(stream);
    lexer.addErrorListener(errorCollector);

    TokenStream tokenStream = new CommonTokenStream(lexer);
    CqlParser parser = new CqlParser(tokenStream);
    parser.addErrorListener(errorCollector);

    // Parse the query string to a statement instance
    R r = parserFunction.parse(parser);

    // The errorCollector has queue up any errors that the lexer and parser may have encountered
    // along the way, if necessary, we turn the last error into exceptions here.
    errorCollector.throwFirstSyntaxError();

    return r;
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:25,代碼來源:CQLFragmentParser.java

示例2: test1

import org.antlr.runtime.CharStream; //導入依賴的package包/類
@Test
public void test1() throws RecognitionException {
    CharStream input = new ANTLRStringStream("version(1.1.0)\n" + "minVer(1.1.0)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "type RaptureQueryResult(@package=rapture.common) {\n" + "    List(JsonContent) rows;\n" + "}\n");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getApiTemplates("Java"));
    com.incapture.rapgen.TTree.hmxdef_return walkerResult = walker.hmxdef();
    System.out.println("Done, result=" + walkerResult.toString());
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:21,代碼來源:JavaWalkerTest.java

示例3: test4

import org.antlr.runtime.CharStream; //導入依賴的package包/類
@Test
public void test4() throws RecognitionException {
    CharStream input = new ANTLRStringStream("sdk(alan)\n" + "version(0.0.1)\n" + "minVer(0.0.1)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "type RaptureQueryResult(@package=rapture.common) {\n" + "    List(JsonContent) rows;\n" + "}\n");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getSdkTemplates("Java"));
    walker.sdkGen();
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:20,代碼來源:JavaWalkerTest.java

示例4: testBean

import org.antlr.runtime.CharStream; //導入依賴的package包/類
@Test
public void testBean() throws RecognitionException {
    CharStream input = new ANTLRStringStream("version(1.1.0)\n" + "minVer(1.1.0)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" +
            "[A Graph node]\n" +
            "@Bean\n" +
            "type Node(@package=rapture.common.dp) {\n" +
            "    String nodeId; //this is not a URI, just a String id\n" +
            "    List<XFer> xferValues;\n" +
            "}\n" +
            "");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getApiTemplates("Java"));
    apiGen_return walkerResult = walker.apiGen();
    System.out.println("Done, result=" + walkerResult.toString());
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:27,代碼來源:JavaWalkerTest.java

示例5: doParse

import org.antlr.runtime.CharStream; //導入依賴的package包/類
protected IParseResult doParse(String ruleName, CharStream in, NodeModelBuilder nodeModelBuilder, int initialLookAhead) {
	TokenSource tokenSource = createLexer(in);
	XtextTokenStream tokenStream = createTokenStream(tokenSource);
	tokenStream.initCurrentLookAhead(initialLookAhead);
	setInitialHiddenTokens(tokenStream);
	AbstractInternalAntlrParser parser = createParser(tokenStream);
	parser.setTokenTypeMap(getTokenDefProvider().getTokenDefMap());
	parser.setSyntaxErrorProvider(getSyntaxErrorProvider());
	parser.setNodeModelBuilder(nodeModelBuilder);
	parser.setSemanticModelBuilder(getElementFactory());
	IUnorderedGroupHelper helper = getUnorderedGroupHelper().get();
	parser.setUnorderedGroupHelper(helper);
	helper.initializeWith(parser);
	try {
		if(ruleName != null)
			return parser.parse(ruleName);
		return parser.parse();
	} catch (Exception re) {
		throw new ParseException(re.getMessage(),re);
	}
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:22,代碼來源:AbstractAntlrParser.java

示例6: loadTemplateFile

import org.antlr.runtime.CharStream; //導入依賴的package包/類
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix !=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:26,代碼來源:STGroup.java

示例7: test1

import org.antlr.runtime.CharStream; //導入依賴的package包/類
@Test
public void test1() throws RecognitionException, IOException {
    CharStream input = new ANTLRStringStream("version(1.1.0)\n" + "minVer(1.1.0)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "type RaptureQueryResult(@package=rapture.common) {\n" + "    List(JsonContent) rows;\n" + "}\n");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTreeJS walker = new TTreeJS(treeInput);
    walker.setTemplateLib(getJsTemplate());
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:19,代碼來源:JSWalkerTest.java

示例8: loadTemplateFile

import org.antlr.runtime.CharStream; //導入依賴的package包/類
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:26,代碼來源:STGroup.java

示例9: toTokenString

import org.antlr.runtime.CharStream; //導入依賴的package包/類
public String toTokenString() {
	CharStream input = this.token.getInputStream();
	GrammarASTAdaptor adaptor = new GrammarASTAdaptor(input);
	CommonTreeNodeStream nodes =
		new CommonTreeNodeStream(adaptor, this);
	StringBuilder buf = new StringBuilder();
	GrammarAST o = (GrammarAST)nodes.LT(1);
	int type = adaptor.getType(o);
	while ( type!=Token.EOF ) {
		buf.append(" ");
		buf.append(o.getText());
		nodes.consume();
		o = (GrammarAST)nodes.LT(1);
		type = adaptor.getType(o);
	}
	return buf.toString();
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:18,代碼來源:GrammarAST.java

示例10: doParse

import org.antlr.runtime.CharStream; //導入依賴的package包/類
private List<Token> doParse(CharStream in) {
	TokenSource tokenSource = createLexer(in);
	LazyTokenStream tokenStream = createTokenStream(tokenSource);
	setInitialHiddenTokens(tokenStream);
	InternalN4JSParser parser = createParser(tokenStream);
	IUnorderedGroupHelper helper = unorderedGroupHelper.get();
	if (!(helper instanceof IUnorderedGroupHelper.Null)) {
		throw new IllegalStateException("Unexpected usage of unordered groups.");
	}
	Stopwatch stopwatch = null;
	boolean debug = LOGGER.isDebugEnabled();
	// boolean debug = true;
	if (debug) {
		stopwatch = Stopwatch.createStarted();
	}
	try {
		parser.entryRuleScript();
		while (tokenStream.LT(1) != Token.EOF_TOKEN) {
			tokenStream.consume();
		}
		@SuppressWarnings("unchecked")
		List<Token> result = tokenStream.getTokens();
		return result;
	} catch (Exception re) {
		throw new ParseException(re.getMessage(), re);
	} finally {
		if (debug) {
			assert stopwatch != null;
			long elapsed = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
			if (elapsed > 5) {
				LOGGER.warn("Coloring parser took: " + elapsed);
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:36,代碼來源:HighlightingParser.java

示例11: toString

import org.antlr.runtime.CharStream; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public String toString(int start, int stop) {
	if (start < 0 || stop < 0) {
		return null;
	}
	CommonToken startToken = (CommonToken) tokens.get(start);
	CommonToken stopToken = (CommonToken) tokens.get(stop);
	CharStream charStream = ((Lexer) tokenSource).getCharStream();
	String result = charStream.toString().substring(startToken.getStartIndex(), stopToken.getStopIndex());
	return result;
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:15,代碼來源:LazyTokenStream.java

示例12: read

import org.antlr.runtime.CharStream; //導入依賴的package包/類
private int read() {
    int result = li.read();
    if (result == LexerInput.EOF) {
        result = CharStream.EOF;
    }

    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:NbLexerCharStream.java

示例13: LA

import org.antlr.runtime.CharStream; //導入依賴的package包/類
@Override
public int LA(int i) {
    if (i == 0)
        return 0; // undefined
    if (i < 0)
        i++; // e.g., translate LA(-1) to use offset 0
    if ((p + i - 1) >= n)
        return CharStream.EOF;
    return Character.toUpperCase(data[p + i - 1]);
}
 
開發者ID:aravindc,項目名稱:jdbacl,代碼行數:11,代碼來源:ANTLRNoCaseStringStream.java

示例14: parse

import org.antlr.runtime.CharStream; //導入依賴的package包/類
private CommonTree parse(String query) throws RecognitionException
{
    CharStream cs = new ANTLRStringStream(query);
    CMISLexer lexer = new CMISLexer(cs);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    CMISParser parser = new CMISParser(tokens);
    CommonTree queryNode = (CommonTree) parser.query().getTree();
    return queryNode;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:10,代碼來源:OpenCmisQueryTest.java

示例15: createLexer

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


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