|
|
@@ -19,6 +19,7 @@ void lexer_read_char(struct lexer *l);
|
|
|
struct token lexer_next_token(struct lexer *l);
|
|
|
struct str lexer_read_ident(struct lexer *l);
|
|
|
enum token_type_enum lexer_lookup_ident(struct str ident);
|
|
|
+void lexer_skip_whitespace(struct lexer *l);
|
|
|
|
|
|
bool _lexer_is_letter(char c);
|
|
|
|
|
|
@@ -50,6 +51,8 @@ lexer_next_token(struct lexer *l)
|
|
|
{
|
|
|
struct token t = TOKEN_ILLEGAL;
|
|
|
|
|
|
+ lexer_skip_whitespace(l);
|
|
|
+
|
|
|
switch ( l->c ) {
|
|
|
case '=': t = token_create(TT_ASSIGN, str_from_cstr("=", 1)); break;
|
|
|
case ';': t = token_create(TT_SEMICOLON, str_from_cstr(";", 1)); break;
|
|
|
@@ -126,6 +129,22 @@ lexer_lookup_ident(struct str ident)
|
|
|
return TT_IDENT;
|
|
|
}
|
|
|
|
|
|
+void
|
|
|
+lexer_skip_whitespace(struct lexer *l)
|
|
|
+{
|
|
|
+loop:
|
|
|
+ switch ( l->c ) {
|
|
|
+ case ' ':
|
|
|
+ case '\t':
|
|
|
+ case '\r':
|
|
|
+ case '\n':
|
|
|
+ lexer_read_char(l);
|
|
|
+ goto loop;
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
bool
|
|
|
_lexer_is_letter(char c)
|
|
|
{
|