org.quasiliteral.quasiterm
Class QFunctor

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

public class QFunctor
extends QAstro

Untamed: A quasi-literal functor of a Term.

As a ValueMaker, this acts like a 0-arity Term. As a MatchMaker, this matches only the functor info of a specimen term, and ignores the specimen's arguments.

Author:
Mark S. Miller
See Also:
Serialized Form

Field Summary
private  Object myOptData
           
private  AstroTag myTag
           
static StaticMaker QFunctorMaker
          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) QFunctor(AstroBuilder builder, AstroTag tag, Object optData, SourceSpan optSpan)
          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)
          Do nothing.
 ConstList getArgs()
          Enabled: @return An empty list of QAstroArg
 int getHeight()
          Enabled: A functor as a Term is a leaf, and so has height 1
 Object getOptData()
          Enabled: Either literal data or null.
 Object[] getSpreadUncall()
          Enabled: Uses 'QFunctorMaker(myBuilder, myTag, myOptData, myOptSpan)'
 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)
          Just returns shapeSoFar, since this has no shape and no children
 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 qfunctor
 Astro withArgs(ConstList qArgs)
          Enabled:
 Astro withoutArgs()
          Enabled:
 
Methods inherited from class org.quasiliteral.quasiterm.QAstro
build, getOptArgData, getOptArgData, getOptArgString, getOptString, getOptTagCode, 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

QFunctorMaker

public static final StaticMaker QFunctorMaker
Enabled:


myTag

private final AstroTag myTag

myOptData

private final Object myOptData
Constructor Detail

QFunctor

QFunctor(AstroBuilder builder,
         AstroTag tag,
         Object optData,
         SourceSpan optSpan)
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 result of a substitute
tag - Identifies a token type in a particular grammar or set of related grammars, used as the functor (or "label") of this QTerm
optData - Either Character, BigInteger, Double, or Twine or null. If not null, then the tag must represent the canonical literal type for this kind of data in this schema.
optSpan - Where is the source text this node was extracted from?
Method Detail

getSpreadUncall

public Object[] getSpreadUncall()
Enabled: Uses 'QFunctorMaker(myBuilder, myTag, myOptData, myOptSpan)'


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.


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.


getArgs

public ConstList getArgs()
Enabled: @return An empty list of QAstroArg


withoutArgs

public Astro withoutArgs()
Enabled:


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 qfunctor

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].

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 the functor information of specimenList[0] matches that of this qfunctor, while ignoring the args.

getHeight

public int getHeight()
Enabled: A functor as a Term is a leaf, and so has height 1

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)
Just returns shapeSoFar, since this has no shape and no children

Specified by:
startShape in class QAstroArg

endShape

void endShape(FlexList optBindings,
              int[] prefix,
              int shape)
Do nothing.

Specified by:
endShape in class QAstroArg


comments?