本文整理汇总了Java中org.antlr.v4.tool.LexerGrammar类的典型用法代码示例。如果您正苦于以下问题:Java LexerGrammar类的具体用法?Java LexerGrammar怎么用?Java LexerGrammar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LexerGrammar类属于org.antlr.v4.tool包,在下文中一共展示了LexerGrammar类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parseText
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
public static ParsingResult parseText(Grammar g,
LexerGrammar lg,
String startRuleName,
final VirtualFile grammarFile,
String inputText)
throws IOException
{
ANTLRInputStream input = new ANTLRInputStream(inputText);
LexerInterpreter lexEngine;
lexEngine = lg.createLexerInterpreter(input);
SyntaxErrorListener syntaxErrorListener = new SyntaxErrorListener();
lexEngine.removeErrorListeners();
lexEngine.addErrorListener(syntaxErrorListener);
CommonTokenStream tokens = new TokenStreamSubset(lexEngine);
return parseText(g, lg, startRuleName, grammarFile, syntaxErrorListener, tokens, 0);
}
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:17,代码来源:ParsingUtils.java
示例2: LexerATNFactory
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
public LexerATNFactory(LexerGrammar g) {
super(g);
// use codegen to get correct language templates for lexer commands
String language = g.getOptionString("language");
CodeGenerator gen = new CodeGenerator(g.tool, null, language);
codegenTemplates = gen.getTemplates();
}
开发者ID:antlr,项目名称:codebuff,代码行数:8,代码来源:LexerATNFactory.java
示例3: getConstantValue
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
protected Integer getConstantValue(String name, Token token) {
if (name == null) {
return null;
}
Integer commonConstant = COMMON_CONSTANTS.get(name);
if (commonConstant != null) {
return commonConstant;
}
int tokenType = g.getTokenType(name);
if (tokenType != org.antlr.v4.runtime.Token.INVALID_TYPE) {
return tokenType;
}
int channelValue = g.getChannelValue(name);
if (channelValue >= org.antlr.v4.runtime.Token.MIN_USER_CHANNEL_VALUE) {
return channelValue;
}
List<String> modeNames = new ArrayList<String>(((LexerGrammar)g).modes.keySet());
int mode = modeNames.indexOf(name);
if (mode >= 0) {
return mode;
}
try {
return Integer.parseInt(name);
} catch (NumberFormatException ex) {
g.tool.errMgr.grammarError(ErrorType.UNKNOWN_LEXER_CONSTANT, g.fileName, token, currentRule.name, token != null ? token.getText() : null);
return null;
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:34,代码来源:LexerATNFactory.java
示例4: ParserATNFactory
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
public ParserATNFactory(Grammar g) {
if (g == null) {
throw new NullPointerException("g");
}
this.g = g;
ATNType atnType = g instanceof LexerGrammar ? ATNType.LEXER : ATNType.PARSER;
int maxTokenType = g.getMaxTokenType();
this.atn = new ATN(atnType, maxTokenType);
}
开发者ID:antlr,项目名称:codebuff,代码行数:12,代码来源:ParserATNFactory.java
示例5: Lexer
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
public Lexer(OutputModelFactory factory, LexerFile file) {
super(factory);
this.file = file; // who contains us?
Grammar g = factory.getGrammar();
channels = new LinkedHashMap<String, Integer>(g.channelNameToValueMap);
modes = ((LexerGrammar)g).modes.keySet();
}
开发者ID:antlr,项目名称:codebuff,代码行数:9,代码来源:Lexer.java
示例6: assignChannelTypes
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
/**
* Assign constant values to custom channels defined in a grammar.
*
* @param g The grammar.
* @param channelDefs A collection of AST nodes defining individual channels
* within a {@code channels{}} block in the grammar.
*/
void assignChannelTypes(Grammar g, List<GrammarAST> channelDefs) {
Grammar outermost = g.getOutermostGrammar();
for (GrammarAST channel : channelDefs) {
String channelName = channel.getText();
// Channel names can't alias tokens or modes, because constant
// values are also assigned to them and the ->channel(NAME) lexer
// command does not distinguish between the various ways a constant
// can be declared. This method does not verify that channels do not
// alias rules, because rule names are not associated with constant
// values in ANTLR grammar semantics.
if (g.getTokenType(channelName) != Token.INVALID_TYPE) {
g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_TOKEN, g.fileName, channel.token, channelName);
}
if (LexerATNFactory.COMMON_CONSTANTS.containsKey(channelName)) {
g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_COMMON_CONSTANTS, g.fileName, channel.token, channelName);
}
if (outermost instanceof LexerGrammar) {
LexerGrammar lexerGrammar = (LexerGrammar)outermost;
if (lexerGrammar.modes.containsKey(channelName)) {
g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_MODE, g.fileName, channel.token, channelName);
}
}
outermost.defineChannelName(channel.getText());
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:38,代码来源:SemanticPipeline.java
示例7: buildFromSnapshot
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
public static ParserInterpreterData buildFromSnapshot(DocumentSnapshot snapshot) {
LexerInterpreterData lexerInterpreterData = LexerInterpreterData.buildFromSnapshot(snapshot);
if (lexerInterpreterData == null) {
return null;
}
List<SyntaxError> syntaxErrors = new ArrayList<>();
Tool tool = new CustomTool(snapshot);
tool.errMgr = new CustomErrorManager(tool);
tool.addListener(new ErrorListener(snapshot, tool, syntaxErrors));
tool.libDirectory = new File(snapshot.getVersionedDocument().getFileObject().getPath()).getParent();
ANTLRStringStream stream = new ANTLRStringStream(snapshot.getText());
stream.name = snapshot.getVersionedDocument().getFileObject().getNameExt();
GrammarRootAST ast = tool.parse(stream.name, stream);
Grammar grammar = tool.createGrammar(ast);
if (grammar instanceof LexerGrammar) {
return null;
}
tool.process(grammar, false);
ParserInterpreterData data = new ParserInterpreterData();
// start by filling in the lexer data
data.lexerInterpreterData = lexerInterpreterData;
// then fill in the parser data
data.grammarFileName = grammar.fileName;
data.serializedAtn = ATNSerializer.getSerializedAsString(grammar.atn, Arrays.asList(grammar.getRuleNames()));
data.vocabulary = grammar.getVocabulary();
data.ruleNames = new ArrayList<>(grammar.rules.keySet());
return data;
}
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:36,代码来源:ParserInterpreterData.java
示例8: loadGrammar
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
/** Same as loadGrammar(fileName) except import vocab from existing lexer */
private Grammar loadGrammar(final Tool tool, final String fileName,
final LexerGrammar lexerGrammar) {
GrammarRootAST grammarRootAST = tool.parseGrammar(fileName);
final Grammar g = tool.createGrammar(grammarRootAST);
g.fileName = fileName;
if (lexerGrammar != null) {
g.importVocab(lexerGrammar);
}
tool.process(g, false);
return g;
}
开发者ID:antlr4ide,项目名称:antlr4ide,代码行数:13,代码来源:ParseTreeCommand.java
示例9: updateGrammarObjectsFromFile_
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
public String updateGrammarObjectsFromFile_(VirtualFile grammarFile) {
String grammarFileName = grammarFile.getPath();
PreviewState previewState = getPreviewState(grammarFile);
Grammar[] grammars = ParsingUtils.loadGrammars(grammarFileName, project);
if (grammars != null) {
synchronized (previewState) { // build atomically
previewState.lg = (LexerGrammar)grammars[0];
previewState.g = grammars[1];
}
}
return grammarFileName;
}
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:13,代码来源:ANTLRv4PluginController.java
示例10: process
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
/**
* compile lexer and parser
*/
public void process() {
CodeGenerator cgen = new CodeGenerator(g);
IntervalSet idTypes = new IntervalSet();
idTypes.add(ANTLRParser.ID);
idTypes.add(ANTLRParser.RULE_REF);
idTypes.add(ANTLRParser.TOKEN_REF);
List<GrammarAST> idNodes = g.ast.getNodesWithType(idTypes);
idNodes.stream()
.filter(idNode -> cgen.getTarget()
.grammarSymbolCausesIssueInGeneratedCode(idNode))
.forEach(idNode -> g.tool.errMgr.grammarError(ErrorType.USE_OF_BAD_WORD,
g.fileName, idNode.getToken(),
idNode.getText()));
if (g.isLexer()) {
lexer = cgen.generateLexer();
} else {
parser = cgen.generateParser();
if (g.tool.gen_listener) {
listener = cgen.generateListener();
if (cgen.getTarget().wantsBaseListener()) {
baseListener = cgen.generateBaseListener();
}
}
if (g.tool.gen_visitor) {
visitor = cgen.generateVisitor();
if (cgen.getTarget().wantsBaseVisitor()) {
baseVisitor = cgen.generateBaseVisitor();
}
}
LexerGrammar lg;
if ((lg = g.implicitLexer) != null) {
CodeGenerator lgcg = new CodeGenerator(lg);
lexer = lgcg.generateLexer();
}
}
tokenvocab = getTokenVocabOutput();
}
开发者ID:julianthome,项目名称:inmemantlr,代码行数:48,代码来源:StringCodeGenPipeline.java
示例11: processNonCombinedGrammar
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
public void processNonCombinedGrammar(Grammar g, boolean gencode) {
if ( g.ast==null || g.ast.hasErrors ) return;
if ( internalOption_PrintGrammarTree ) System.out.println(g.ast.toStringTree());
boolean ruleFail = checkForRuleIssues(g);
if ( ruleFail ) return;
int prevErrors = errMgr.getNumErrors();
// MAKE SURE GRAMMAR IS SEMANTICALLY CORRECT (FILL IN GRAMMAR OBJECT)
SemanticPipeline sem = new SemanticPipeline(g);
sem.process();
String language = g.getOptionString("language");
if ( !CodeGenerator.targetExists(language) ) {
errMgr.toolError(ErrorType.CANNOT_CREATE_TARGET_GENERATOR, language);
return;
}
if ( errMgr.getNumErrors()>prevErrors ) return;
// BUILD ATN FROM AST
ATNFactory factory;
if ( g.isLexer() ) factory = new LexerATNFactory((LexerGrammar)g);
else factory = new ParserATNFactory(g);
g.atn = factory.createATN();
if ( generate_ATN_dot ) generateATNs(g);
// PERFORM GRAMMAR ANALYSIS ON ATN: BUILD DECISION DFAs
AnalysisPipeline anal = new AnalysisPipeline(g);
anal.process();
//if ( generate_DFA_dot ) generateDFAs(g);
if ( g.tool.getNumErrors()>prevErrors ) return;
// GENERATE CODE
if ( gencode ) {
CodeGenPipeline gen = new CodeGenPipeline(g);
gen.process();
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:43,代码来源:Tool.java
示例12: getRuleDependencies
import org.antlr.v4.tool.LexerGrammar; //导入依赖的package包/类
public static Map<Rule, Set<Rule>> getRuleDependencies(LexerGrammar g, String modeName) {
return getRuleDependencies(g, g.modes.get(modeName));
}
开发者ID:antlr,项目名称:codebuff,代码行数:4,代码来源:UseDefAnalyzer.java
注:本文中的org.antlr.v4.tool.LexerGrammar类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论