Java Code Examples for org.antlr.v4.tool.Grammar#getOptionString()
The following examples show how to use
org.antlr.v4.tool.Grammar#getOptionString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParserFile.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
public ParserFile(OutputModelFactory factory, String fileName) { super(factory, fileName); Grammar g = factory.getGrammar(); namedActions = new HashMap<String, Action>(); for (String name : g.namedActions.keySet()) { ActionAST ast = g.namedActions.get(name); namedActions.put(name, new Action(factory, ast)); } genPackage = g.tool.genPackage; // need the below members in the ST for Python genListener = g.tool.gen_listener; genVisitor = g.tool.gen_visitor; grammarName = g.name; if (g.getOptionString("contextSuperClass") != null) { contextSuperClass = new ActionText(null, g.getOptionString("contextSuperClass")); } }
Example 2
Source File: OutputFile.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public OutputFile(OutputModelFactory factory, String fileName) { super(factory); this.fileName = fileName; Grammar g = factory.getGrammar(); grammarFileName = g.fileName; ANTLRVersion = Tool.VERSION; TokenLabelType = g.getOptionString("TokenLabelType"); InputSymbolType = TokenLabelType; }
Example 3
Source File: Recognizer.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public Recognizer(OutputModelFactory factory) { super(factory); Grammar g = factory.getGrammar(); grammarFileName = new File(g.fileName).getName(); grammarName = g.name; name = g.getRecognizerName(); tokens = new LinkedHashMap<String,Integer>(); for (Map.Entry<String, Integer> entry : g.tokenNameToTypeMap.entrySet()) { Integer ttype = entry.getValue(); if ( ttype>0 ) { tokens.put(entry.getKey(), ttype); } } ruleNames = g.rules.keySet(); rules = g.rules.values(); atn = new SerializedATN(factory, g.atn); if (g.getOptionString("superClass") != null) { superClass = new ActionText(null, g.getOptionString("superClass")); } else { superClass = null; } CodeGenerator gen = factory.getGenerator(); tokenNames = translateTokenStringsToTarget(g.getTokenDisplayNames(), gen); literalNames = translateTokenStringsToTarget(g.getTokenLiteralNames(), gen); symbolicNames = translateTokenStringsToTarget(g.getTokenSymbolicNames(), gen); }
Example 4
Source File: RunANTLROnGrammarFile.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean isGrammarStale(ANTLRv4GrammarProperties grammarProperties) { String sourcePath = grammarProperties.resolveLibDir(project, getParentDir(grammarFile)); String fullyQualifiedInputFileName = sourcePath+File.separator+grammarFile.getName(); ANTLRv4PluginController controller = ANTLRv4PluginController.getInstance(project); final PreviewState previewState = controller.getPreviewState(grammarFile); Grammar g = previewState.getMainGrammar(); // Grammar should be updated in the preview state before calling this function if ( g==null ) { return false; } String language = g.getOptionString(ANTLRv4GrammarProperties.PROP_LANGUAGE); CodeGenerator generator = new CodeGenerator(null, g, language); String recognizerFileName = generator.getRecognizerFileName(); VirtualFile contentRoot = getContentRoot(project, grammarFile); String package_ = grammarProperties.getPackage(); String outputDirName = grammarProperties.resolveOutputDirName(project, contentRoot, package_); String fullyQualifiedOutputFileName = outputDirName+File.separator+recognizerFileName; File inF = new File(fullyQualifiedInputFileName); File outF = new File(fullyQualifiedOutputFileName); boolean stale = inF.lastModified()>outF.lastModified(); LOG.info((!stale ? "not" : "") + "stale: " + fullyQualifiedInputFileName + " -> " + fullyQualifiedOutputFileName); return stale; }
Example 5
Source File: Tool.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
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(); } }
Example 6
Source File: CodeGenerator.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
public CodeGenerator(Grammar g) { this(g.tool, g, g.getOptionString("language")); }