本文整理汇总了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;
}
示例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());
}
示例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();
}
示例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());
}
示例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);
}
}
示例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;
}
示例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());
}
示例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;
}
示例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();
}
示例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);
}
}
}
}
示例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;
}
示例12: read
import org.antlr.runtime.CharStream; //导入依赖的package包/类
private int read() {
int result = li.read();
if (result == LexerInput.EOF) {
result = CharStream.EOF;
}
return result;
}
示例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]);
}
示例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;
}
示例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);
}
}