org.pz.platypus
Class PlatypusParser

java.lang.Object
  extended by org.pz.platypus.PlatypusParser

public class PlatypusParser
extends java.lang.Object

The primary parser for Platypus files. It parses input into core elements: - text - commands and macros - comments, both line and block format


Field Summary
private  java.lang.String blockCommentClosingSymbol
          the symbol we need to match for the close of a block of
private  CommandTable ctable
          the ComandTable that holds all the commands that Platypus supports
private  GDD gdd
           
private  boolean inCode
          are we in code? If so, this changes how we isLineComment text.
 
Constructor Summary
PlatypusParser(GDD Gdd)
           
 
Method Summary
 void addToken(TokenList tokens, TokenType tokType, java.lang.String content, Source source)
          Adds a parsed token to the ArrayList of tokens
private  boolean blockClosesOnSameLine(ParseContext context, java.lang.String blockCommentClosingSymbol)
           
static boolean doesPlatypusParse(PropertyFile configFile, java.lang.String pluginPrefix)
          Do we do the parsing, or will the output plugin do the parsing? Check the config file for what the plug-in specifies.
(package private)  void emitEolToken(TokenList newTokens, Source source)
          Emits the so-called "soft" EOL command used when at end of line.
 java.lang.String extractCommandRoot(ParseContext context)
          Extracts the root of a command.
private  int handleClosingBlockComment(TokenList newTokens, ParseContext context, int closeCommentStart)
          Write the closed block comment to the token list and return the amount by which the isLineComment point needs to be moved up to get past the block comment.
(package private)  void invalidCommandError(ParseContext context, TokenList tokens, java.lang.String commandRoot)
          Write an error message to console saying that the command-like token is not actually a Platypus command, and then write the token out to the output as a text token.
 boolean isInCode()
           
 int noParse(LineList lines, TokenList tokens)
          Some output plugins want to parse the input text themselves.
private  int outputMacroAsToken(ParseContext context, TokenList tokens, MacroParser mp)
          Outputs the macro to the TokenList without expanding it.
 int parse(LineList lines, TokenList tokens, PropertyFile configFile, java.lang.String pluginPrefix)
          Converts input lines into an ArrayList of parsed tokens.
 int parseLine(TokenList newTokens, InputLine line)
          Parse a line of the input file
 int parseSegment(ParseContext context, TokenList tokens)
          The primary line-parsing routine.
(package private)  boolean passThroughEscapeChar()
          Check the config file to see whether we pass through the escape char to the output token stream.
 int processBlockComment(ParseContext context, TokenList tokens)
          Processes block comments.
 int processCommand(ParseContext context, TokenList tokens)
          Just grabs the command and writes it to the token list
 int processMacro(ParseContext context, TokenList tokens)
          If the config file for this output format says that Platypus expands macros, this routine looks up the macro, expands it, and puts the expanded form in gdd.expandedMacro.
 void setInCode(boolean inCodeYesOrNo)
           
 int writeOutText(int start, int end, char[] text, TokenList tokensOut, Source source)
          Write out a set of text characters to the token list as a text token
private  void writeOutText(ParseContext context, int endPoint, TokenList tokens)
          Write out text Token to the token list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inCode

private boolean inCode
are we in code? If so, this changes how we isLineComment text.


blockCommentClosingSymbol

private java.lang.String blockCommentClosingSymbol
the symbol we need to match for the close of a block of


ctable

private CommandTable ctable
the ComandTable that holds all the commands that Platypus supports


gdd

private GDD gdd
Constructor Detail

PlatypusParser

public PlatypusParser(GDD Gdd)
Method Detail

parse

public int parse(LineList lines,
                 TokenList tokens,
                 PropertyFile configFile,
                 java.lang.String pluginPrefix)
Converts input lines into an ArrayList of parsed tokens.

Parameters:
lines - the input lines
tokens - the resulting tokens
configFile - the configuration file might have info on how to handle some features
pluginPrefix - the prefix to look up output items with in the config file
Returns:
Status.OK if all went well, otherwise an error code.

parseLine

public int parseLine(TokenList newTokens,
                     InputLine line)
Parse a line of the input file

Parameters:
line - line to be parsed
newTokens - the TokenList to which we're adding tokens
Returns:
Status.OK or Status.UNFIXABLE_PARSE_ERR, which is a serious, stop-the-Platypus error

emitEolToken

void emitEolToken(TokenList newTokens,
                  Source source)
Emits the so-called "soft" EOL command used when at end of line.

Parameters:
newTokens - token list to add the token to
source - file# and line# of token

handleClosingBlockComment

private int handleClosingBlockComment(TokenList newTokens,
                                      ParseContext context,
                                      int closeCommentStart)
Write the closed block comment to the token list and return the amount by which the isLineComment point needs to be moved up to get past the block comment.

Parameters:
newTokens - what we write the tokens to
context - the parsing context info
closeCommentStart - where the beginning of the close to the block comment is
Returns:
number of chars to move forward to get past the closing of the block comment

parseSegment

public int parseSegment(ParseContext context,
                        TokenList tokens)
The primary line-parsing routine. It finds one segment (text, a command, a comment block) parses it, adds it to tokens, and returns after moving parsePoint to the first character of the next segment. This method is called repeatedly by parseLine() until parsePoint points to the '\n' that ends the input line. Note: assumes that all segments end with a \n

