-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split LexGenerator out of Main #428
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
afe31a8
Split Main in Main and LexGenerator.
regisd 939d6c6
Make Main non instanciable.
regisd f37dc62
Adapt code to refactoring.
regisd 5d63d4e
Update javadoc
regisd 5d7ae8c
Remove hack to fetch cup.jar in the ant build.
regisd 84a4c63
Revert "Remove hack to fetch cup.jar in the ant build."
regisd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
* JFlex 1.7.1-SNAPSHOT * | ||
* Copyright (C) 1998-2018 Gerwin Klein <[email protected]> * | ||
* All rights reserved. * | ||
* * | ||
* License: BSD * | ||
* * | ||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
|
||
package jflex; | ||
|
||
import static jflex.Options.encoding; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* This is the main class of JFlex controlling the scanner generation process. It is responsible for | ||
* parsing the commandline, getting input files, starting up the GUI if necessary, etc. | ||
* | ||
* @author Gerwin Klein | ||
* @author Régis Décamps | ||
* @version JFlex 1.7.1-SNAPSHOT | ||
*/ | ||
public class LexGenerator { | ||
|
||
/** JFlex version */ | ||
public static final String VERSION = "1.7.1-SNAPSHOT"; // $NON-NLS-1$ | ||
|
||
/** | ||
* Generates a scanner for the specified input file. | ||
* | ||
* @param inputFile a file containing a lexical specification to generate a scanner for. | ||
*/ | ||
public static void generate(File inputFile) { | ||
|
||
Out.resetCounters(); | ||
|
||
Timer totalTime = new Timer(); | ||
Timer time = new Timer(); | ||
|
||
LexScan scanner = null; | ||
LexParse parser = null; | ||
Reader inputReader = null; | ||
|
||
totalTime.start(); | ||
|
||
try { | ||
Out.println(ErrorMessages.READING, inputFile.toString()); | ||
inputReader = | ||
new InputStreamReader(Files.newInputStream(Paths.get(inputFile.toString())), encoding); | ||
scanner = new LexScan(inputReader); | ||
scanner.setFile(inputFile); | ||
parser = new LexParse(scanner); | ||
} catch (IOException e) { | ||
Out.error(ErrorMessages.CANNOT_OPEN, inputFile.toString()); | ||
throw new GeneratorException(); | ||
} | ||
|
||
try { | ||
NFA nfa = (NFA) parser.parse().value; | ||
|
||
Out.checkErrors(); | ||
|
||
if (Options.dump) Out.dump(ErrorMessages.get(ErrorMessages.NFA_IS) + Out.NL + nfa + Out.NL); | ||
|
||
if (Options.dot) nfa.writeDot(Emitter.normalize("nfa.dot", null)); // $NON-NLS-1$ | ||
|
||
Out.println(ErrorMessages.NFA_STATES, nfa.numStates); | ||
|
||
time.start(); | ||
DFA dfa = nfa.getDFA(); | ||
time.stop(); | ||
Out.time(ErrorMessages.DFA_TOOK, time); | ||
|
||
dfa.checkActions(scanner, parser); | ||
|
||
nfa = null; | ||
|
||
if (Options.dump) Out.dump(ErrorMessages.get(ErrorMessages.DFA_IS) + Out.NL + dfa + Out.NL); | ||
|
||
if (Options.dot) dfa.writeDot(Emitter.normalize("dfa-big.dot", null)); // $NON-NLS-1$ | ||
|
||
Out.checkErrors(); | ||
|
||
time.start(); | ||
dfa.minimize(); | ||
time.stop(); | ||
|
||
Out.time(ErrorMessages.MIN_TOOK, time); | ||
|
||
if (Options.dump) Out.dump(ErrorMessages.get(ErrorMessages.MIN_DFA_IS) + Out.NL + dfa); | ||
|
||
if (Options.dot) dfa.writeDot(Emitter.normalize("dfa-min.dot", null)); // $NON-NLS-1$ | ||
|
||
time.start(); | ||
|
||
Emitter e = new Emitter(inputFile, parser, dfa); | ||
e.emit(); | ||
|
||
time.stop(); | ||
|
||
Out.time(ErrorMessages.WRITE_TOOK, time); | ||
|
||
totalTime.stop(); | ||
|
||
Out.time(ErrorMessages.TOTAL_TIME, totalTime); | ||
} catch (ScannerException e) { | ||
Out.error(e.file, e.message, e.line, e.column); | ||
throw new GeneratorException(); | ||
} catch (MacroException e) { | ||
Out.error(e.getMessage()); | ||
throw new GeneratorException(); | ||
} catch (IOException e) { | ||
Out.error(ErrorMessages.IO_ERROR, e.toString()); | ||
throw new GeneratorException(); | ||
} catch (OutOfMemoryError e) { | ||
Out.error(ErrorMessages.OUT_OF_MEMORY); | ||
throw new GeneratorException(); | ||
} catch (GeneratorException e) { | ||
throw new GeneratorException(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw new GeneratorException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment will need adjustment for the refactor, indicating which part is in which class in the new setting.