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 |
|
|
#include <iostream> |
11 |
|
|
#include <sstream> |
12 |
|
|
#include <vector> |
13 |
|
|
#include "SourceToken.h" |
14 |
|
|
|
15 |
|
|
#ifndef CRUDEBYTE_CODE_SCANNER_H |
16 |
|
|
#define CRUDEBYTE_CODE_SCANNER_H |
17 |
|
|
|
18 |
|
|
namespace LinuxSampler { |
19 |
|
|
|
20 |
|
|
class CodeScanner { |
21 |
|
|
public: |
22 |
|
|
void* scanner; |
23 |
|
|
std::istream* is; |
24 |
|
|
SourceToken token; |
25 |
|
|
int line; |
26 |
|
|
int column; |
27 |
schoenebeck |
3729 |
int offset; |
28 |
|
|
int length; |
29 |
schoenebeck |
2885 |
|
30 |
|
|
CodeScanner(std::istream* is); |
31 |
|
|
virtual ~CodeScanner(); |
32 |
|
|
std::vector<SourceToken> tokens() const { return m_tokens; } |
33 |
|
|
bool isMultiLine() const; |
34 |
|
|
|
35 |
|
|
protected: |
36 |
|
|
std::vector<SourceToken> m_tokens; |
37 |
|
|
|
38 |
|
|
virtual int processScanner() = 0; |
39 |
|
|
SourceToken processOneToken(); |
40 |
|
|
void processAll(); |
41 |
|
|
void trim(); |
42 |
|
|
}; |
43 |
|
|
|
44 |
|
|
// base types |
45 |
|
|
#define EofToken() SourceToken() |
46 |
|
|
#define NewLineToken() SourceToken(SourceToken::NEW_LINE, "\n") |
47 |
|
|
#define KeywordToken(s) SourceToken(SourceToken::KEYWORD, s) |
48 |
|
|
#define VariableNameToken(s) SourceToken(SourceToken::VARIABLE_NAME, s) |
49 |
|
|
#define IdentifierToken(s) SourceToken(SourceToken::IDENTIFIER, s) |
50 |
|
|
#define NumberLiteralToken(s) SourceToken(SourceToken::NUMBER_LITERAL, s) |
51 |
|
|
#define StringLiteralToken(s) SourceToken(SourceToken::STRING_LITERAL, s) |
52 |
|
|
#define CommentToken(s) SourceToken(SourceToken::COMMENT, s) |
53 |
|
|
#define PreprocessorToken(s) SourceToken(SourceToken::PREPROCESSOR, s) |
54 |
schoenebeck |
3591 |
#define MetricPrefixToken(s) SourceToken(SourceToken::METRIC_PREFIX, s) |
55 |
schoenebeck |
3562 |
#define StdUnitToken(s) SourceToken(SourceToken::STANDARD_UNIT, s) |
56 |
schoenebeck |
2885 |
#define OtherToken(s) SourceToken(SourceToken::OTHER, s) |
57 |
|
|
|
58 |
|
|
// extended types |
59 |
|
|
#define IntegerVariableToken(s) SourceToken(SourceToken::INTEGER_VARIABLE, s) |
60 |
schoenebeck |
3573 |
#define RealVariableToken(s) SourceToken(SourceToken::REAL_VARIABLE, s) |
61 |
schoenebeck |
2885 |
#define StringVariableToken(s) SourceToken(SourceToken::STRING_VARIABLE, s) |
62 |
schoenebeck |
3573 |
#define IntegerArrayVariableToken(s) SourceToken(SourceToken::INTEGER_ARRAY_VARIABLE, s) |
63 |
|
|
#define RealArrayVariableToken(s) SourceToken(SourceToken::REAL_ARRAY_VARIABLE, s) |
64 |
schoenebeck |
2885 |
#define EventHandlerNameToken(s) SourceToken(SourceToken::EVENT_HANDLER_NAME, s) |
65 |
|
|
|
66 |
|
|
} // namespace LinuxSampler |
67 |
|
|
|
68 |
|
|
#endif // CRUDEBYTE_CODE_SCANNER_H |