1 |
schoenebeck |
2885 |
/* |
2 |
schoenebeck |
3562 |
* Copyright (c) 2015-2019 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 |
|
|
SourceToken() : baseType(END_OF_FILE), extType(NO_EXT), line(0), column(0) { |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
SourceToken(BaseType_t t, String s = "") : baseType(t), extType(NO_EXT), txt(s), line(0), column(0) { |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
SourceToken(ExtType_t t, String s = "") : baseType(OTHER), extType(t), txt(s), line(0), column(0) { |
53 |
|
|
switch (t) { |
54 |
|
|
case NO_EXT: baseType = OTHER; break; |
55 |
|
|
case INTEGER_VARIABLE: baseType = VARIABLE_NAME; break; |
56 |
schoenebeck |
3573 |
case REAL_VARIABLE: baseType = VARIABLE_NAME; break; |
57 |
schoenebeck |
2885 |
case STRING_VARIABLE: baseType = VARIABLE_NAME; break; |
58 |
schoenebeck |
3573 |
case INTEGER_ARRAY_VARIABLE: baseType = VARIABLE_NAME; break; |
59 |
|
|
case REAL_ARRAY_VARIABLE: baseType = VARIABLE_NAME; break; |
60 |
schoenebeck |
2885 |
case EVENT_HANDLER_NAME: baseType = IDENTIFIER; break; |
61 |
|
|
} |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
BaseType_t baseType; |
65 |
|
|
ExtType_t extType; |
66 |
|
|
String txt; |
67 |
|
|
int line; |
68 |
|
|
int column; |
69 |
|
|
|
70 |
|
|
String text() const { return txt; } |
71 |
|
|
int firstLine() const { return line; } |
72 |
|
|
int firstColumn() const { return column; } |
73 |
|
|
|
74 |
|
|
// base types |
75 |
schoenebeck |
3034 |
bool isEOF() const { return baseType == END_OF_FILE; } |
76 |
schoenebeck |
2885 |
bool isNewLine() const { return baseType == NEW_LINE; } |
77 |
|
|
bool isKeyword() const { return baseType == KEYWORD; } |
78 |
|
|
bool isVariableName() const { return baseType == VARIABLE_NAME; } |
79 |
|
|
bool isIdentifier() const { return baseType == IDENTIFIER; } |
80 |
|
|
bool isNumberLiteral() const { return baseType == NUMBER_LITERAL; } |
81 |
|
|
bool isStringLiteral() const { return baseType == STRING_LITERAL; } |
82 |
|
|
bool isComment() const { return baseType == COMMENT; } |
83 |
|
|
bool isPreprocessor() const { return baseType == PREPROCESSOR; } |
84 |
schoenebeck |
3562 |
bool isMetricPrefix() const { return baseType == METRIC_PREFIX; } |
85 |
|
|
bool isStdUnit() const { return baseType == STANDARD_UNIT; } |
86 |
schoenebeck |
2885 |
bool isOther() const { return baseType == OTHER; } |
87 |
|
|
|
88 |
|
|
// extended types |
89 |
|
|
bool isIntegerVariable() const { return extType == INTEGER_VARIABLE; } |
90 |
schoenebeck |
3573 |
bool isRealVariable() const { return extType == REAL_VARIABLE; } |
91 |
schoenebeck |
2885 |
bool isStringVariable() const { return extType == STRING_VARIABLE; } |
92 |
schoenebeck |
3573 |
bool isIntegerArrayVariable() const { return extType == INTEGER_ARRAY_VARIABLE; } |
93 |
|
|
bool isRealArrayVariable() const { return extType == REAL_ARRAY_VARIABLE; } |
94 |
schoenebeck |
2885 |
bool isEventHandlerName() const { return extType == EVENT_HANDLER_NAME; } |
95 |
|
|
|
96 |
|
|
operator bool() const { return baseType != END_OF_FILE; } |
97 |
|
|
|
98 |
|
|
bool equalsType(const SourceToken& other) const { |
99 |
|
|
return baseType == other.baseType && extType == other.extType; |
100 |
|
|
} |
101 |
|
|
}; |
102 |
|
|
|
103 |
|
|
} // namespace LinuxSampler |
104 |
|
|
|
105 |
|
|
#endif // CRUDEBYTE_CODE_TOKEN_H |