1 |
schoenebeck |
2885 |
/* |
2 |
schoenebeck |
3729 |
* Copyright (c) 2015-2020 Christian Schoenebeck |
3 |
schoenebeck |
2885 |
* |
4 |
|
|
* http://www.linuxsampler.org |
5 |
|
|
* |
6 |
|
|
* This file is part of LinuxSampler and released under the same terms. |
7 |
|
|
* See README file for details. |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#ifndef CRUDEBYTE_CODE_TOKEN_H |
11 |
|
|
#define CRUDEBYTE_CODE_TOKEN_H |
12 |
|
|
|
13 |
|
|
#include "../../common/global.h" |
14 |
|
|
|
15 |
|
|
namespace LinuxSampler { |
16 |
|
|
|
17 |
|
|
class SourceToken { |
18 |
|
|
public: |
19 |
|
|
enum BaseType_t { |
20 |
|
|
// most fundamental tokens |
21 |
|
|
END_OF_FILE = 0, |
22 |
|
|
NEW_LINE, |
23 |
|
|
// base token types |
24 |
|
|
KEYWORD, |
25 |
|
|
VARIABLE_NAME, |
26 |
|
|
IDENTIFIER, // i.e. function name |
27 |
|
|
NUMBER_LITERAL, |
28 |
|
|
STRING_LITERAL, |
29 |
|
|
COMMENT, |
30 |
|
|
PREPROCESSOR, |
31 |
schoenebeck |
3562 |
METRIC_PREFIX, |
32 |
|
|
STANDARD_UNIT, |
33 |
schoenebeck |
2885 |
OTHER, // anything else not classified here |
34 |
|
|
}; |
35 |
|
|
|
36 |
|
|
enum ExtType_t { |
37 |
|
|
NO_EXT, ///< no extended type available for this token |
38 |
|
|
INTEGER_VARIABLE, |
39 |
schoenebeck |
3573 |
REAL_VARIABLE, |
40 |
schoenebeck |
2885 |
STRING_VARIABLE, |
41 |
schoenebeck |
3573 |
INTEGER_ARRAY_VARIABLE, |
42 |
|
|
REAL_ARRAY_VARIABLE, |
43 |
schoenebeck |
2885 |
EVENT_HANDLER_NAME // only NKSP language |
44 |
|
|
}; |
45 |
|
|
|
46 |
schoenebeck |
3729 |
SourceToken() : baseType(END_OF_FILE), extType(NO_EXT), line(0), column(0), |
47 |
|
|
offset(0), length(0) |
48 |
|
|
{ |
49 |
schoenebeck |
2885 |
} |
50 |
|
|
|
51 |
schoenebeck |
3729 |
SourceToken(BaseType_t t, String s = "") : baseType(t), extType(NO_EXT), |
52 |
|
|
txt(s), line(0), column(0), |
53 |
|
|
offset(0), length(0) |
54 |
|
|
{ |
55 |
schoenebeck |
2885 |
} |
56 |
|
|
|
57 |
schoenebeck |
3729 |
SourceToken(ExtType_t t, String s = "") : baseType(OTHER), extType(t), |
58 |
|
|
txt(s), line(0), column(0), |
59 |
|
|
offset(0), length(0) |
60 |
|
|
{ |
61 |
schoenebeck |
2885 |
switch (t) { |
62 |
|
|
case NO_EXT: baseType = OTHER; break; |
63 |
|
|
case INTEGER_VARIABLE: baseType = VARIABLE_NAME; break; |
64 |
schoenebeck |
3573 |
case REAL_VARIABLE: baseType = VARIABLE_NAME; break; |
65 |
schoenebeck |
2885 |
case STRING_VARIABLE: baseType = VARIABLE_NAME; break; |
66 |
schoenebeck |
3573 |
case INTEGER_ARRAY_VARIABLE: baseType = VARIABLE_NAME; break; |
67 |
|
|
case REAL_ARRAY_VARIABLE: baseType = VARIABLE_NAME; break; |
68 |
schoenebeck |
2885 |
case EVENT_HANDLER_NAME: baseType = IDENTIFIER; break; |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
BaseType_t baseType; |
73 |
|
|
ExtType_t extType; |
74 |
|
|
String txt; |
75 |
|
|
int line; |
76 |
|
|
int column; |
77 |
schoenebeck |
3729 |
int offset; |
78 |
|
|
int length; |
79 |
schoenebeck |
2885 |
|
80 |
|
|
String text() const { return txt; } |
81 |
|
|
int firstLine() const { return line; } |
82 |
|
|
int firstColumn() const { return column; } |
83 |
schoenebeck |
3729 |
int firstByte() const { return offset; } |
84 |
|
|
int lengthBytes() const { return length; } |
85 |
schoenebeck |
2885 |
|
86 |
|
|
// base types |
87 |
schoenebeck |
3034 |
bool isEOF() const { return baseType == END_OF_FILE; } |
88 |
schoenebeck |
2885 |
bool isNewLine() const { return baseType == NEW_LINE; } |
89 |
|
|
bool isKeyword() const { return baseType == KEYWORD; } |
90 |
|
|
bool isVariableName() const { return baseType == VARIABLE_NAME; } |
91 |
|
|
bool isIdentifier() const { return baseType == IDENTIFIER; } |
92 |
|
|
bool isNumberLiteral() const { return baseType == NUMBER_LITERAL; } |
93 |
|
|
bool isStringLiteral() const { return baseType == STRING_LITERAL; } |
94 |
|
|
bool isComment() const { return baseType == COMMENT; } |
95 |
|
|
bool isPreprocessor() const { return baseType == PREPROCESSOR; } |
96 |
schoenebeck |
3562 |
bool isMetricPrefix() const { return baseType == METRIC_PREFIX; } |
97 |
|
|
bool isStdUnit() const { return baseType == STANDARD_UNIT; } |
98 |
schoenebeck |
2885 |
bool isOther() const { return baseType == OTHER; } |
99 |
|
|
|
100 |
|
|
// extended types |
101 |
|
|
bool isIntegerVariable() const { return extType == INTEGER_VARIABLE; } |
102 |
schoenebeck |
3573 |
bool isRealVariable() const { return extType == REAL_VARIABLE; } |
103 |
schoenebeck |
2885 |
bool isStringVariable() const { return extType == STRING_VARIABLE; } |
104 |
schoenebeck |
3573 |
bool isIntegerArrayVariable() const { return extType == INTEGER_ARRAY_VARIABLE; } |
105 |
|
|
bool isRealArrayVariable() const { return extType == REAL_ARRAY_VARIABLE; } |
106 |
schoenebeck |
2885 |
bool isEventHandlerName() const { return extType == EVENT_HANDLER_NAME; } |
107 |
|
|
|
108 |
|
|
operator bool() const { return baseType != END_OF_FILE; } |
109 |
|
|
|
110 |
|
|
bool equalsType(const SourceToken& other) const { |
111 |
|
|
return baseType == other.baseType && extType == other.extType; |
112 |
|
|
} |
113 |
|
|
}; |
114 |
|
|
|
115 |
|
|
} // namespace LinuxSampler |
116 |
|
|
|
117 |
|
|
#endif // CRUDEBYTE_CODE_TOKEN_H |