1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 19:19:53 +00:00

Add keyword syntax for strings.

This commit is contained in:
bakpakin 2017-07-02 17:24:33 -04:00
parent e2c78b36d0
commit 268bd5f954
2 changed files with 10 additions and 2 deletions

View File

@ -238,11 +238,16 @@ static GstValue build_token(GstParser *p, GstBuffer *buf) {
if (buf->data[0] >= '0' && buf->data[0] <= '9') { if (buf->data[0] >= '0' && buf->data[0] <= '9') {
p_error(p, "symbols cannot start with digits"); p_error(p, "symbols cannot start with digits");
x.type = GST_NIL; x.type = GST_NIL;
} else {
if (buf->data[0] == ':' && buf->count >= 2) {
x.type = GST_STRING;
x.data.string = gst_string_b(p->vm, buf->data + 1, buf->count - 1);
} else { } else {
x.type = GST_SYMBOL; x.type = GST_SYMBOL;
x.data.string = gst_buffer_to_string(p->vm, buf); x.data.string = gst_buffer_to_string(p->vm, buf);
} }
} }
}
return x; return x;
} }

View File

@ -28,6 +28,7 @@
(assert (>= 6.0 5.0 4.0 4.0 3.0 2.0 1.0) "greater than or equal to reals") (assert (>= 6.0 5.0 4.0 4.0 3.0 2.0 1.0) "greater than or equal to reals")
(assert (< nil 1.0 1 false true "hi" (assert (< nil 1.0 1 false true "hi"
(quote hello)
(array 1 2 3) (array 1 2 3)
(tuple 1 2 3) (tuple 1 2 3)
(table "a" "b" "c" false) (table "a" "b" "c" false)
@ -43,6 +44,8 @@
(assert (= 7 (bor 3 4)) "bit or") (assert (= 7 (bor 3 4)) "bit or")
(assert (= 0 (band 3 4)) "bit and") (assert (= 0 (band 3 4)) "bit and")
(assert (= "hello" :hello) "keyword syntax for strings")
((fn [] ((fn []
(var accum 1) (var accum 1)
(var count 0) (var count 0)