peer-at-code-parser-java/src/dev/peerat/parser/Token.java

69 lines
1.3 KiB
Java

package dev.peerat.parser;
public class Token{
private int line;
private int character;
private TokenType type;
private String value;
public Token(int line, int character, String value, TokenType type){
this.line = line;
this.character = character;
this.value = value;
this.type = type;
}
public int getLineNumber(){
return this.line;
}
public int getCharacterNumber(){
return this.character;
}
public TokenType getType(){
return this.type;
}
public String getValue(){
return this.value;
}
//line & character start & end ?
public Token concat(Token token){
return new Token(line, character, value+token.getValue(), TokenType.GROUP);
}
void setLine(int value){
this.line = value;
}
void setCharacter(int value){
this.character = value;
}
void setValue(String value){
this.value = value;
}
void setType(TokenType value){
this.type = value;
}
@Override
public boolean equals(Object obj){
if(obj == null) return false;
if(obj instanceof Token){
Token token = (Token)obj;
return this.line == token.line && this.character == token.character && ((this.value == null && token.value == null) || (this.value.equals(token.value))) && this.type.equals(token.type);
}
return false;
}
@Override
public String toString(){
return "Token["+line+";"+character+";"+type+";"+value+"]";
}
}