test 7
This commit is contained in:
parent
2be4542c1b
commit
ced10cf298
5 changed files with 14 additions and 7 deletions
10
src/lexer.l
10
src/lexer.l
|
|
@ -13,7 +13,8 @@
|
||||||
^[ \t]*\r?\n { /* Ignore lines containing whitespace only */ }
|
^[ \t]*\r?\n { /* Ignore lines containing whitespace only */ }
|
||||||
^[ \t]*#.*\n { /* Ignore comment-only lines */ }
|
^[ \t]*#.*\n { /* Ignore comment-only lines */ }
|
||||||
|
|
||||||
^[ \t]+ {
|
|
||||||
|
^[ \t]* {
|
||||||
int col = indent_stack.calculateColumn(yytext, yyleng);
|
int col = indent_stack.calculateColumn(yytext, yyleng);
|
||||||
auto action = indent_stack.updateIndentation(col);
|
auto action = indent_stack.updateIndentation(col);
|
||||||
|
|
||||||
|
|
@ -21,6 +22,13 @@
|
||||||
if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT;
|
if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
^. {
|
||||||
|
// Line starts with non-whitespace (column 0)
|
||||||
|
auto action = indent_stack.updateIndentation(0);
|
||||||
|
yyless(0);
|
||||||
|
if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT;
|
||||||
|
}
|
||||||
|
|
||||||
\n { return yy::parser::token::TOK_NEWLINE; }
|
\n { return yy::parser::token::TOK_NEWLINE; }
|
||||||
|
|
||||||
def { return yy::parser::token::TOK_KW_DEF; }
|
def { return yy::parser::token::TOK_KW_DEF; }
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,6 @@ def calculate(a, b=10):
|
||||||
if result > 100:
|
if result > 100:
|
||||||
print("Large result:", result)
|
print("Large result:", result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# This is a comment
|
# this is a comment
|
||||||
x = calculate(5, 15)
|
x = calculate(5, 15)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ KW_RETURN
|
||||||
IDENTIFIER result
|
IDENTIFIER result
|
||||||
NEWLINE
|
NEWLINE
|
||||||
DEDENT
|
DEDENT
|
||||||
NEWLINE
|
|
||||||
IDENTIFIER x
|
IDENTIFIER x
|
||||||
ASSIGN
|
ASSIGN
|
||||||
IDENTIFIER calculate
|
IDENTIFIER calculate
|
||||||
|
|
@ -49,4 +48,4 @@ COMMA
|
||||||
NUMBER 15
|
NUMBER 15
|
||||||
R_PAREN
|
R_PAREN
|
||||||
NEWLINE
|
NEWLINE
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -18,4 +18,4 @@ IDENTIFIER very_long_variable_name_123
|
||||||
ASSIGN
|
ASSIGN
|
||||||
STRING "test"
|
STRING "test"
|
||||||
NEWLINE
|
NEWLINE
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -16,4 +16,4 @@ NEWLINE
|
||||||
KW_NOT
|
KW_NOT
|
||||||
IDENTIFIER flag
|
IDENTIFIER flag
|
||||||
NEWLINE
|
NEWLINE
|
||||||
EOF
|
EOF
|
||||||
Loading…
Add table
Add a link
Reference in a new issue