org.quasiliteral.antlr
Class AstroToken

java.lang.Object
  |
  +--antlr.Token
        |
        +--org.quasiliteral.antlr.AstroToken
All Implemented Interfaces:
Astro, AstroArg, Cloneable

public class AstroToken
extends Token
implements Astro

Untamed: A Kind of Antlr Token that preserves all the information in a Functor.

In keeping with the nature of an Antlr Token, and in order to be usable from within Antlr itself, AstroToken is mutable, but just mutable enough to accomodate Antlr. Specifically, the various values are settable once.

Author:
Mark S. Miller, Based on ValueExtentToken by Danfuzz Bornstein

Field Summary
private  Object myOptData
          Must be a null, Character, BigInteger, Double, String, or Twine.
private  AstroSchema myOptSchema
           
private  SourceSpan myOptSpan
           
private  AstroTag myOptTag
           
 
Fields inherited from class antlr.Token
badToken, EOF_TYPE, INVALID_TYPE, MIN_USER_TYPE, NULL_TREE_LOOKAHEAD, SKIP
 
Constructor Summary
  AstroToken()
          Enabled: Construct an instance.
(package private) AstroToken(AstroSchema optSchema, AstroTag tag, Object optData, SourceSpan optSpan)
          Makes an AstroToken that represents a token in some grammar.
 
Method Summary
 Astro build(AstroBuilder builder)
          Enabled:
static Astro build(Token self, AstroBuilder builder)
          Enabled: Since not all Tokens are AstroTokens, this static method provides the equivalent of the build/1 instance method for Tokens in general.
 ConstList getArgs()
          Enabled:
 int getColumn()
          Enabled:
 int getLine()
          Enabled:
 Object getOptArgData()
          Enabled:
 Object getOptArgData(short tagCode)
          Enabled:
 String getOptArgString(short tagCode)
          Enabled:
 Object getOptData()
          Enabled: If this token represents literal data, return that data, else null.
 SourceSpan getOptSpan()
          Enabled:
 String getOptString()
          Enabled:
 short getOptTagCode()
          Enabled:
 AstroTag getTag()
          Enabled:
 String getText()
          Enabled:
 void setColumn(int c)
          Enabled: Override to make set-once, and so set the source-span info of myOptSpan
 void setLine(int l)
          Enabled: Override to make set-once, and so set the source-span info of myOptSpan
 void setSchema(AstroSchema schema)
          Enabled: For when the type-code is already set by generic Antlr code, while Astro-specific knowledge of the schema comes along later.
 void setText(String s)
          Enabled:
 void setType(int t)
          Enabled: Override to make set-once
 Astro withArgs(ConstList args)
          Enabled:
 Astro withoutArgs()
          Enabled:
 
Methods inherited from class antlr.Token
getType, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myOptSchema

private AstroSchema myOptSchema

myOptTag

private AstroTag myOptTag

myOptData

private Object myOptData
Must be a null, Character, BigInteger, Double, String, or Twine. If not null, then the type must correspond to the tag.


myOptSpan

private final SourceSpan myOptSpan
Constructor Detail

AstroToken

public AstroToken()
Enabled: Construct an instance.

The instance will have the tag code -1, null optData, and null optSpan.


AstroToken

AstroToken(AstroSchema optSchema,
           AstroTag tag,
           Object optData,
           SourceSpan optSpan)
Makes an AstroToken that represents a token in some grammar.

The invariants of an AstroToken are not checked here, but rather are enforced by the callers in this class and in ASTBuilder.

Parameters:
optSchema - If provided, the AstroSchema in which tag is defined. To use the composite representation, a schema must be provided.
tag - Identifies a token type in a particular grammar or set of related grammars.
optData - null, Character, BigInteger, Double, or Twine presumably calculated from lexing this token
optSpan - Where this token was extracted from.
Method Detail

build

public Astro build(AstroBuilder builder)
Enabled:

Specified by:
build in interface Astro

build

public static Astro build(Token self,
                          AstroBuilder builder)
Enabled: Since not all Tokens are AstroTokens, this static method provides the equivalent of the build/1 instance method for Tokens in general.

In the understanding of non-Astro Tokens used here, their functor is only according to the AST's type code, for the tag, and the AST's text, for the data. This choice for data will often be a mistake, but there's no generic way to make a better decision. For grammars where this is wrong, you should build a grammar-specific converter.

XXX This should probably be made into a sugar-instance-method of Token.


getTag

public AstroTag getTag()
Enabled:

Specified by:
getTag in interface Astro

setSchema

public void setSchema(AstroSchema schema)
Enabled: For when the type-code is already set by generic Antlr code, while Astro-specific knowledge of the schema comes along later.

To use this, the type code must already be set, the tag must not yet be set, and the schema must not be set to a different schema.


setType

public void setType(int t)
Enabled: Override to make set-once

Overrides:
setType in class Token

getOptTagCode

public short getOptTagCode()
Enabled:

Specified by:
getOptTagCode in interface Astro

getOptData

public Object getOptData()
Enabled: If this token represents literal data, return that data, else null.

Specified by:
getOptData in interface Astro

getOptString

public String getOptString()
Enabled:

Specified by:
getOptString in interface Astro

getOptArgData

public Object getOptArgData()
Enabled:

Specified by:
getOptArgData in interface Astro

getOptArgData

public Object getOptArgData(short tagCode)
Enabled:

Specified by:
getOptArgData in interface Astro

getOptArgString

public String getOptArgString(short tagCode)
Enabled:

Specified by:
getOptArgString in interface Astro

getOptSpan

public SourceSpan getOptSpan()
Enabled:

Specified by:
getOptSpan in interface AstroArg

getText

public String getText()
Enabled:

Overrides:
getText in class Token

setText

public void setText(String s)
Enabled:

Overrides:
setText in class Token

getLine

public int getLine()
Enabled:

Overrides:
getLine in class Token

setLine

public void setLine(int l)
Enabled: Override to make set-once, and so set the source-span info of myOptSpan

Overrides:
setLine in class Token

getColumn

public int getColumn()
Enabled:

Overrides:
getColumn in class Token

setColumn

public void setColumn(int c)
Enabled: Override to make set-once, and so set the source-span info of myOptSpan

Overrides:
setColumn in class Token

getArgs

public ConstList getArgs()
Enabled:

Specified by:
getArgs in interface Astro

withoutArgs

public Astro withoutArgs()
Enabled:

Specified by:
withoutArgs in interface Astro

withArgs

public Astro withArgs(ConstList args)
Enabled:

Specified by:
withArgs in interface Astro


comments?