use of org.antlr.works.utils.ErrorListener in project antlrworks by antlr.
the class ANTLRGrammarEngineImpl method analyze.
public GrammarResult analyze() throws Exception {
// if there is no need to analyze the grammar, return the previous result
if (!needsToAnalyzeGrammar) {
GrammarResult r = analyzeCompleted(null);
if (r.isSuccess()) {
return r;
} else {
needsToAnalyzeGrammar = true;
}
}
// Set the error listener
ErrorListener el = ErrorListener.getThreadInstance();
ErrorManager.setErrorListener(el);
createGrammars();
Grammar g = getDefaultGrammar();
if (g == null) {
return analyzeCompleted(el);
}
List rules = g.checkAllRulesForLeftRecursion();
if (!rules.isEmpty()) {
printLeftRecursionToConsole(rules);
markLeftRecursiveRules(rules);
}
if (ErrorManager.doNotAttemptAnalysis()) {
return analyzeCompleted(el);
}
try {
if (g.nfa == null) {
g.composite.createNFAs();
}
g.createLookaheadDFAs();
if (engine.isCombinedGrammar()) {
// If the grammar is combined, analyze also the lexer
if (lexerGrammar != null) {
lexerGrammar.composite.createNFAs();
lexerGrammar.createLookaheadDFAs();
}
}
buildNonDeterministicErrors(el);
markRulesWithWarningsOrErrors();
} catch (Exception e) {
// ignore
}
return analyzeCompleted(el);
}
use of org.antlr.works.utils.ErrorListener in project antlrworks by antlr.
the class CodeGenerate method generate.
public boolean generate() {
ErrorListener el = ErrorListener.getThreadInstance();
ErrorManager.setErrorListener(el);
String[] params;
if (debug)
params = new String[] { "-debug", "-o", getOutputPath(), "-lib", window.getFileFolder(), window.getFilePath() };
else
params = new String[] { "-o", getOutputPath(), "-lib", window.getFileFolder(), window.getFilePath() };
new File(getOutputPath()).mkdirs();
Tool antlr = new Tool(Utils.concat(params, AWPrefs.getANTLR3Options()));
antlr.process();
boolean success = !el.hasErrors();
if (success) {
dateOfModificationOnDisk = window.getDocument().getDateOfModificationOnDisk();
}
lastError = el.getFirstErrorMessage();
el.clear();
ErrorManager.removeErrorListener();
return success;
}
use of org.antlr.works.utils.ErrorListener in project antlrworks by antlr.
the class ANTLRGrammarEngineImpl method createGrammars.
public void createGrammars() throws Exception {
if (!needsToCreateGrammar) {
if (createGrammarResult.isSuccess()) {
return;
} else {
needsToCreateGrammar = true;
}
}
ErrorListener el = ErrorListener.getThreadInstance();
ErrorManager.setErrorListener(el);
parserGrammar = null;
lexerGrammar = null;
createGrammarResult.clear();
try {
switch(engine.getType()) {
case ElementGrammarName.COMBINED:
createCombinedGrammar();
break;
case ElementGrammarName.TREEPARSER:
case ElementGrammarName.PARSER:
createParserGrammar();
break;
case ElementGrammarName.LEXER:
createLexerGrammar();
break;
}
// if no exception, then assume create grammar was successful
needsToCreateGrammar = false;
} finally {
// store the result of creating the grammars
createGrammarResult.setErrors(el.errors);
createGrammarResult.setWarnings(el.warnings);
el.clear();
ErrorManager.removeErrorListener();
}
}
Aggregations