Parameters:
context - the source context data
tokens - the sequence of tokens to which we'll add the parsed segment.
Returns:
the new isLineComment point or, if an error that can't be fixed in the parser occurs, returns Status.UNFIXABLE_PARSE_ERR

passThroughEscapeChar

boolean passThroughEscapeChar()
Check the config file to see whether we pass through the escape char to the output token stream. The default is no. So, in the event it's not specified, we return false.

Returns:
false if we don't pass it through (the general case), true if we do.

writeOutText

private void writeOutText(ParseContext context,
                          int endPoint,
                          TokenList tokens)
Write out text Token to the token list

Parameters:
context - where the text string is
endPoint - the end of the text (starts at context.startPoint)
tokens - the token list to write the token to.

processBlockComment

public int processBlockComment(ParseContext context,
                               TokenList tokens)
Processes block comments. It identifies the starting marker, computes the ending marker, and verifies checks whether the closing marker is on the same line. If so, it handles the block comment. Otherwise, it stores the closing marker in blockCommentClosingSymbol.

Parameters:
tokens - the token list to add the block-comment token to
context - the parser context/location info.
Returns:
the new isLineComment point //TODO: put this in a block-comment parser?

blockClosesOnSameLine

private boolean blockClosesOnSameLine(ParseContext context,
                                      java.lang.String blockCommentClosingSymbol)

processCommand

public int processCommand(ParseContext context,
                          TokenList tokens)
Just grabs the command and writes it to the token list

Parameters:
context - parse context: sourcefile# & line#, parsePoint, line as string, line as char[]
tokens - token list to which we will add the tokens derived from the command
Returns:
the updated version of the isLineComment point.

invalidCommandError

void invalidCommandError(ParseContext context,
                         TokenList tokens,
                         java.lang.String commandRoot)
Write an error message to console saying that the command-like token is not actually a Platypus command, and then write the token out to the output as a text token.

Parameters:
context - the parser context
tokens - list of tokens to which this token will be added
commandRoot - the root of the command, were it a real command.

extractCommandRoot

public java.lang.String extractCommandRoot(ParseContext context)
                                    throws java.lang.IndexOutOfBoundsException
Extracts the root of a command. The root is the part that at the beginning of the command that remains the same regardless of parameters. To wit: - commands with no parameters, it's the whole command: [+i] - commands with 1 parameter, it's everything up to the ':' fsize: in [fsize:12pt] - commands with 2+ parameters, it's the family name, so [font| in [font|size:12pt|face:...

Parameters:
context - the parsing location info.
Returns:
the command root as a string
Throws:
java.lang.IndexOutOfBoundsException - for unclosed command

processMacro

public int processMacro(ParseContext context,
                        TokenList tokens)
If the config file for this output format says that Platypus expands macros, this routine looks up the macro, expands it, and puts the expanded form in gdd.expandedMacro. If the config file says not to process macros, the macro is simply written out to the token stream.

Parameters:
tokens - list of tokens we're building up in parser. (Used only if macros not processed)
context - the parsing context info
Returns:
the new isLineComment point after the macro, or Status.UNFIXABLE_PARSE_ERR if an error occurs

outputMacroAsToken

private int outputMacroAsToken(ParseContext context,
                               TokenList tokens,
                               MacroParser mp)
Outputs the macro to the TokenList without expanding it.

Parameters:
context - the parsing context data
tokens - the TokenList to which the token is written
mp - the macro parser class
Returns:
number of chars to skip

writeOutText

public int writeOutText(int start,
                        int end,
                        char[] text,
                        TokenList tokensOut,
                        Source source)
Write out a set of text characters to the token list as a text token

Parameters:
start - subscript of first char in text
end - subscript of last char in text
text - array of chars containing the line from which the text is extracted
tokensOut - the list of tokens to which the text token will be added
source - the file# and line#
Returns:
right now, always Status.OK. If this doesn't change, might change to void.

doesPlatypusParse

public static boolean doesPlatypusParse(PropertyFile configFile,
                                        java.lang.String pluginPrefix)
Do we do the parsing, or will the output plugin do the parsing? Check the config file for what the plug-in specifies. If there is no entry, the default is that we isLineComment.

Parameters:
configFile - the configuration file
pluginPrefix - the prefix for this output plugin
Returns:
true if we isLineComment, false if the plugin does the parsing.

addToken

public void addToken(TokenList tokens,
                     TokenType tokType,
                     java.lang.String content,
                     Source source)
Adds a parsed token to the ArrayList of tokens

Parameters:
tokens - the ArrayList of tokens to add to
tokType - the type of token we're adding (an enum in Platypus.TokenType)
content - the user entered text that's been parsed into a token
source - the file# and line# in the input file where the token was found

noParse

public int noParse(LineList lines,
                   TokenList tokens)
Some output plugins want to parse the input text themselves. (This would occur, for example, if an output plugin adds proprietary commands to the Platypus commands.) In this case, it is passed tokens that consist only of the unparsed lines.

Parameters:
lines - ArrayList of input lines
tokens - ArrayList of output tokens (consisting of the unparsed lines)
Returns:
Status.OK, if all went well; otherwise, an error code.

isInCode

public boolean isInCode()

setInCode

public void setInCode(boolean inCodeYesOrNo)


Copyright © 2008-10 Pacific Data Works LLC