unsw.cse.framescript
Class Pattern

java.lang.Object
  extended by unsw.cse.framescript.Term
      extended by unsw.cse.framescript.Pattern

public class Pattern
extends Term

This class implements the Pattern type in FrameScript.

Author:
mmcgill

Constructor Summary
Pattern(Term t)
          Creates a pattern with one element.
Pattern(Term t, Pattern p)
          Creates a pattern where a term a placed at the head of another pattern.
 
Method Summary
 Pattern append(Pattern p)
          Appends a pattern to the end of a pattern.
 java.lang.String asString(int indentLevel, boolean inPattern)
          Turns the Term into a string.
 boolean equals(Term t)
          Compares two Terms for equality.
 Term eval(Instance currentObject, StackFrame frame)
          Evaluates a Term.
 boolean fullMatch(unsw.cse.framescript.InputPattern input, Instance current, StackFrame frame)
          Matches the Term to the current position in an input pattern.
 boolean isEmpty()
           
 Term mapVars(FSList vars)
          Maps atoms to variables from the list of variables.
 boolean match(unsw.cse.framescript.InputPattern input, Instance current, StackFrame frame)
          Matches the Term to the current position in an input pattern.
 java.lang.String toString()
          Turns the Term into a string.
 
Methods inherited from class unsw.cse.framescript.Term
assign, indents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pattern

public Pattern(Term t)
Creates a pattern with one element.

Parameters:
t - the only element in the pattern

Pattern

public Pattern(Term t,
               Pattern p)
Creates a pattern where a term a placed at the head of another pattern.

Parameters:
t - term to be placed at the head of the pattern
p - the pattern that follows the head
Method Detail

append

public Pattern append(Pattern p)
Appends a pattern to the end of a pattern.

Parameters:
p - pattern being appended to the end
Returns:
a pattern where this pattern is followed by p

eval

public Term eval(Instance currentObject,
                 StackFrame frame)
          throws FSException
Description copied from class: Term
Evaluates a Term. For many Terms the result is to return itself.

Specified by:
eval in class Term
Parameters:
currentObject - the enclosing instance frame for the code being evaluated
frame - StackFrame that holds the values for any variables
Returns:
the result of the evaluation
Throws:
FSException - if any errors occur in performing the evaluation

equals

public boolean equals(Term t)
Description copied from class: Term
Compares two Terms for equality.

Specified by:
equals in class Term
Parameters:
t - Term to be compared to
Returns:
true if the Terms are equal, false otherwise

mapVars

public Term mapVars(FSList vars)
             throws SyntaxError
Description copied from class: Term
Maps atoms to variables from the list of variables.

Overrides:
mapVars in class Term
Parameters:
vars - a list of variables to be mapped
Returns:
a clone of the Term where all the variables have been mapped
Throws:
SyntaxError - if in performing the mapping it finds an invalid variable name

match

public boolean match(unsw.cse.framescript.InputPattern input,
                     Instance current,
                     StackFrame frame)
              throws FSException
Description copied from class: Term
Matches the Term to the current position in an input pattern.

Overrides:
match in class Term
Parameters:
input - the input the Term is being matched against
current - the enclosing instance frame for the code being evaluated
frame - StackFrame that holds the values for any variables
Returns:
true if it matches else false
Throws:
FSException - if any errors occur during the match process

fullMatch

public boolean fullMatch(unsw.cse.framescript.InputPattern input,
                         Instance current,
                         StackFrame frame)
                  throws FSException
Description copied from class: Term
Matches the Term to the current position in an input pattern.

Overrides:
fullMatch in class Term
Parameters:
input - the input the Term is being matched against
current - the enclosing instance frame for the code being evaluated
frame - StackFrame that holds the values for any variables
Returns:
true if it matches else false
Throws:
FSException - if any errors occur during the match process

toString

public java.lang.String toString()
Description copied from class: Term
Turns the Term into a string.

Specified by:
toString in class Term

asString

public java.lang.String asString(int indentLevel,
                                 boolean inPattern)
Description copied from class: Term
Turns the Term into a string.

Overrides:
asString in class Term
Parameters:
indentLevel - indentation level to uses for any subsequent lines in the string
inPattern - whether or not to format the string as though it is inside a pattern
Returns:
a string representing the Term

isEmpty

public boolean isEmpty()