org.quasiliteral.quasiterm
Class QTerm

java.lang.Object
  |
  +--org.quasiliteral.quasiterm.QAstroArg
        |
        +--org.quasiliteral.quasiterm.QAstro
              |
              +--org.quasiliteral.quasiterm.QTerm
All Implemented Interfaces:
Astro, AstroArg, Marker, MatchMaker, PassByConstruction, Persistent, Selfless, Serializable, ValueMaker

public class QTerm
extends QAstro

Untamed: A quasi-literal Term, that matches or generates an actual Astro.

Author:
Mark S. Miller
See Also:
Serialized Form

Field Summary
private  int myHeight
          Just used to decide how to pretty print.
private  ConstList myQArgs
           
private  QAstro myQFunctor
           
static StaticMaker QTermMaker
          Enabled:
(package private) static long serialVersionUID
           
 
Fields inherited from class org.quasiliteral.quasiterm.QAstroArg
EListGuard, EMPTY_INDEX, myBuilder, myOptSpan
 
Fields inherited from interface org.erights.e.elib.tables.Selfless
HONORARY, HONORED_NAMES
 
Fields inherited from interface org.erights.e.elib.serial.PassByConstruction
HONORARY, HONORED_NAMES
 
Fields inherited from interface org.erights.e.elib.serial.Persistent
HONORARY, HONORED_NAMES
 
Constructor Summary
(package private) QTerm(AstroBuilder builder, QAstro qFunctor, ConstList qArgs)
          Makes a QTerm that matches or generates a Astro.
 
Method Summary
(package private)  QAstro asFunctor()
          Returns a variant of this Astro that may serve as a functor of a QTerm.
(package private)  void endShape(FlexList optBindings, int[] prefix, int shape)
          Just delegate to all children
 ConstList getArgs()
          Enabled: @return :(ConstList of(QAstroArg))
 int getHeight()
          Enabled:
 Object getOptData()
          Enabled: Either literal data or null.
 String getOptString()
          Enabled:
 short getOptTagCode()
          Enabled:
 Object[] getSpreadUncall()
          Enabled: Uses 'QTermMaker(myBuilder, myQFunctor, myQArgs)'
 AstroTag getTag()
          Enabled: Represents the token-type of the functor of this term.
 int matchBindSlice(ConstList args, ConstList specimenList, FlexList bindings, int[] index)
          Enabled: Attempts to match against the Astro specimenList[0].
 void prettyPrintOn(TextWriter out)
          Enabled:
 AstroArg qbuild(QuasiBuilder qbuilder)
          Enabled:
(package private)  int startShape(ConstList args, FlexList optBindings, int[] prefix, int shapeSoFar)
          A QTerm has whatever shape its children agree on
 ConstList substSlice(ConstList args, int[] index)
          Enabled: @return A single list of a single Astro, whose functor is based on literal functor info of this qterm, and whose args are the concatentation of the substSlice of the qargs of this qterm.
 Astro withArgs(ConstList qArgs)
          Enabled:
 Astro withoutArgs()
          Enabled: Returns a QTerm like with one, but without args.
 
Methods inherited from class org.quasiliteral.quasiterm.QAstro
build, getOptArgData, getOptArgData, getOptArgString, matchBind, matchBind, substitute
 
Methods inherited from class org.quasiliteral.quasiterm.QAstroArg
__printOn, asText, getOptSpan, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.quasiliteral.astro.AstroArg
getOptSpan
 

Field Detail

serialVersionUID

static final long serialVersionUID

QTermMaker

public static final StaticMaker QTermMaker
Enabled:


myQFunctor

private final QAstro myQFunctor

myQArgs

private final ConstList myQArgs

myHeight

private transient int myHeight
Just used to decide how to pretty print.

Initialized lazily. 0 if uninitialized, so does not need to be recalculated on revival.

Constructor Detail

QTerm

QTerm(AstroBuilder builder,
      QAstro qFunctor,
      ConstList qArgs)
Makes a QTerm that matches or generates a Astro.

The invariants of a QTerm are not checked here, but rather are enforced by the callers in this class and in QTermBuilder.

Parameters:
builder - Used to build the results of a substitute
qFunctor - Matches of generates functor information
qArgs - This QTerm's argument list -- a list of QAstroArg
Method Detail

getSpreadUncall

public Object[] getSpreadUncall()
Enabled: Uses 'QTermMaker(myBuilder, myQFunctor, myQArgs)'


qbuild

public AstroArg qbuild(QuasiBuilder qbuilder)
Enabled:

Specified by:
qbuild in class QAstroArg

getTag

public AstroTag getTag()
Enabled: Represents the token-type of the functor of this term.


getOptTagCode

public short getOptTagCode()
Enabled:

Specified by:
getOptTagCode in interface Astro
Overrides:
getOptTagCode in class QAstro

getOptData

public Object getOptData()
Enabled: Either literal data or null. If not null, then the tag must represent the canonical literal type for this kind of data in this schema.


getOptString

public String getOptString()
Enabled:

Specified by:
getOptString in interface Astro
Overrides:
getOptString in class QAstro

getArgs

public ConstList getArgs()
Enabled: @return :(ConstList of(QAstroArg))


withoutArgs

public Astro withoutArgs()
Enabled: Returns a QTerm like with one, but without args.

Unlike myQFunctor, this will only match a Term of zero-arity.


withArgs

public Astro withArgs(ConstList qArgs)
Enabled:


substSlice

public ConstList substSlice(ConstList args,
                            int[] index)
Enabled: @return A single list of a single Astro, whose functor is based on literal functor info of this qterm, and whose args are the concatentation of the substSlice of the qargs of this qterm.

Specified by:
substSlice in class QAstroArg
Parameters:
index - Further indexes after a hole's hole-num. For example, If a dollar-hole's hole-num is 3 and index is [4,5], then the dollar-hole would evaluate to args[3][4][5].
Returns:
:(ConstList of(Astro))

matchBindSlice

public int matchBindSlice(ConstList args,
                          ConstList specimenList,
                          FlexList bindings,
                          int[] index)
Enabled: Attempts to match against the Astro specimenList[0].

Matches the arg list by a naive greedy algorithm.

Specified by:
matchBindSlice in class QAstroArg
Parameters:
args - See the doc on 'args' in #substitute(Object[], String)
specimenList - :(ConstList of(Astro))
bindings - Like 'args', but by extraction from specimen
index - Further indexes after a hole's hole-num. For example, If a dollar-hole's hole-num is 3 and index is [4,5], then the dollar-hole would access args[3][4][5]. Similarly, an at-hole with hole-num 3 would store into bindings[3][4][5].
Returns:
-1 or 1, depending on whether specimenList[0] matches this qterm.

getHeight

public int getHeight()
Enabled:

Specified by:
getHeight in class QAstroArg

prettyPrintOn

public void prettyPrintOn(TextWriter out)
                   throws IOException
Enabled:

Specified by:
prettyPrintOn in class QAstroArg
IOException

asFunctor

QAstro asFunctor()
Description copied from class: QAstro
Returns a variant of this Astro that may serve as a functor of a QTerm.

If this Astro (or derivatives) should not be used as a functor, then this operation should throw.

Specified by:
asFunctor in class QAstro

startShape

int startShape(ConstList args,
               FlexList optBindings,
               int[] prefix,
               int shapeSoFar)
A QTerm has whatever shape its children agree on

Specified by:
startShape in class QAstroArg

endShape

void endShape(FlexList optBindings,
              int[] prefix,
              int shape)
Just delegate to all children

Specified by:
endShape in class QAstroArg


comments?