shell: comments

This commit is contained in:
Kartik K. Agaram 2021-04-29 23:48:36 -07:00
parent 24883b04f5
commit d46c4b06b2
1 changed files with 47 additions and 0 deletions

View File

@ -18,6 +18,9 @@ fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace)
populate-stream dest-ah, 0x100/max-definition-size
#
next-token in, token, trace
var skip?/eax: boolean <- comment-token? token
compare skip?, 0/false
loop-if-!=
var error?/eax: boolean <- has-errors? trace
compare error?, 0/false
{
@ -129,6 +132,13 @@ fn next-token in: (addr gap-buffer), _out-cell: (addr cell), trace: (addr trace)
write-int32-hex stream, gval
trace trace, "read", stream
}
# comment
{
compare g, 0x23/comment
break-if-!=
rest-of-line in, out, trace
break $next-token:body
}
# digit
{
var digit?/eax: boolean <- decimal-digit? g
@ -339,6 +349,29 @@ fn next-bracket-token g: grapheme, out: (addr stream byte), trace: (addr trace)
trace trace, "read", stream
}
fn rest-of-line in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) {
trace-text trace, "read", "comment"
{
var empty?/eax: boolean <- gap-buffer-scan-done? in
compare empty?, 0/false
{
break-if-=
return
}
var g/eax: grapheme <- read-from-gap-buffer in
compare g, 0xa/newline
break-if-=
write-grapheme out, g
loop
}
var stream-storage: (stream byte 0x80)
var stream/esi: (addr stream byte) <- address stream-storage
write stream, "=> "
rewind-stream out
write-stream stream, out
trace trace, "read", stream
}
fn symbol-grapheme? g: grapheme -> _/eax: boolean {
## whitespace
compare g, 9/tab
@ -750,3 +783,17 @@ fn stream-token? _in: (addr cell) -> _/eax: boolean {
}
return 1/true
}
fn comment-token? _in: (addr cell) -> _/eax: boolean {
var in/eax: (addr cell) <- copy _in
var in-data-ah/eax: (addr handle stream byte) <- get in, text-data
var in-data/eax: (addr stream byte) <- lookup *in-data-ah
rewind-stream in-data
var g/eax: grapheme <- read-grapheme in-data
compare g, 0x23/hash
{
break-if-=
return 0/false
}
return 1/true
}