/[svn]/linuxsampler/trunk/src/scriptvm/editor/SourceToken.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/scriptvm/editor/SourceToken.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3034 - (hide annotations) (download) (as text)
Mon Oct 31 00:05:00 2016 UTC (7 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 3048 byte(s)
* Fixed a bunch of minor issues (mostly compiler warnings).
* Bumped version (2.0.0.svn31).

1 schoenebeck 2885 /*
2     * Copyright (c) 2015-2016 Christian Schoenebeck
3     *
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     OTHER, // anything else not classified here
32     };
33    
34     enum ExtType_t {
35     NO_EXT, ///< no extended type available for this token
36     INTEGER_VARIABLE,
37     STRING_VARIABLE,
38     ARRAY_VARIABLE,
39     EVENT_HANDLER_NAME // only NKSP language
40     };
41    
42     SourceToken() : baseType(END_OF_FILE), extType(NO_EXT), line(0), column(0) {
43     }
44    
45     SourceToken(BaseType_t t, String s = "") : baseType(t), extType(NO_EXT), txt(s), line(0), column(0) {
46     }
47    
48     SourceToken(ExtType_t t, String s = "") : baseType(OTHER), extType(t), txt(s), line(0), column(0) {
49     switch (t) {
50     case NO_EXT: baseType = OTHER; break;
51     case INTEGER_VARIABLE: baseType = VARIABLE_NAME; break;
52     case STRING_VARIABLE: baseType = VARIABLE_NAME; break;
53     case ARRAY_VARIABLE: baseType = VARIABLE_NAME; break;
54     case EVENT_HANDLER_NAME: baseType = IDENTIFIER; break;
55     }
56     }
57    
58     BaseType_t baseType;
59     ExtType_t extType;
60     String txt;
61     int line;
62     int column;
63    
64     String text() const { return txt; }
65     int firstLine() const { return line; }
66     int firstColumn() const { return column; }
67    
68     // base types
69 schoenebeck 3034 bool isEOF() const { return baseType == END_OF_FILE; }
70 schoenebeck 2885 bool isNewLine() const { return baseType == NEW_LINE; }
71     bool isKeyword() const { return baseType == KEYWORD; }
72     bool isVariableName() const { return baseType == VARIABLE_NAME; }
73     bool isIdentifier() const { return baseType == IDENTIFIER; }
74     bool isNumberLiteral() const { return baseType == NUMBER_LITERAL; }
75     bool isStringLiteral() const { return baseType == STRING_LITERAL; }
76     bool isComment() const { return baseType == COMMENT; }
77     bool isPreprocessor() const { return baseType == PREPROCESSOR; }
78     bool isOther() const { return baseType == OTHER; }
79    
80     // extended types
81     bool isIntegerVariable() const { return extType == INTEGER_VARIABLE; }
82     bool isStringVariable() const { return extType == STRING_VARIABLE; }
83     bool isArrayVariable() const { return extType == ARRAY_VARIABLE; }
84     bool isEventHandlerName() const { return extType == EVENT_HANDLER_NAME; }
85    
86     operator bool() const { return baseType != END_OF_FILE; }
87    
88     bool equalsType(const SourceToken& other) const {
89     return baseType == other.baseType && extType == other.extType;
90     }
91     };
92    
93     } // namespace LinuxSampler
94    
95     #endif // CRUDEBYTE_CODE_TOKEN_H

  ViewVC Help
Powered by ViewVC