24
24
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
25
*/
26
26
27
- // #define CPP_DEBUG
28
-
29
27
#ifdef CPP_DEBUG
30
28
# define DEBUG_SPAM
31
29
#endif
32
30
33
31
#include " Parser.h"
34
32
#include " AK/LogStream.h"
35
33
#include " AST.h"
34
+ #include < AK/Debug.h>
36
35
#include < AK/ScopeGuard.h>
37
36
#include < AK/ScopeLogger.h>
38
37
#include < LibCpp/Lexer.h>
@@ -49,7 +48,7 @@ Parser::Parser(const StringView& program)
49
48
continue ;
50
49
m_tokens.append (move (token));
51
50
}
52
- #ifdef CPP_DEBUG
51
+ #if CPP_DEBUG
53
52
dbgln (" Program:" );
54
53
dbgln (" {}" , m_program);
55
54
dbgln (" Tokens:" );
@@ -229,10 +228,12 @@ bool Parser::match_variable_declaration()
229
228
save_state ();
230
229
ScopeGuard state_guard = [this ] { load_state (); };
231
230
231
+ // Type
232
232
if (!peek (Token::Type::KnownType).has_value () && !peek (Token::Type::Identifier).has_value ())
233
233
return false ;
234
234
consume ();
235
235
236
+ // Identifier
236
237
if (!peek (Token::Type::Identifier).has_value ())
237
238
return false ;
238
239
consume ();
@@ -243,9 +244,10 @@ bool Parser::match_variable_declaration()
243
244
error (" initial value of variable is not an expression" );
244
245
return false ;
245
246
}
247
+ return true ;
246
248
}
247
249
248
- return true ;
250
+ return match (Token::Type::Semicolon) ;
249
251
}
250
252
251
253
NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration (ASTNode& parent)
@@ -706,7 +708,7 @@ void Parser::error(StringView message)
706
708
m_tokens[m_state.token_index ].m_start .column );
707
709
}
708
710
m_errors.append (formatted_message);
709
- dbgln (" {}" , formatted_message);
711
+ dbgln<CPP_DEBUG> (" {}" , formatted_message);
710
712
}
711
713
712
714
bool Parser::match_expression ()
@@ -1019,5 +1021,4 @@ NonnullRefPtr<IfStatement> Parser::parse_if_statement(ASTNode& parent)
1019
1021
}
1020
1022
return if_statement;
1021
1023
}
1022
-
1023
1024
}
0 commit comments