Accept tabs as being equivalent to eight spaces, but no mixing on a single line
This commit is contained in:
parent
ee518f9643
commit
cdd3272d0e
@ -141,13 +141,7 @@ Blocks, including function `def` blocks and control flow structures like `if` an
|
||||
|
||||
You may indent blocks to whatever level you desire, so long as ordering remains consistent, though the recommendation indentation size is 4 spaces.
|
||||
|
||||
Tabs are not valid as indentation and will be ignored. It is recommended that you use an editor which provides a clear visual distinction between tabs and spaces, such as [Bim](https://github.com/klange/bim).
|
||||
|
||||
```py
|
||||
if False:
|
||||
print("Oh no, that was a tab.")
|
||||
# → Oh no, that was a tab.
|
||||
```
|
||||
It is recommended that you use an editor which provides a clear visual distinction between tabs and spaces, such as [Bim](https://github.com/klange/bim).
|
||||
|
||||
Blocks can also accept a single inline statement:
|
||||
|
||||
|
13
scanner.c
13
scanner.c
@ -86,18 +86,19 @@ static void skipWhitespace() {
|
||||
}
|
||||
|
||||
static KrkToken makeIndentation() {
|
||||
char reject = (peek() == ' ') ? '\t' : ' ';
|
||||
while (!isAtEnd() && (peek() == ' ' || peek() == '\t')) advance();
|
||||
if (isAtEnd()) return makeToken(TOKEN_EOF);
|
||||
if (peek() == '\n') {
|
||||
/* Pretend we didn't see this line */
|
||||
return makeToken(TOKEN_INDENTATION);
|
||||
for (const char * start = scanner.start; start < scanner.cur; start++) {
|
||||
if (*start == reject) return errorToken("Invalid mix of indentation.");
|
||||
}
|
||||
KrkToken out = makeToken(TOKEN_INDENTATION);
|
||||
if (reject == ' ') out.length *= 8;
|
||||
if (peek() == '#') {
|
||||
KrkToken out = makeToken(TOKEN_INDENTATION);
|
||||
/* Skip the entirety of the comment but not the line feed */
|
||||
while (!isAtEnd() && peek() != '\n') advance();
|
||||
return out;
|
||||
}
|
||||
return makeToken(TOKEN_INDENTATION);
|
||||
return out;
|
||||
}
|
||||
|
||||
static KrkToken string(char quoteMark) {
|
||||
|
@ -1,2 +1,2 @@
|
||||
960 lines
|
||||
954 lines
|
||||
['', 'Kuroko is a bytecode-interpreted, dynamic, strongly-typed language with syntax similar to Python.', '', 'The bytecode VM / compiler is substantially based on Robert Nystrom\'s [_Crafting Interpreters_](https://craftinginterpreters.com/).']
|
||||
|
5
test/testTabWidth.krk
Normal file
5
test/testTabWidth.krk
Normal file
@ -0,0 +1,5 @@
|
||||
def foo():
|
||||
print("Four spaces")
|
||||
print("Four tabs")
|
||||
|
||||
foo()
|
2
test/testTabWidth.krk.expect
Normal file
2
test/testTabWidth.krk.expect
Normal file
@ -0,0 +1,2 @@
|
||||
Four spaces
|
||||
Four tabs
|
Loading…
Reference in New Issue
Block a user