1
0
Fork 0

Add line comments

This commit is contained in:
Alex Kotov 2023-05-06 19:55:45 +04:00
parent af6458a173
commit a46827abc5
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 48 additions and 23 deletions

View file

@ -74,7 +74,9 @@ void token_add(const Lexer lexer)
{
assert(lexer);
if (lexer->state != STATE_WHITESPACE) {
if (lexer->state != STATE_WHITESPACE &&
lexer->state != STATE_COMMENT_LINE)
{
enum TokenType token_type;
assert(State_to_token_type(lexer->state, &token_type));
@ -92,7 +94,9 @@ void Lexer_lex(const Lexer self, const char chr)
switch (self->state) {
case STATE_INIT:
if (chr == '(') {
if (chr == ';') {
self->state = STATE_COMMENT_LINE;
} else if (chr == '(') {
self->state = STATE_ROUND_OPEN;
buffer_add(self, chr);
} else if (chr == ')') {
@ -131,7 +135,9 @@ void Lexer_lex(const Lexer self, const char chr)
}
break;
case STATE_WHITESPACE:
if (chr == '(') {
if (chr == ';') {
self->state = STATE_COMMENT_LINE;
} else if (chr == '(') {
token_add(self);
self->state = STATE_ROUND_OPEN;
buffer_add(self, chr);
@ -179,6 +185,14 @@ void Lexer_lex(const Lexer self, const char chr)
assert(0);
}
break;
case STATE_COMMENT_LINE:
if (chr == '\n') {
token_add(self);
self->state = STATE_WHITESPACE;
} else {
buffer_add(self, chr);
}
break;
case STATE_ROUND_OPEN:
case STATE_ROUND_CLOSE:
case STATE_SQUARE_OPEN:
@ -186,7 +200,9 @@ void Lexer_lex(const Lexer self, const char chr)
case STATE_CURLY_OPEN:
case STATE_CURLY_CLOSE:
case STATE_QUOTE:
if (chr == '(') {
if (chr == ';') {
self->state = STATE_COMMENT_LINE;
} else if (chr == '(') {
token_add(self);
self->state = STATE_ROUND_OPEN;
buffer_add(self, chr);
@ -245,7 +261,9 @@ void Lexer_lex(const Lexer self, const char chr)
}
break;
case STATE_TAG:
if (chr == '(') {
if (chr == ';') {
self->state = STATE_COMMENT_LINE;
} else if (chr == '(') {
token_add(self);
self->state = STATE_ROUND_OPEN;
buffer_add(self, chr);
@ -283,7 +301,9 @@ void Lexer_lex(const Lexer self, const char chr)
}
break;
case STATE_IDENT:
if (chr == '(') {
if (chr == ';') {
self->state = STATE_COMMENT_LINE;
} else if (chr == '(') {
token_add(self);
self->state = STATE_ROUND_OPEN;
buffer_add(self, chr);
@ -321,7 +341,9 @@ void Lexer_lex(const Lexer self, const char chr)
}
break;
case STATE_NUM:
if (chr == '(') {
if (chr == ';') {
self->state = STATE_COMMENT_LINE;
} else if (chr == '(') {
token_add(self);
self->state = STATE_ROUND_OPEN;
buffer_add(self, chr);
@ -368,7 +390,9 @@ void Lexer_lex(const Lexer self, const char chr)
}
break;
case STATE_STRING_END:
if (chr == '(') {
if (chr == ';') {
self->state = STATE_COMMENT_LINE;
} else if (chr == '(') {
self->state = STATE_ROUND_OPEN;
buffer_add(self, chr);
} else if (chr == ')') {

View file

@ -16,6 +16,7 @@
enum Lexer_State {
STATE_INIT,
STATE_WHITESPACE,
STATE_COMMENT_LINE,
STATE_ROUND_OPEN,
STATE_ROUND_CLOSE,
STATE_SQUARE_OPEN,

View file

@ -23,8 +23,8 @@
(displayln '#true)
(displayln (quote #false))
(displayln '#false)
'(displayln (quote "#\n"))
'(displayln '"#\n")
;(displayln (quote #\n))
;(displayln '#\n)
(displayln (quote foo))
(displayln 'foo)
(displayln (quote "foo"))
@ -39,8 +39,8 @@
(displayln "--- TEST: arcane/tokenize --------------------------------------")
(displayln (arcane/tokenize "("))
(displayln (arcane/tokenize "#false"))
'(displayln (arcane/tokenize "''"))
'(displayln (arcane/tokenize "'qwe'"))
;(displayln (arcane/tokenize "\"\""))
;(displayln (arcane/tokenize "\"qwe\""))
(displayln (arcane/tokenize "(displayln (list 1))"))
(newline)
(displayln "--- TEST: arcane/typeof ----------------------------------------")
@ -48,7 +48,7 @@
(displayln (arcane/typeof +))
(displayln (arcane/typeof (cons 123 456)))
(displayln (arcane/typeof #false))
'(displayln (arcane/typeof "#\n"))
;(displayln (arcane/typeof #\n))
(displayln (arcane/typeof 'foo))
(displayln (arcane/typeof "foo"))
(displayln (arcane/typeof 123))
@ -73,7 +73,7 @@
(displayln (boolean? '()))
(displayln (boolean? #true))
(displayln (boolean? #false))
'(displayln (boolean? "#\n"))
;(displayln (boolean? #\n))
(displayln (boolean? 'foo))
(displayln (boolean? "foo"))
(displayln (boolean? 123))
@ -84,7 +84,7 @@
(displayln (char? '()))
(displayln (char? #true))
(displayln (char? #false))
'(displayln (char? "#\n"))
;(displayln (char? #\n))
(displayln (char? 'foo))
(displayln (char? "foo"))
(displayln (char? 123))
@ -95,7 +95,7 @@
(displayln (null? '()))
(displayln (null? #true))
(displayln (null? #false))
'(displayln (null? "#\n"))
;(displayln (null? #\n))
(displayln (null? 'foo))
(displayln (null? "foo"))
(displayln (null? 123))
@ -106,7 +106,7 @@
(displayln (number? '()))
(displayln (number? #true))
(displayln (number? #false))
'(displayln (number? "#\n"))
;(displayln (number? #\n))
(displayln (number? 'foo))
(displayln (number? "foo"))
(displayln (number? 123))
@ -117,7 +117,7 @@
(displayln (pair? '()))
(displayln (pair? #true))
(displayln (pair? #false))
'(displayln (pair? "#\n"))
;(displayln (pair? #\n))
(displayln (pair? 'foo))
(displayln (pair? "foo"))
(displayln (pair? 123))
@ -128,7 +128,7 @@
(displayln (procedure? '()))
(displayln (procedure? #true))
(displayln (procedure? #false))
'(displayln (procedure? "#\n"))
;(displayln (procedure? #\n))
(displayln (procedure? 'foo))
(displayln (procedure? "foo"))
(displayln (procedure? 123))
@ -139,7 +139,7 @@
(displayln (string? '()))
(displayln (string? #true))
(displayln (string? #false))
'(displayln (string? "#\n"))
;(displayln (string? #\n))
(displayln (string? 'foo))
(displayln (string? "foo"))
(displayln (string? 123))
@ -150,7 +150,7 @@
(displayln (symbol? '()))
(displayln (symbol? #true))
(displayln (symbol? #false))
'(displayln (symbol? "#\n"))
;(displayln (symbol? #\n))
(displayln (symbol? 'foo))
(displayln (symbol? "foo"))
(displayln (symbol? 123))
@ -160,7 +160,7 @@
(newline)
(displayln "--- TEST: number->string ---------------------------------------")
(displayln (number->string 123))
'(displayln (number->string "-123"))
;(displayln (number->string -123))
(displayln (number->string 123456 16))
(newline)
(displayln "--- TEST: string->symbol ---------------------------------------")
@ -177,7 +177,7 @@
(displayln (not '()))
(displayln (not #true))
(displayln (not #false))
'(displayln (not "#\n"))
;(displayln (not #\n))
(displayln (not 'foo))
(displayln (not "foo"))
(displayln (not 123))