Tokens

The tokens are instances that holds information about an operation. Such as the type of the operation, the type of the data, the input, the output, and the depth of that operation.


Convert Token
GitHub Javadoc


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
GitHub Javadoc


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
GitHub Javadoc


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
GitHub Javadoc


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);