2022-03-29 19:31:45 +00:00
|
|
|
#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,
|
|
|
|
|
2022-03-29 21:08:55 +00:00
|
|
|
IF,
|
|
|
|
ELSE,
|
|
|
|
|
|
|
|
DEFAULT,
|
|
|
|
|
|
|
|
// BOOLEAN VALUE
|
|
|
|
TRUE,
|
|
|
|
FALSE,
|
|
|
|
|
2022-04-08 20:46:47 +00:00
|
|
|
// NULL
|
|
|
|
NIL,
|
|
|
|
|
2022-03-29 21:08:55 +00:00
|
|
|
// KEYWORDS
|
|
|
|
KW_NAME,
|
|
|
|
KW_INFO,
|
|
|
|
KW_HEADER,
|
|
|
|
KW_DIRECTORY,
|
|
|
|
KW_LIBRARY,
|
|
|
|
KW_ADDRESS,
|
|
|
|
KW_COMPONENT,
|
|
|
|
KW_MESSAGES,
|
|
|
|
KW_INSTANCE_NAME,
|
|
|
|
KW_COUNT,
|
|
|
|
KW_DISPLAY,
|
|
|
|
KW_PIN,
|
|
|
|
KW_TOOLTIP,
|
|
|
|
KW_CONNECTION,
|
|
|
|
KW_ATTRIBUTE,
|
|
|
|
KW_SOURCE,
|
|
|
|
KW_POPUP,
|
|
|
|
KW_RULE,
|
|
|
|
KW_TITLE,
|
|
|
|
KW_TEXT,
|
|
|
|
KW_BUS,
|
|
|
|
KW_WIRES,
|
|
|
|
KW_ENUMERATED,
|
|
|
|
KW_WIRE,
|
|
|
|
KW_INSTANCE,
|
|
|
|
KW_SCHEMA,
|
|
|
|
KW_POSITION,
|
|
|
|
KW_SIZE,
|
|
|
|
KW_UNKNOWN,
|
2022-03-29 19:31:45 +00:00
|
|
|
|
|
|
|
// TYPES
|
2022-03-29 21:08:55 +00:00
|
|
|
INT_TYPE,
|
|
|
|
BOOL_TYPE,
|
|
|
|
STRING_TYPE,
|
|
|
|
WIRE_TYPE,
|
|
|
|
|
|
|
|
// WIRE TYPES
|
|
|
|
WIRE_DEFAULT,
|
|
|
|
WIRE_AND,
|
|
|
|
WIRE_OR,
|
|
|
|
R_WIRE,
|
|
|
|
|
|
|
|
// PIN_TYPES
|
|
|
|
PIN_IN,
|
|
|
|
PIN_OUT,
|
|
|
|
PIN_IN_OUT,
|
|
|
|
|
|
|
|
// COMPONENT TYPES
|
|
|
|
CT_MEMORY,
|
|
|
|
CT_PROCESSOR,
|
|
|
|
|
|
|
|
// ACTION TYPES
|
|
|
|
ERROR,
|
|
|
|
WARNING,
|
|
|
|
|
|
|
|
// OTHER
|
|
|
|
END_OF_FILE
|
2022-03-29 19:31:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Token {
|
|
|
|
TokenType type;
|
|
|
|
Span span;
|
|
|
|
std::string text;
|
|
|
|
|
|
|
|
Token(TokenType type, Span span, std::string text);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TOKEN_H
|