Package org.codehaus.mojo.javacc
Class GrammarInfo
java.lang.Object
org.codehaus.mojo.javacc.GrammarInfo
This bean holds some output related information about a JavaCC grammar file. It assists in determining the exact
output location for the generated parser file.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
The path to the grammar file (relative to its source directory, e.g.private final String
The path to the directory of the parser package (relative to a source root directory, e.g.private final String
The path to the generated parser file (relative to a source root directory, e.g.private final String
The simple name of the generated parser (e.g.private final String
The declared package for the generated parser (e.g.private final File
The absolute path to the base directory in which the grammar file resides. -
Constructor Summary
ConstructorsConstructorDescriptionGrammarInfo
(File sourceDir, String inputFile) Creates a new info from the specified grammar file.GrammarInfo
(File sourceDir, String inputFile, String packageName) Creates a new info from the specified grammar file. -
Method Summary
Modifier and TypeMethodDescriptionprivate String
findPackageName
(String grammar) Extracts the declared package name from the specified grammar file.private String
findParserName
(String grammar) Extracts the simple parser name from the specified grammar file.Gets the absolute path to the grammar file.Gets the path to the directory of the parser package (relative to a source root directory, e.g.Gets the path to the parser file (relative to a source root directory, e.g.Gets the simple name of the generated parser (e.g.Gets the declared package for the generated parser (e.g.Gets the path to the grammar file (relative to its source directory).Gets the absolute path to the base directory in which the grammar file resides.resolvePackageName
(String packageName) Resolves the specified package name against the package name of the parser generated from this grammar.toString()
Gets a string representation of this bean.
-
Field Details
-
sourceDirectory
The absolute path to the base directory in which the grammar file resides. -
grammarFile
The path to the grammar file (relative to its source directory, e.g. "grammars/MyParser.jj"). -
parserPackage
The declared package for the generated parser (e.g. "org.apache"). -
parserDirectory
The path to the directory of the parser package (relative to a source root directory, e.g. "org/apache"). -
parserName
The simple name of the generated parser (e.g. "MyParser"). -
parserFile
The path to the generated parser file (relative to a source root directory, e.g. "org/apache/MyParser.java").
-
-
Constructor Details
-
GrammarInfo
Creates a new info from the specified grammar file.- Parameters:
sourceDir
- The absolute path to the base directory in which the grammar file resides, must not benull
.inputFile
- The path to the grammar file (relative to the source directory), must not benull
.- Throws:
IOException
- If reading the grammar file failed.
-
GrammarInfo
Creates a new info from the specified grammar file.- Parameters:
sourceDir
- The absolute path to the base directory in which the grammar file resides, must not benull
.inputFile
- The path to the grammar file (relative to the source directory), must not benull
.packageName
- The package name for the generated parser, may benull
to use the package declaration from the grammar file.- Throws:
IOException
- If reading the grammar file failed.
-
-
Method Details
-
findPackageName
Extracts the declared package name from the specified grammar file.- Parameters:
grammar
- The contents of the grammar file, must not benull
.- Returns:
- The declared package name or an empty string if not found.
-
findParserName
Extracts the simple parser name from the specified grammar file.- Parameters:
grammar
- The contents of the grammar file, must not benull
.- Returns:
- The parser name or an empty string if not found.
-
getSourceDirectory
Gets the absolute path to the base directory in which the grammar file resides. Note that this is not necessarily the parent directory of the grammar file.- Returns:
- The absolute path to the base directory in which the grammar file resides, never
null
.
-
getGrammarFile
Gets the absolute path to the grammar file.- Returns:
- The absolute path to the grammar file, never
null
.
-
getRelativeGrammarFile
Gets the path to the grammar file (relative to its source directory).- Returns:
- The path to the grammar file (relative to its source directory), never
null
.
-
resolvePackageName
Resolves the specified package name against the package name of the parser generated from this grammar. To reference the parser package, the input string may use the prefix "*". For example, if the package for the parser is "org.apache" and the input string is "*.node", the resolved package is "org.apache.node". The period after the asterisk is significant, i.e. in the previous example the input string "*node" would resolve to "org.apachenode".- Parameters:
packageName
- The package name to resolve, may benull
.- Returns:
- The resolved package name or
null
if the input string wasnull
.
-
getParserPackage
Gets the declared package for the generated parser (e.g. "org.apache").- Returns:
- The declared package for the generated parser (e.g. "org.apache") or an empty string if no package
declaration was found, never
null
.
-
getParserDirectory
Gets the path to the directory of the parser package (relative to a source root directory, e.g. "org/apache").- Returns:
- The path to the directory of the parser package (relative to a source root directory, e.g. "org/apache")
or an empty string if no package declaration was found, never
null
.
-
getParserName
Gets the simple name of the generated parser (e.g. "MyParser")- Returns:
- The simple name of the generated parser (e.g. "MyParser"), never
null
.
-
getParserFile
Gets the path to the parser file (relative to a source root directory, e.g. "org/apache/MyParser.java").- Returns:
- The path to the parser file (relative to a source root directory, e.g. "org/apache/MyParser.java"), never
null
.
-
toString
Gets a string representation of this bean. This value is for debugging purposes only.
-