schema_editor/comdel/parser/token.h

132 lines
1.9 KiB
C++

#ifndef TOKEN_H
#define TOKEN_H
#include <string>
#include <map>
struct Position {
unsigned fileId;
unsigned line;
unsigned col;
unsigned offset;
Position();
Position(unsigned fileId, unsigned line, unsigned col, unsigned offset);
};
/** Location of an ast node inside the source **/
struct Span {
/** beginning (low) position **/
Position lo;
/** end (high) position **/
Position hi;
Span();
Span(Position lo, Position hi);
Span(Position lo);
Span to(const Span& span) const;
};
enum class TokenType {
COLON,
SEMICOLON,
LBRACE,
RBRACE,
LPAREN,
RPAREN,
LBRACKET,
RBRACKET,
LT,
GT,
KEYWORD,
IDENTIFIER,
NUMBER,
STRING,
NOT,
COMMA,
DOT,
COLOR,
EQUALS,
COMMENT,
WHITESPACE,
END_OF_FILE
};
enum class ValueType {
// TYPES
BOOL,
INT,
STRING,
COLOR,
WIRE,
ADDRESS_SPACE,
};
class KeywordType {
public:
enum Type {
// KEYWORDS
NAME,
INFO,
HEADER,
DIRECTORY,
LIBRARY,
ADDRESS,
COMPONENT,
MESSAGES,
INSTANCE_NAME,
COUNT,
DISPLAY,
PIN,
TOOLTIP,
CONNECTION,
ATTRIBUTE,
SOURCE,
POPUP,
RULE,
TITLE,
TEXT,
BUS,
WIRES,
ENUMERATED,
WIRE,
INSTANCE,
SCHEMA,
POSITION,
SIZE,
UNKNOWN
};
static KeywordType::Type determineType(std::string type) {
if(keywords.count(type) == 0) {
return UNKNOWN;
}
return keywords.at(type);
}
private:
const static std::map<std::string, KeywordType::Type> keywords;
};
struct Token {
TokenType type;
Span span;
std::string text;
Token(TokenType type, Span span, std::string text);
};
#endif // TOKEN_H