All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xjs.serialization.token.SymbolToken Maven / Gradle / Ivy

There is a newer version: 0.36
Show newest version
package xjs.serialization.token;

/**
 * Represents a single symbol or special character. The type of
 * token captured by this object can be represented by the
 * following pattern:
 *
 * 
 *   [^\w\s]
 * 
* *

Note that this token does not necessarily follow or * precede any whitespace. * *

For example, the following text: * *

 *   hello123?
 * 
* *

Counts as two tokens: * *

 *   [ word('hello123'), symbol('?')]
 * 
* *

Likewise, groups of symbols are considered multiple symbol * tokens. Authors will need to account for multi-character * symbols manually. * *

This text: * *

 *   ?:
 * 
* *

Also counts as two tokens: * *

 *   [ symbol('?'), symbol(':') ]
 * 
*/ public class SymbolToken extends Token { /** * The single symbol represented by this token. Authors * will need to access this character directly to analyze * the token. */ public final char symbol; /** * Constructs a new Token object to be placed on an AST. * * @param start The inclusive start index of this token. * @param end The exclusive end index of this token. * @param line The inclusive line number of this token. * @param offset The column of the start index. * @param symbol The raw symbol represented by this token. */ public SymbolToken(final int start, final int end, final int line, final int offset, final char symbol) { this(start, end, line, offset, TokenType.SYMBOL, symbol); } /** * Constructs a new Token object to be placed on an AST. * * @param start The inclusive start index of this token. * @param end The exclusive end index of this token. * @param line The inclusive line number of this token. * @param offset The column of the start index. * @param type The type of token. * @param symbol The raw symbol represented by this token. */ public SymbolToken( final int start, final int end, final int line, final int offset, final TokenType type, final char symbol) { super(start, end, line, offset, type); this.symbol = symbol; } /** * Constructs a new symbol token with effectively no scope. * * @param symbol The raw symbol represented by this token. */ public SymbolToken(final char symbol) { super(symbol == '\n' ? TokenType.BREAK : TokenType.SYMBOL); this.symbol = symbol; } @Override public boolean isSymbol(final char symbol) { return this.symbol == symbol; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy