org.peaseplate.internal.lang
Class Parser

java.lang.Object
  extended by org.peaseplate.internal.lang.Parser

public class Parser
extends java.lang.Object

The default parser for the referece language. Default Reference = Command Key = KeyIdentifier | String Identifier = Identifier Command = ("(" Command ")" ) | (Expression {AnyOperator Command} ["?" Command ":" Command] TransformerChain) Expression = [UnaryOperator] (Invocation | Query | Variable | Number | String | "true" | "false" | "null" | "$this" | "$pop") {ExpressionChain} ExpressionChain = Query | ("." ("$pop" | Invocation)) Invocation = Identifier ParameterList Query = "[" Command "]" ParameterList ParameterList = ["(" {Command {"," Command}} ")"] VariableList = ["(" {Variable {"," Variable}} ")"] IdentifierList = ["(" {Identifier {"," Identifier}} ")"] TransformerChain = {"->" Identifier ["." Identifier] ParameterList} IdentifierExtension = ["." Identifier] AnyOperator = MultiplicativeOperator | AdditiveOperator | ShiftOperator | RelationalOperator | EqualityOperator | BitwiseOperator | ConditionalAndOperator | ConditionalOrOperator UnaryOperator = "+" | "-" | "~" | "!" MultiplicativeOperator = "*" | "/" | "%" AdditiveOperator = "+" | "-" ShiftOperator = "<<" | ">>" | ">>>" RelationalOperator = "<" | "<=" | ">" | ">=" EqualityOperator = "==" | "!=" BitwiseOperator = "&" | "^" | "|" ConditionalAndOperator = "&&" ConditionalOrOperator = "||" Identifier = (LETTER | "_") {LETTER | DIGIT | "_"} Variable = '$' (LETTER | DIGIT | "_") {LETTER | DIGIT | "_"} KeyIdentifier = (LETTER | DIGIT | "_" | "-" | "." | "/") {LETTER | DIGIT | "_" | "-" | "." | "/"} AnyIdentifier = ANY_EXCEPT_SPACE Number = (DecimalNumber | RealNumber | HexNumber | OctalNumber) DecimalNumber = DIGIT_EXCEPT_ZERO {DIGIT} RealNumber = {DIGIT} ["." DIGIT {DIGIT}] [("e" | "E") ["-" | "+"] DIGIT {DIGIT}] ["d" | "D" | "f" | "F"] HexNumber = ("#" | "0x") DIGIT {DIGIT} OctalNumber = "0" {DIGIT} String = "\"" {ANY_EXCEPT_QUOTES} "\"" Boolean = "true" | "false" Keyword = "pop" | "this" Null = "null"


Constructor Summary
Parser(TemplateEngine engine, CompileContext context, int line, int column, char[] code, int offset, int length)
           
 
Method Summary
protected  ICommand createDoubleParameterCommand(Tokenizer.Type operator, java.lang.Object value, int line, int column, ICommand left, ICommand right)
           
protected  ICommand createSingleParameterCommand(Tokenizer.Type operator, java.lang.Object value, int line, int column, ICommand command)
           
 CompileContext getContext()
           
 TemplateEngine getEngine()
           
 Tokenizer getTokenizer()
           
protected  boolean isAnyOperator()
           
protected  boolean isAnyOperator(Tokenizer.Type type)
           
protected  boolean isExpression()
           
protected  boolean isExpressionChain()
           
protected  boolean isInvocation()
           
 java.lang.String parseAssignedKey()
           
