Skip to content

Commit

Permalink
various fixenings
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 8, 2023
1 parent 50b4d34 commit 65e0498
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
7 changes: 4 additions & 3 deletions doc/syntax-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ Jou has a few different kinds of tokens:
- `continue`
- `True`
- `False`
- `None`
- `NULL`
- `self`
- `void`
- `noreturn`
- `and`
- `or`
- `not`
- `self`
- `as`
- `sizeof`
- `assert`
- `void`
- `noreturn`
- `bool`
- `byte`
- `short`
Expand Down
7 changes: 3 additions & 4 deletions self_hosted/tokenizer.jou
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ def is_keyword(word: byte*) -> bool:
# - syntax documentation
keywords = [
"import", "def", "declare", "class", "union", "enum", "global",
"return", "if", "elif", "else", "while", "for", "break", "continue", "pass",
"True", "False", "NULL", "self",
"and", "or", "not", "as", "sizeof", "assert",
"void", "noreturn",
"return", "if", "elif", "else", "while", "for", "pass", "break", "continue",
"True", "False", "None", "NULL", "void", "noreturn",
"and", "or", "not", "self", "as", "sizeof", "assert",
"bool", "byte", "short", "int", "long", "float", "double",
]

Expand Down
3 changes: 3 additions & 0 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static AstType parse_type(ParserState *ps)
AstType result = { .kind = AST_TYPE_NAMED, .location = ps->tokens->location };

if (ps->tokens->type != TOKEN_NAME
&& !is_keyword(ps->tokens, "None")
&& !is_keyword(ps->tokens, "void")
&& !is_keyword(ps->tokens, "noreturn")
&& !is_keyword(ps->tokens, "short")
Expand Down Expand Up @@ -459,6 +460,8 @@ static AstExpression parse_elementary_expression(ParserState *ps)
expr.kind = AST_EXPR_GET_VARIABLE;
strcpy(expr.data.varname, "self");
ps->tokens++;
} else if (is_keyword(ps->tokens, "None")) {
fail(ps->tokens[0].location, "None is not a value in Jou, use e.g. -1 for numbers or NULL for pointers");
} else {
goto not_an_expression;
}
Expand Down
7 changes: 3 additions & 4 deletions src/tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,9 @@ static bool is_keyword(const char *s)
// - self-hosted compiler
// - syntax documentation
"import", "def", "declare", "class", "union", "enum", "global",
"return", "if", "elif", "else", "while", "for", "break", "continue",
"True", "False", "NULL", "self",
"and", "or", "not", "as", "sizeof", "assert", "pass",
"void", "noreturn",
"return", "if", "elif", "else", "while", "for", "pass", "break", "continue",
"True", "False", "None", "NULL", "void", "noreturn",
"and", "or", "not", "self", "as", "sizeof", "assert",
"bool", "byte", "short", "int", "long", "float", "double",
};
for (const char **kw = &keywords[0]; kw < &keywords[sizeof(keywords)/sizeof(keywords[0])]; kw++)
Expand Down
2 changes: 2 additions & 0 deletions tests/syntax_error/None_as_value.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def foo() -> None:
x = None # Error: None is not a value in Jou, use e.g. -1 for numbers or NULL for pointers
4 changes: 4 additions & 0 deletions tests/syntax_error/assign_to_None.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def foo() -> None:
# error message is kinda weird, but IMO it's ok.
# Not many people will run into this. It's not tempting for a Python programmer.
None = 123 # Error: None is not a value in Jou, use e.g. -1 for numbers or NULL for pointers

0 comments on commit 65e0498

Please sign in to comment.