|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.hdcookbook.grin.io.text.ShowParser
public class ShowParser
The parser of a show file. This is a really simple-minded parser. For example, all tokens are just strings, so, for example, you have to write "( 0 3 )" and not "(0 3)", since the first has four tokens and the second only two.
Field Summary | |
---|---|
static Command[] |
emptyCommandArray
A useful constant for parsing: An empty command array |
Constructor Summary | |
---|---|
ShowParser(java.io.Reader reader,
java.lang.String showName,
SEShow show)
Create a parser to parse a show at the given location. |
|
ShowParser(java.io.Reader reader,
java.lang.String showName,
SEShow show,
ShowBuilder builder)
Create a parser to parse a show at the given location. |
Method Summary | |
---|---|
void |
addForwardReference(ForwardReference fw,
int rank)
Adds a forward reference to a show feature. |
Assembly |
lookupAssemblyOrFail(java.lang.String name)
Look up a named assembly. |
Feature[] |
lookupAssemblyParts(Assembly assembly,
java.lang.String[] parts)
Look up the parts of an assembly. |
Feature |
lookupFeatureOrFail(java.lang.String name)
Look up a named feature. |
void |
parse()
Parse the current show file. |
boolean |
parseBoolean()
Parse a boolean value |
java.awt.Color |
parseColor()
Parse a color representation ("{ r g b a }") |
java.awt.Color |
parseColorNoOpenBrace()
Parse a color representation when the opening brace has already been read. |
Command[] |
parseCommands()
Parse a list of commands |
Command[] |
parseCommandsNoOpenBrace()
Parse a list of commands after the leading "{" has already been read |
void |
parseExpected(java.lang.String expected)
Parses a token that we expect to see. |
java.lang.String[][] |
parseMatrix()
Parse a 2-D matrix of strings. |
static SEShow |
parseShow(java.lang.String showName,
Director director,
ShowBuilder builder)
A utility method to convert text-based grin file to an SEShow object. |
static SEShow |
parseShowNoAbort(java.lang.String showName,
Director director,
ShowBuilder builder)
A utility method to convert text-based grin file to an SEShow object. |
java.lang.String[] |
parseStrings()
Parse a list of strings |
java.lang.String[] |
parseStringsWithOpenBraceRead()
Parse a list of strings, without reading the leading open-brace. |
void |
readJavaSource(java.lang.StringBuffer xletSource,
java.lang.StringBuffer grinviewSource,
java.lang.StringBuffer originalSource,
SEShowCommand command)
Read a java_source fragment. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Command[] emptyCommandArray
Constructor Detail |
---|
public ShowParser(java.io.Reader reader, java.lang.String showName, SEShow show)
reader
- Where to read the show from. We read it up to the
end_show token. It is recommended to be a
BufferedReader instance for a performance improvement.showName
- The name of the show, for error messages.show
- The show to populate. This should be a new, empty
show.public ShowParser(java.io.Reader reader, java.lang.String showName, SEShow show, ShowBuilder builder)
reader
- Where to read the show from. We read it up to the
end_show token. It is recommended to be a BufferedReader
instance for a performance improvement.showName
- The name of the show, for error messages.show
- The show to populate. This should be a new, empty
show.builder
- A helper to build the tree. You can use something
other than the default to add decorations to the
tree, e.g. for debugging.Method Detail |
---|
public void addForwardReference(ForwardReference fw, int rank)
Lexer lexer = ...; final ShowParser parser = lexer.getParser(); final MyFeature feature = ...; final String otherFeatureName = ...; ForwardReference fw = new ForwardReference(lexer) { public void resolve() throws IOException { Feature f = parser.lookupFeatureOrFail(otherFeatureName); feature.setOtherFeature(f); } }; parser.addForwardReference(fw, 0);The GRIN parser guarantees that all of its forward reference resolution will be copleted before the first forward reference added by this method. For example, all groups and assemblies will be completely populated before any of your forward references are.
Within your forward references, you might need to make sure that some of them are resolved before others. Within GRIN, and example of this is the visual RC handler, which depends on the assembly it's bound to being completely resolved before the RC handler's references are resolved. If you need to impose an ordering on the resolution order of different kinds of forward references, use the rank parameter.
fw
- The forward reference to addrank
- The rank order. Higher numbered forward references
are processed after lower numbered ones. Internally,
the parser uses this as an array index. Must be >= 0.public void parse() throws java.io.IOException
java.io.IOException
public Command[] parseCommands() throws java.io.IOException
java.io.IOException
public Command[] parseCommandsNoOpenBrace() throws java.io.IOException
java.io.IOException
public Feature[] lookupAssemblyParts(Assembly assembly, java.lang.String[] parts) throws java.io.IOException
java.io.IOException
ForwardReference
public Feature lookupFeatureOrFail(java.lang.String name) throws java.io.IOException
java.io.IOException
ForwardReference
public Assembly lookupAssemblyOrFail(java.lang.String name) throws java.io.IOException
java.io.IOException
ForwardReference
public java.lang.String[][] parseMatrix() throws java.io.IOException
java.io.IOException
public java.lang.String[] parseStrings() throws java.io.IOException
java.io.IOException
public java.lang.String[] parseStringsWithOpenBraceRead() throws java.io.IOException
java.io.IOException
public boolean parseBoolean() throws java.io.IOException
java.io.IOException
public java.awt.Color parseColor() throws java.io.IOException
java.io.IOException
public java.awt.Color parseColorNoOpenBrace() throws java.io.IOException
java.io.IOException
parseColor()
public void parseExpected(java.lang.String expected) throws java.io.IOException
java.io.IOException
public void readJavaSource(java.lang.StringBuffer xletSource, java.lang.StringBuffer grinviewSource, java.lang.StringBuffer originalSource, SEShowCommand command) throws java.io.IOException
java.io.IOException
public static SEShow parseShow(java.lang.String showName, Director director, ShowBuilder builder)
On a parse error, this prints an error message to stderr, then aborts execution. If you want the IOException yourself, then call parseShowNoAbort().
showName
- The name of the show text file to parse.director
- The director to use for the recreated show,
could be null.builder
- The show builder object with the extension parser
being set, could be null.
parseShowNoAbort(String, Director, ShowBuilder)
public static SEShow parseShowNoAbort(java.lang.String showName, Director director, ShowBuilder builder) throws java.io.IOException
On a parse error, this throws an IO Exception, and doesn't print anything to stderr. If you want a more friendly error message, try parseShow().
showName
- The name of the show text file to parse.director
- The director to use for the recreated show,
could be null.builder
- The show builder object with the extension parser
being set, could be null.
java.io.IOException
parseShow(String, Director, ShowBuilder)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |