|
6 | 6 | #include <iostream> |
7 | 7 | #include "CANDatabaseException.h" |
8 | 8 |
|
9 | | -void throwError(const std::string& category, const std::string& description, |
10 | | - unsigned long long line) { |
11 | | - throw CANDatabaseException( |
12 | | - category + ": " + description + " at line " + std::to_string(line + 1) |
13 | | - ); |
14 | | -} |
| 9 | +void throw_error(const std::string& category, const std::string& description, |
| 10 | + unsigned long long line); |
15 | 11 |
|
16 | | -void warning(const std::string& description, unsigned long long line) { |
17 | | - std::cerr << "WARNING: " |
18 | | - << description |
19 | | - << " at line " |
20 | | - << line + 1 |
21 | | - << std::endl; |
22 | | -} |
| 12 | +void warning(const std::string& description, unsigned long long line) ; |
23 | 13 |
|
24 | | -void skipIf(Tokenizer& tokenizer, const std::string& token) { |
25 | | - if(tokenizer.getNextToken() == token) |
26 | | - return; |
| 14 | +const Token& |
| 15 | +assert_token(Tokenizer& tokenizer, const std::string& token); |
27 | 16 |
|
28 | | - throwError( |
29 | | - "Syntax error", |
30 | | - "expected \"" + token + "\" but got \"" + |
31 | | - tokenizer.getCurrentToken().image + "\"", |
32 | | - tokenizer.lineCount() |
33 | | - ); |
34 | | -} |
| 17 | +const Token& |
| 18 | +assert_token(Tokenizer& tokenizer, Token::Type targetType); |
35 | 19 |
|
36 | | -void assertToken(const Tokenizer& tokenizer, const std::string& token) { |
37 | | - if(tokenizer.getCurrentToken() == token) |
38 | | - return; |
| 20 | +const Token& |
| 21 | +assert_current_token(const Tokenizer& tokenizer, const std::string& token); |
39 | 22 |
|
40 | | - throwError( |
41 | | - "Syntax error", |
42 | | - "expected \"" + token + "\" but got \"" + |
43 | | - tokenizer.getCurrentToken().image + "\"", |
44 | | - tokenizer.lineCount() |
45 | | - ); |
46 | | -} |
| 23 | +const Token& |
| 24 | +assert_current_token(const Tokenizer& tokenizer, Token::Type type); |
47 | 25 |
|
| 26 | +bool is_current_token(const Tokenizer& tokenizer, const std::string& token); |
48 | 27 |
|
49 | | -Token checkCurrentTokenType(const Token& toCheck, Token::Type targetType, |
50 | | - unsigned long long line) { |
51 | | - if(toCheck == targetType) |
52 | | - return toCheck; |
| 28 | +bool is_current_token(const Tokenizer& tokenizer, Token::Type token); |
53 | 29 |
|
54 | | - throwError( |
55 | | - "Syntax error", |
56 | | - "unexpected \"" + toCheck.image + "\"", |
57 | | - line |
58 | | - ); |
| 30 | +bool is_token(Tokenizer& tokenizer, const std::string& token); |
59 | 31 |
|
60 | | - // Removes a compilation warning |
61 | | - return toCheck; |
62 | | -} |
| 32 | +bool is_token(Tokenizer& tokenizer, Token::Type token); |
63 | 33 |
|
64 | | -Token checkCurrentTokenType(const Token& toCheck, |
65 | | - const std::string& token, |
66 | | - unsigned long long line) { |
67 | | - if(toCheck == token) |
68 | | - return toCheck; |
69 | | - |
70 | | - throwError( |
71 | | - "Syntax error", |
72 | | - "unexpected \"" + toCheck.image + "\"", |
73 | | - line |
74 | | - ); |
75 | | - |
76 | | - // Removes a compilation warning |
77 | | - return toCheck; |
78 | | -} |
79 | | - |
80 | | -Token checkTokenType(Tokenizer& tokenizer, Token::Type targetType) { |
81 | | - return checkCurrentTokenType(tokenizer.getNextToken(), |
82 | | - targetType, |
83 | | - tokenizer.lineCount()); |
84 | | -} |
85 | 34 | #endif |
0 commit comments