-
token.parent
is the parent-token of the token. It is the token of the parent-operation of the operation of the token. It is the way to transact between a chain of operations that uses tokens. token.depth
is a final integer represents the number of parents the token have.
int depth = token.depth; int i = 0; while((token = token.parent) != null) i++; assert i == depth;
token.data
is a map that holds variables within the token only. It has the variables that should effect its token’s behavior only.
//sharing data locally to this token specifically token.data.put("key", "value"); //getting data shared locally to this token specifically token.data.get("key");
token.linear
is a map that holds variables for all of it’s children. It has the variables that should effect its token’s and its token’s children and grand-children’s behavior.
//share data linearly to the next new children only. token.linear.put("key", "value"); //getting data shared linearly from the parent while initializing token.linear.get("key");
token.tree
is a map that holds variables remotely across all the tokens related in any kind to its token.
//share data globally to all the tokens related to this token token.tree.put("key", "value"); //getting data shared globally the tokens related to this token token.tree.get("key");
Convert Token
The Convert Token is a token for object converting operation witch is converting the value of an object from a class to a different class. The token holds the input object, the output object, the input type, the output type, and the environment variables that the converting methods could communicate using it.
//the parent token
ConvertToken parent = //...;
//the input object that have the value to be converted
Object in = //...;
//the output object to convert the value to
//it will be replaced if it is null or invalid
Object out = //...;
//the clazz of the input object
//the clazz's family is used to pick the method
//the clazz's class is used as the class of the input
Clazz inClz = //...;
//the clazz of the output object
//the clazz's family is used to pick the method
//the clazz's class is used to construct new product
//if th product given is null or not valid
Clazz outClz = //...;
ConvertToken token = new ConvertToken(parent,in,out,inClz,outClz);
//if no parent: new ConvertToken(in, out, inClz, outClz);
assert token.parent == parent;
assert token.input == in;
assert token.output == out;
assert token.inputClazz == inClz;
assert token.outputClazz = outClz;
//now you can pass it to any converter
converter.convert(token);
Classify Token
The Classify Token is a token for a classification operation witch is determining the way to parse a text and the type of the result from parsing the text. The token holds the reader that its text should be classified, the result of the classification, and the environment variables that the classification methods could communicate using it.
//the parent token.
ClassifyToken parent = //...;
//the reader to classify the text that it holds
//it should support `mark(int)` and `reset()`
//and `mark(int)` should not be fixed to the integer given to it
Reader reader = //...;
//the clazz to be returned if the classification failed.
//if null, then a classification-exception will be thrown when
//the classifier failed to classify
Clazz klazz = //...;
ClassifyToken token = new ClassifyToken(parent, reader, klazz);
//if no parent: new ClassifyToken(reader, klazz);
assert token.parent == parent;
assert token.input == reader;
assert token.output == klazz;
//now you can pass it to any classifier
classifier.classify(token);
Parse Token
The Parse Token is a token for a parsing operation witch is storing the value of a text in a java object so it could accessed more easier. The token holds the reader that its text should be parsed, the result from parsing, and the environment variables that the parsing methods could communicate using it.
//the parent token.
ParseToken parent = //...;
//the reader to parse the text that it holds
//it should support `mark(int)` and `reset()`
//and `mark(int)` should not be fixed to the integer given to it
Reader reader = //...;
//the initial output.
//the output to write the parsed values to.
//nullable, and get replaced if it is not valid
Object instance = //...;
//the clazz of how to parse the text as.
//the clazz's family is used to pick the method
//the clazz's klass is used to construct new instance of the value
//if the value given is null or not valid
Clazz klazz = //...;
ParseToken token = new ParseToken(parent, reader, instance, klazz);
//if no parent: new ParseToken(reader, instance, klazz);
assert token.parent == parent;
assert token.input == reader;
assert token.output == instance;
assert token.klazz == klazz;
//now you can pass it to any parser
parser.parse(token);
Format Token
The Format Token is a token for a formatting operation witch is writing a text that represents a value of a java object to be stored or transferred. The token holds the output writer to be written on, the input java object, and the environment variables that the formatting methods could communicate using it.
//the parent token.
FormatToken parent = //...;
//the object to be written as text
Object instance = //...;
//the writer to write the formatting results on
Writer writer = //...;
//the clazz of how to format the instance as
//the clazz's family is used to pick the method
//the clazz's klass is used to annotate it as the class in the text
Clazz klazz = //...;
FormatToken token = new FormatToken(parent,instance,writer,klazz);
//if no parent: new FormatToken(instance, writer, klazz);
assert token.parent == parent;
assert token.input == instance;
assert token.output == writer;
assert token.klazz == klazz;
//now you can pass it to any formatter
formatter.format(token);