core/parser/tokenizer.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Avisynth v2.5. Copyright 2002 Ben Rudiak-Gould et al. | ||
| 2 | // http://avisynth.nl | ||
| 3 | |||
| 4 | // This program is free software; you can redistribute it and/or modify | ||
| 5 | // it under the terms of the GNU General Public License as published by | ||
| 6 | // the Free Software Foundation; either version 2 of the License, or | ||
| 7 | // (at your option) any later version. | ||
| 8 | // | ||
| 9 | // This program is distributed in the hope that it will be useful, | ||
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | // GNU General Public License for more details. | ||
| 13 | // | ||
| 14 | // You should have received a copy of the GNU General Public License | ||
| 15 | // along with this program; if not, write to the Free Software | ||
| 16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit | ||
| 17 | // http://www.gnu.org/copyleft/gpl.html . | ||
| 18 | // | ||
| 19 | // Linking Avisynth statically or dynamically with other modules is making a | ||
| 20 | // combined work based on Avisynth. Thus, the terms and conditions of the GNU | ||
| 21 | // General Public License cover the whole combination. | ||
| 22 | // | ||
| 23 | // As a special exception, the copyright holders of Avisynth give you | ||
| 24 | // permission to link Avisynth with independent modules that communicate with | ||
| 25 | // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license | ||
| 26 | // terms of these independent modules, and to copy and distribute the | ||
| 27 | // resulting combined work under terms of your choice, provided that | ||
| 28 | // every copy of the combined work is accompanied by a complete copy of | ||
| 29 | // the source code of Avisynth (the version of Avisynth used to produce the | ||
| 30 | // combined work), being distributed under the terms of the GNU General | ||
| 31 | // Public License plus this exception. An independent module is a module | ||
| 32 | // which is not derived from or based on Avisynth, such as 3rd-party filters, | ||
| 33 | // import and export plugins, or graphical user interfaces. | ||
| 34 | |||
| 35 | |||
| 36 | #ifndef __Tokenizer_H__ | ||
| 37 | #define __Tokenizer_H__ | ||
| 38 | |||
| 39 | #include <avisynth.h> | ||
| 40 | #include <vector> | ||
| 41 | |||
| 42 | /********************************************************* | ||
| 43 | *********************************************************/ | ||
| 44 | |||
| 45 | |||
| 46 | class Tokenizer | ||
| 47 | /** | ||
| 48 | * Breaks up scripts into tokens | ||
| 49 | **/ | ||
| 50 | { | ||
| 51 | public: | ||
| 52 | Tokenizer(const char* pc, IScriptEnvironment* _env); | ||
| 53 | explicit Tokenizer(Tokenizer* old); | ||
| 54 | |||
| 55 | void NextToken(); | ||
| 56 | |||
| 57 | // unlike AVSValue, these Is-of-Type checks are exact | ||
| 58 | 60 | inline bool IsIdentifier() const { return type == 'I'; } | |
| 59 | 126 | inline bool IsOperator() const { return type == 'o'; } | |
| 60 | 3 | inline bool IsInt() const { return type == 'i'; } | |
| 61 | 1 | inline bool IsFloat() const { return type == 'f'; } // means by double internally | |
| 62 | 1 | inline bool IsLong() const { return type == 'l'; } | |
| 63 | ✗ | inline bool IsString() const { return type == 's'; } | |
| 64 | #ifdef ARRAYS_AT_TOKENIZER_LEVEL | ||
| 65 | inline bool IsArray() const { return type == 'a'; } | ||
| 66 | #endif | ||
| 67 | 30 | inline bool IsNewline() const { return type == 'n'; } | |
| 68 | 18 | inline bool IsEOF() const { return type == 0; } | |
| 69 | |||
| 70 | bool IsIdentifier(const char* id) const; | ||
| 71 | 120 | inline bool IsOperator(int o) const | |
| 72 |
1/4✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 120 times.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
|
120 | { return IsOperator() && o == op; } |
| 73 | |||
| 74 | 3 | const char* AsIdentifier() const { AssertType('I'); return identifier; } | |
| 75 | ✗ | int AsOperator() const { AssertType('o'); return op; } | |
| 76 | 2 | int AsInt() const { AssertType('i'); return integer; } | |
| 77 | //float AsFloat() const { AssertType('f'); return floating_pt; } | ||
| 78 | 1 | double AsFloat() const { AssertType('f'); return double_pt; } // v11: using double internally | |
| 79 | ✗ | int64_t AsLong() const { AssertType('l'); return longlong; } | |
| 80 | ✗ | const char* AsString() const { AssertType('s'); return string; } | |
| 81 | #ifdef ARRAYS_AT_TOKENIZER_LEVEL | ||
| 82 | std::vector<AVSValue>* AsArray() const { AssertType('a'); return array2; } | ||
| 83 | #endif | ||
| 84 | |||
| 85 | 6 | int GetLine() const { return line; } | |
| 86 | int GetColumn(const char* start_of_string) const; | ||
| 87 | |||
| 88 | private: | ||
| 89 | void SkipWhitespace(); | ||
| 90 | void SkipNewline(); | ||
| 91 | void GetNumber(); | ||
| 92 | void AssertType(char expected_type) const; | ||
| 93 | void SetToOperator(int o); | ||
| 94 | |||
| 95 | IScriptEnvironment* const env; | ||
| 96 | const char* token_start; | ||
| 97 | const char* pc; | ||
| 98 | int line; | ||
| 99 | char type; // 'I'dentifier, 'o'perator, 'i'nt, 'f'loat, 's'tring, 'n'ewline, 'a'rray, 'l'ong, 0=eof. no 'd', float holds double | ||
| 100 | union | ||
| 101 | { | ||
| 102 | const char* identifier; | ||
| 103 | const char* string; | ||
| 104 | int op; // '+', '++', '.', ',', '(', ')','[', ']', 0=eoln | ||
| 105 | int integer; | ||
| 106 | //float floating_pt; replaced by double internally | ||
| 107 | int64_t longlong; // if it fits, integer is used instead (leave as much compatibility) | ||
| 108 | double double_pt; | ||
| 109 | #ifdef ARRAYS_AT_TOKENIZER_LEVEL | ||
| 110 | // not used now, finally arrays are implemented with helper script functions | ||
| 111 | std::vector<AVSValue>* array2; | ||
| 112 | #endif | ||
| 113 | }; | ||
| 114 | }; | ||
| 115 | |||
| 116 | |||
| 117 | |||
| 118 | /**** Helper functions ****/ | ||
| 119 | |||
| 120 | void ThrowTypeMismatch(char expected, char actual, IScriptEnvironment* env); | ||
| 121 | |||
| 122 | |||
| 123 | #endif // __Tokenizer_H__ | ||
| 124 |