org.quasiliteral.quasiterm
Class QAtHole

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

public class QAtHole
extends QHole

Untamed: An at-hole of a quasi-literal term expression extracts the specimen into a binding.

An at-hole is not a valid ValueMaker, and so neither is any quasi tree that contains an at-hole. If encountered during substitution, an at-hole throws. It would be good to make this error occur earlier.

As a MatchMaker, this requires the specimen to meet its constraints (optional tag, optional requirement of zero arity), and then extracts it into the binding at [hole-number]+index.

Author:
Mark S. Miller
See Also:
Serialized Form

Field Summary
static StaticMaker QAtHoleMaker
          Enabled:
(package private) static long serialVersionUID
           
 
Fields inherited from class org.quasiliteral.quasiterm.QHole
myHoleNum, myIsFunctorHole, myOptTag
 
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) QAtHole(AstroBuilder builder, AstroTag optTag, int holeNum, boolean isFunctorHole, SourceSpan optSpan)
          Makes a hole that extracts a specimen into a binding.
 
Method Summary
(package private)  QAstro asFunctor()
          Returns a variant of this Astro that may serve as a functor of a QTerm.
(package private)  QHole asTagged(Astro ident)
           
(package private)  void endShape(FlexList optBindings, int[] prefix, int shape)
          Truncate and snapshot the bindings at [myHoleNum]+prefix to shape.
 Object[] getSpreadUncall()
          Enabled: Uses 'QAtHoleMaker(myBuilder, myOptTag, myHoleNum, myIsFunctorHole, myOptSpan)'
 int matchBindSlice(ConstList args, ConstList specimenList, FlexList bindings, int[] index)
          Enabled: This extracts the specimen into the binding at [myHoleNum]+index.
 void prettyPrintOn(TextWriter out)
          Enabled:
 AstroArg qbuild(QuasiBuilder qbuilder)
          Enabled:
(package private)  int startShape(ConstList args, FlexList optBindings, int[] prefix, int shapeSoFar)
          An at-hole doesn't contribute to the shape, so just returns shapeSoFar, but initializes the binding at [myHoleNum]+prefix to a new empty FlexList.
 ConstList substSlice(ConstList args, int[] index)
          Enabled: This throws, complaining that a quasi-tree with an @-hole may not be used as a ValueMaker.
 
Methods inherited from class org.quasiliteral.quasiterm.QHole
getArgs, getHeight, getOptData, getTag, multiGet, multiPut, optCoerce, withArgs, withoutArgs
 
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

QAtHoleMaker

public static final StaticMaker QAtHoleMaker
Enabled:

Constructor Detail

QAtHole

QAtHole(AstroBuilder builder,
        AstroTag optTag,
        int holeNum,
        boolean isFunctorHole,
        SourceSpan optSpan)
Makes a hole that extracts a specimen into a binding.

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

For the meanings of the parameters, see the QHole constructor, which has the same parameters.

Method Detail

getSpreadUncall

public Object[] getSpreadUncall()
Enabled: Uses 'QAtHoleMaker(myBuilder, myOptTag, myHoleNum, myIsFunctorHole, myOptSpan)'


qbuild

public AstroArg qbuild(QuasiBuilder qbuilder)
Enabled:

Specified by:
qbuild in class QAstroArg

startShape

int startShape(ConstList args,
               FlexList optBindings,
               int[] prefix,
               int shapeSoFar)
An at-hole doesn't contribute to the shape, so just returns shapeSoFar, but initializes the binding at [myHoleNum]+prefix to a new empty FlexList.

Specified by:
startShape in class QAstroArg

endShape

void endShape(FlexList optBindings,
              int[] prefix,
              int shape)
Truncate and snapshot the bindings at [myHoleNum]+prefix to shape.

Specified by:
endShape in class QAstroArg

substSlice

public ConstList substSlice(ConstList args,
                            int[] index)
Enabled: This throws, complaining that a quasi-tree with an @-hole may not be used as a ValueMaker.

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: This extracts the specimen into the binding at [myHoleNum]+index.

This first ensures the specimen meets our own constraints.

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 they match.

asTagged

QHole asTagged(Astro ident)
Specified by:
asTagged in class QHole

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

prettyPrintOn

public void prettyPrintOn(TextWriter out)
                   throws IOException
Enabled:

Specified by:
prettyPrintOn in class QAstroArg
IOException


comments?