Skip to content

Commit 3dae8c9

Browse files
committed
added support for indenting with 4 spaces
1 parent 40429f9 commit 3dae8c9

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

.mog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import (
2-
src as up
2+
src as up
33
)
44

55
v_path = [which v]
@@ -9,7 +9,7 @@ default:
99

1010
@desc(run mog, this is kinda circular)
1111
run:
12-
v run .
12+
v run .
1313

1414
@desc(run mog with debug output)
1515
run_trace:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A simple task runner
44

5-
Define your tasks in a `.mog` file and run them with the `mog` command. Indentation is done with the tab character. Define a task named 'default' to be ran when `mog` is called without a task name.
5+
Define your tasks in a `.mog` file and run them with the `mog` command. Indentation is done with the tab character or 4 spaces. Define a task named 'default' to be ran when `mog` is called without a task name.
66

77

88
## Features

src/another/.mog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
test:
22
echo in another
3-
pwd
3+
pwd

src/lexer.v

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,36 @@ fn (mut l Lexer) eat_word() !Token {
171171
return error('Unkown syntax error at line ${l.line} : col ${l.column}')
172172
}
173173

174+
fn (mut l Lexer) is_indent() bool {
175+
if l.current_char == '\n' {
176+
if l.peek() == indent {
177+
return true
178+
}
179+
if l.peek() == ' ' && l.peek(num: 2) == ' ' && l.peek(num: 3) == ' ' && l.peek(num: 4) == ' ' {
180+
return true
181+
}
182+
}
183+
if l.current_char == indent {
184+
return true
185+
}
186+
if l.current_char == ' ' && l.peek() == ' ' && l.peek(num: 2) == ' ' && l.peek(num: 3) == ' ' {
187+
return true
188+
}
189+
return false
190+
}
191+
174192
fn (mut l Lexer) eat_command_body() !Token {
175193
if l.current_char == '' || l.peek() == '' {
176194
l.end_of_file()
177195
return l.make_token(.eof, 'EOF')
178196
}
179197
if l.current_char == '\n' {
180-
if l.peek() == '\n' || l.peek() != indent {
198+
if l.peek() == '\n' || !l.is_indent() {
181199
l.context = .root
182200
}
183201
return l.eat_newline()
184202
}
185-
if l.current_char != indent {
203+
if !l.is_indent() {
186204
l.context = .root
187205
return error('no indent')
188206
}
@@ -311,7 +329,7 @@ fn (mut l Lexer) get_next_token() ![]Token {
311329
return [l.make_token(.eof, 'EOF')]
312330
}
313331

314-
if l.current_char == ' ' {
332+
if l.current_char == ' ' && l.context != .command_block {
315333
l.skip_whitespace()
316334
}
317335

v.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Module {
22
name: 'mog'
33
description: 'A simple task runner'
4-
version: '1.3.0'
4+
version: '1.4.0'
55
license: 'MIT'
66
dependencies: []
77
}

0 commit comments

Comments
 (0)