protected  ICommand parseCommand(Tokenizer.Type operator, int parenthesisCount)
          Parses the command notation Command = ("(" Command ")" ) | (Expression {AnyOperator Command} ["?"
protected  ICommand parseExpression()
          Parses the expression.
protected  ICommand parseExpressionChain(ICommand command)
           
 java.lang.String parseIdentifierExtension()
          Parses the code as identifier extension.
 java.lang.String[] parseIdentifierList()
          Parses the code as identifier list.
protected  ICommand parseInvocation(ICommand command)
           
 ICommand[] parseParameterList()
          Parses the code as parameter list.
protected  ICommand parseQuery(ICommand command)
           
protected  ICommand parseSubExpression()
           
 ICommand parseTransformerChain(ICommand command)
          Parses the transformer notation.
 java.lang.String[] parseVariableList()
          Parses the code as variable list.
 ICommand readDefaultReference()
          Parses the code as default reference.
 java.lang.String readIdentifier()
          Parses the code as a single identifier.
 java.lang.String readKey()
          Parses the code as key token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parser

public Parser(TemplateEngine engine,
              CompileContext context,
              int line,
              int column,
              char[] code,
              int offset,
              int length)
Method Detail

getEngine

public TemplateEngine getEngine()

getContext

public CompileContext getContext()

getTokenizer

public Tokenizer getTokenizer()

readDefaultReference

public ICommand readDefaultReference()
                              throws TemplateException
Parses the code as default reference. Expects that the cursor is located before the first token. Default Reference = Command

Returns:
the command
Throws:
TemplateException - on occasion

readKey

public java.lang.String readKey()
                         throws TemplateException
Parses the code as key token. Expects that the cursor is located before the first token which must be a key or string

Returns:
the key
Throws:
TemplateException - on occasion

readIdentifier

public java.lang.String readIdentifier()
                                throws TemplateException
Parses the code as a single identifier. Expects that the cursor is located before the first token with must be an identifier

Returns:
the identifier
Throws:
TemplateException - on occasion

parseCommand

protected ICommand parseCommand(Tokenizer.Type operator,
                                int parenthesisCount)
                         throws TemplateException
Parses the command notation Command = ("(" Command ")" ) | (Expression {AnyOperator Command} ["?" Command ":" Command] {"->" Transformer})

Parameters:
operator - the operator just prior to the current token
parenthesisCount - the count of parentheses
Returns:
the command
Throws:
TemplateException - on occasion

isAnyOperator

protected boolean isAnyOperator()
                         throws TemplateException
Throws:
TemplateException

isExpression

protected boolean isExpression()

parseExpression

protected ICommand parseExpression()
                            throws TemplateException
Parses the expression. Exprects that the cursor is on the first token. Expression = [UnaryOperator] (Invocation | Query | Variable | Number | String | "true" | "false" | "null" | "$this" | "$pop") {ExpressionChain}

Returns:
the expression
Throws:
TemplateException - on occasion

parseSubExpression

protected ICommand parseSubExpression()
                               throws TemplateException
Throws:
TemplateException

isExpressionChain

protected boolean isExpressionChain()

parseExpressionChain

protected ICommand parseExpressionChain(ICommand command)
                                 throws TemplateException
Throws:
TemplateException

isInvocation

protected boolean isInvocation()

parseInvocation

protected ICommand parseInvocation(ICommand command)
                            throws TemplateException
Throws:
TemplateException

parseQuery

protected ICommand parseQuery(ICommand command)
                       throws TemplateException
Throws:
TemplateException

parseParameterList

public ICommand[] parseParameterList()
                              throws TemplateException
Parses the code as parameter list. Expects that the cursor is on the opening parentheses of the list. If this is not the case (no parameter list specified) then this method returns null. ParameterList = ["(" {Command {"," Command}} ")"]

Returns:
the commands of the paramters or null
Throws:
TemplateException - on occasion

parseVariableList

public java.lang.String[] parseVariableList()
                                     throws TemplateException
Parses the code as variable list. Expects that the cursor is on the opening parentheses of the list. If this is not the case (no parameter list specified) then this method returns null. VariableList = ["(" {Variable {"," Variable}} ")"]

Returns:
the variables or null
Throws:
TemplateException - on occasion

parseIdentifierList

public java.lang.String[] parseIdentifierList()
                                       throws TemplateException
Parses the code as identifier list. Expects that the cursor is on the opening parentheses of the list. If this is not the case (no identifier list specified) then this method returns null. IdentifierList = ["(" {Identifier {"," Identifier}} ")"]

Returns:
the identifiers or null
Throws:
TemplateException - on occasion

parseIdentifierExtension

public java.lang.String parseIdentifierExtension()
                                          throws TemplateException
Parses the code as identifier extension. Expects that the cursor is on the first token. If there is no extension, the method returns null. IdentifierExtension = ["." Identifier]

Returns:
the extension or null
Throws:
TemplateException

createSingleParameterCommand

protected ICommand createSingleParameterCommand(Tokenizer.Type operator,
                                                java.lang.Object value,
                                                int line,
                                                int column,
                                                ICommand command)
                                         throws TemplateException
Throws:
TemplateException

createDoubleParameterCommand

protected ICommand createDoubleParameterCommand(Tokenizer.Type operator,
                                                java.lang.Object value,
                                                int line,
                                                int column,
                                                ICommand left,
                                                ICommand right)
                                         throws TemplateException
Throws:
TemplateException

parseTransformerChain

public ICommand parseTransformerChain(ICommand command)
                               throws TemplateException
Parses the transformer notation. Expects that the cursor is on the transformer symbol (->). If there is no such symbol, it assumes that there is no transformer appended and returns the command itself. TransformerChain = {"->" Identifier ["." Identifier] ParameterList}

Parameters:
command - the command to be sent to the transformer
Returns:
the command itself or wrapped by a transformer
Throws:
TemplateException - on occasion

parseAssignedKey

public java.lang.String parseAssignedKey()
                                  throws TemplateException
Throws:
TemplateException

isAnyOperator

protected boolean isAnyOperator(Tokenizer.Type type)


Copyright © 2008. All Rights Reserved.