org.problets.domain.template
Class TemplateParser

java.lang.Object
  extended by org.problets.domain.template.TemplateParser

public class TemplateParser
extends java.lang.Object

Provides static methods to parse a template

Author:
Amruth Kumar

Field Summary
static java.lang.String CODE_DELIMITER
           
 
Constructor Summary
TemplateParser()
           
 
Method Summary
static java.lang.String extractCondition(java.lang.String template)
          public string extractCondition(String template); Generate the condition of the switch statement
static java.lang.String extractScopeTemplate(java.lang.String template)
          public string extractScopeTemplate(String template); Generate the scope template of this control object
static int getIndexOfBalancingChar(java.lang.String template, int index)
          Get the index of the balancing closingChar corresponding to the openingChar
static int getIndexOfBalancingChar(java.lang.String template, int index, boolean handleHash)
           
static java.lang.String getNextActualToken(java.lang.String template, int index)
          The old version of getNextToken() worked as follows: Case 1: If the template started with <, it returned up to the matching > Case 2: If the template did not start with <, it returned up to the next < The problem was that in case 1, it returned '< ' and '<<' In case 2, it returned all sorts of operators and literal constants combined, such as '+ 1){' This version post-processes the result returned by the earlier version and returns the next token, whether it is <, <<, +, literal constants, (, ), {, }, ; etc.
static java.lang.String getNextStatement(java.lang.String masterTemplate, int start)
          Method to extract the next statement - returns the String corresponding to all characters up to and including the next semi-colon that is not part of a constraint.
static java.lang.String getNextToken(java.lang.String template)
           
static java.lang.String getNextToken(java.lang.String template, int index)
           
static int getOrdinality(java.lang.String token)
           
static int getScopeExtent(java.lang.String masterTemplate, char[] scopeTemplate, int index)
          // Method to extract a complete scope template OR a call to a scope object // from the masterTemplate // Returns the index past the scopeTemplate in the masterTemplate // Start from , Read argument list, // If ; follows argument list, read it - and return the function call // else, Read the body of the function and return the function definition
static void main(java.lang.String[] args)
           
static java.util.Vector parseTemplate(java.lang.String templateString)
          Converts the string template into a vector of statement strings, the statements being {, }, declaration, print, delete, while, iwhile, dowhile, idowhile, for, ifor, if, if-else, assignment and introduces filler statements <...>
static java.lang.String[] split(java.lang.String template)
          Returns an array of tokens in the template.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CODE_DELIMITER

public static final java.lang.String CODE_DELIMITER
See Also:
Constant Field Values
Constructor Detail

TemplateParser

public TemplateParser()
Method Detail

getOrdinality

public static int getOrdinality(java.lang.String token)

getNextToken

public static java.lang.String getNextToken(java.lang.String template)

getNextToken

public static java.lang.String getNextToken(java.lang.String template,
                                            int index)

getNextActualToken

public static java.lang.String getNextActualToken(java.lang.String template,
                                                  int index)
The old version of getNextToken() worked as follows: Case 1: If the template started with <, it returned up to the matching > Case 2: If the template did not start with <, it returned up to the next < The problem was that in case 1, it returned '< ' and '<<' In case 2, it returned all sorts of operators and literal constants combined, such as '+ 1){' This version post-processes the result returned by the earlier version and returns the next token, whether it is <, <<, +, literal constants, (, ), {, }, ; etc. Since most of the code uses the earlier version, it is kept for backward compatibility but it is advisable to use this version in the future


split

public static java.lang.String[] split(java.lang.String template)
Returns an array of tokens in the template. The tokens are not perfect: '< ', '+ 1){' are all marked tokens


getNextStatement

public static java.lang.String getNextStatement(java.lang.String masterTemplate,
                                                int start)
Method to extract the next statement - returns the String corresponding to all characters up to and including the next semi-colon that is not part of a constraint. To find the new value of index, just add the length of the string to its current value


getIndexOfBalancingChar

public static int getIndexOfBalancingChar(java.lang.String template,
                                          int index)
Get the index of the balancing closingChar corresponding to the openingChar


getIndexOfBalancingChar

public static int getIndexOfBalancingChar(java.lang.String template,
                                          int index,
                                          boolean handleHash)

parseTemplate

public static java.util.Vector parseTemplate(java.lang.String templateString)
Converts the string template into a vector of statement strings, the statements being {, }, declaration, print, delete, while, iwhile, dowhile, idowhile, for, ifor, if, if-else, assignment and introduces filler statements <...>


getScopeExtent

public static int getScopeExtent(java.lang.String masterTemplate,
                                 char[] scopeTemplate,
                                 int index)
// Method to extract a complete scope template OR a call to a scope object // from the masterTemplate // Returns the index past the scopeTemplate in the masterTemplate // Start from , Read argument list, // If ; follows argument list, read it - and return the function call // else, Read the body of the function and return the function definition


extractCondition

public static java.lang.String extractCondition(java.lang.String template)
public string extractCondition(String template); Generate the condition of the switch statement

Parameters:
template - - the template currently in use
Returns:
- the condition as a string NOTE: will eventually want all control objects deriving from this same function....will want to place in ControlModel BUT, does not handle simple statement bodies for loops

extractScopeTemplate

public static java.lang.String extractScopeTemplate(java.lang.String template)
public string extractScopeTemplate(String template); Generate the scope template of this control object

Parameters:
template - - the template currently in use
Returns:
- the sub-template insdie the scope braces, inclusive

main

public static void main(java.lang.String[] args)