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
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. |
serialVersionUID
static final long serialVersionUID
myOptTag
final AstroTag myOptTag
myHoleNum
final int myHoleNum
myIsFunctorHole
final boolean myIsFunctorHole
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?
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:
- If termoid doesn't coerce to an Astro, then null -- we have no
match
- If we have a tag, and it doesn't match termoid's tag, then
null.
- If we are a functor-hole (rather than a term-hole) and termoid has
one or more arguments, then null.
- Otherwise, we match, so return the coerced termoid.
The coercion rules are:
- An integer coerces to a literal integer term.
- A floating point number coerces to a literal float64 term.
- A character coerces to a literal character term.
- null coerces to term`null`, ie, a term with tag "null" and no
arguments.
- A boolean coerces to either term`true` or term`false`.
- A String or Twine normally coerces to a zero-arity term whose
tag is that String. But if this hole's tag is ".String.", then
the String will instead convert to a literal string term.
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?