org.quasiliteral.quasiterm
Class QHole

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

public abstract class QHole
extends QAstro

Untamed: Represents a dollar-hole ("${}") or an at-hole ("@{}") that may be a functor-hole or a term-hole, and that may or may not insist on a tag.

Author:
Mark S. Miller
See Also:
Serialized Form

Field Summary
(package private)  int myHoleNum
           
(package private)  boolean myIsFunctorHole
           
(package private)  AstroTag myOptTag
           
(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) QHole(AstroBuilder builder, AstroTag optTag, int holeNum, boolean isFunctorHole, SourceSpan optSpan)
          Makes a hole that matches a term (either a substitution-arg or a specimen), and either evaluates to it (if this is a dollar-hole) or extracts it (if this is an at-hole).
 
Method Summary
(package private) abstract  QHole asTagged(Astro ident)
           
 ConstList getArgs()
          Enabled: A hole itself has no args, even though a term-hole will match a corresponding literal term that does.
 int getHeight()
          Enabled: A hole is a leaf, and so has height 1
 Object getOptData()
          Enabled: Holes have no data, so getOptData/0 always returns null.
 AstroTag getTag()
          Enabled: Tagged holes return their tag, otherwise throws.
private  Astro leafTag(String tagName)
           
static Object multiGet(ConstList args, int holeNum, int[] index, boolean repeat)
          Enabled: Given a multi-dimensional list and an index path, retrieve the corresponding element of the list.
static Object multiPut(FlexList bindings, int holeNum, int[] index, Object newValue)
          Enabled: Given a multi-dimensional list and an index path, put newValue at that position in the list.
(package private)  Astro optCoerce(Object termoid)
          Does 'termoid' coerced to an Astro match the pattern represented by this hole?
 Astro withArgs(ConstList qArgs)
          Enabled: Can only do this to a functor-hole, in which case it makes a QTerm.
 Astro withoutArgs()
          Enabled: A hole itself has no args, so this just returns itself.
 
Methods inherited from class org.quasiliteral.quasiterm.QAstro
asFunctor, build, getOptArgData, getOptArgData, getOptArgString, getOptString, getOptTagCode, matchBind, matchBind, substitute
 
Methods inherited from class org.quasiliteral.quasiterm.QAstroArg
__printOn, asText, endShape, getOptSpan, matchBindSlice, prettyPrintOn, qbuild, startShape, substSlice, 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
 
Methods inherited from interface org.erights.e.elib.tables.Selfless
getSpreadUncall
 

Field Detail

serialVersionUID

static final long serialVersionUID

myOptTag

final AstroTag myOptTag

myHoleNum

final int myHoleNum

myIsFunctorHole

final boolean myIsFunctorHole
Constructor Detail

QHole

QHole(AstroBuilder builder,
      AstroTag optTag,
      int holeNum,
      boolean isFunctorHole,
      SourceSpan optSpan)
Makes a hole that matches a term (either a substitution-arg or a specimen), and either evaluates to it (if this is a dollar-hole) or extracts it (if this is an at-hole).

Parameters:
builder - Used to build the result of a substitute.
optTag - If present, represents the token tag that the corresponding literal term must have, and this is a tagged-hole. If this is a dollar-hole, the corresponding literal term must be the substitution are at myHoleNum. If this is an at-hole, the corresponding literal term is the specimen.
holeNum - Which hole am I? If this is a dollar-hole, then this says which substitution-arg. If this is an at-hole, then this says which binding.
isFunctorHole - If true, then the corresponding literal term must be 0-arity. If false, then the corresponding literal term may itself have any argument list, and this is a termHole.
optSpan - Where was the source text this node was extracted from?
Method Detail

multiGet

public static Object multiGet(ConstList args,
                              int holeNum,
                              int[] index,
                              boolean repeat)
Enabled: Given a multi-dimensional list and an index path, retrieve the corresponding element of the list.

For example, if 'args' is [['a','b'],['c','d','e']], 'holeNum' is 1, 'index' is [2,3], and 'repeat' is true, then the answer should be 'e', since it's at args[1][2], and the repeat flag allows us to ignore the 3 when we find that 'e' isn't a list. If 'repeat' had been false, the presence of an additional step on the index path would have caused an exception to be thrown. In either case, if an index step is out of bounds, an exception is thrown regardless of the value of 'repeat'.


multiPut

public static Object multiPut(FlexList bindings,
                              int holeNum,
                              int[] index,
                              Object newValue)
Enabled: Given a multi-dimensional list and an index path, put newValue at that position in the list.

For example, if 'bindings' is [['a','b'],['c','d','e']] diverge(), 'holeNum' is 1, 'index' is [2], and 'newValue' is 'x', then the 'e' should be replaced with 'x', since it's at list[1][2]. If any index step is out of bounds, the corresponding list is grown to include it (see FlexList.ensureSize(int) and null is returned. Alternatively, if an old value is being overwritten, then that old value is also returned.


optCoerce

Astro optCoerce(Object termoid)
Does 'termoid' coerced to an Astro match the pattern represented by this hole?

When this hole is a dollar-hole, termoid will be a substitution-arg. When this hole is an at-hole, termoid will be the specimen. In either case, the same criteria are applied:

The coercion rules are:


leafTag

private Astro leafTag(String tagName)

getTag

public AstroTag getTag()
Enabled: Tagged holes return their tag, otherwise throws.


getOptData

public Object getOptData()
Enabled: Holes have no data, so getOptData/0 always returns null.


getArgs

public ConstList getArgs()
Enabled: A hole itself has no args, even though a term-hole will match a corresponding literal term that does.

Returns:
An empty list of QAstroAr

withoutArgs

public Astro withoutArgs()
Enabled: A hole itself has no args, so this just returns itself.


withArgs

public Astro withArgs(ConstList qArgs)
Enabled: Can only do this to a functor-hole, in which case it makes a QTerm.


getHeight

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

Specified by:
getHeight in class QAstroArg

asTagged

abstract QHole asTagged(Astro ident)


comments?