mirror of
https://github.com/janet-lang/janet
synced 2025-01-11 16:10:27 +00:00
Add # comments to parser
This commit is contained in:
parent
171c0ce49e
commit
740367ec5c
26
core/parse.c
26
core/parse.c
@ -407,7 +407,29 @@ static int form_state(GstParser *p, uint8_t c) {
|
|||||||
/* Handle a character */
|
/* Handle a character */
|
||||||
void gst_parse_byte(GstParser *p, uint8_t c) {
|
void gst_parse_byte(GstParser *p, uint8_t c) {
|
||||||
int done = 0;
|
int done = 0;
|
||||||
++p->index;
|
/* Update position in source */
|
||||||
|
if (c == '\n') {
|
||||||
|
p->line++;
|
||||||
|
p->index = 0;
|
||||||
|
p->comment = GST_PCOMMENT_EXPECTING;
|
||||||
|
} else {
|
||||||
|
++p->index;
|
||||||
|
}
|
||||||
|
/* Check comments */
|
||||||
|
switch (p->comment) {
|
||||||
|
case GST_PCOMMENT_NOT:
|
||||||
|
break;
|
||||||
|
case GST_PCOMMENT_EXPECTING:
|
||||||
|
if (c == '#') {
|
||||||
|
p->comment = GST_PCOMMENT_INSIDE;
|
||||||
|
return;
|
||||||
|
} else if (!is_whitespace(c)) {
|
||||||
|
p->comment = GST_PCOMMENT_NOT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GST_PCOMMENT_INSIDE:
|
||||||
|
return;
|
||||||
|
}
|
||||||
/* Dispatch character to state */
|
/* Dispatch character to state */
|
||||||
while (!done) {
|
while (!done) {
|
||||||
GstParseState *top = parser_peek(p);
|
GstParseState *top = parser_peek(p);
|
||||||
@ -478,8 +500,10 @@ void gst_parser(GstParser *p, Gst *vm) {
|
|||||||
p->data = data;
|
p->data = data;
|
||||||
p->count = 0;
|
p->count = 0;
|
||||||
p->index = 0;
|
p->index = 0;
|
||||||
|
p->line = 1;
|
||||||
p->quoteCount = 0;
|
p->quoteCount = 0;
|
||||||
p->error = NULL;
|
p->error = NULL;
|
||||||
p->status = GST_PARSER_ROOT;
|
p->status = GST_PARSER_ROOT;
|
||||||
p->value.type = GST_NIL;
|
p->value.type = GST_NIL;
|
||||||
|
p->comment = GST_PCOMMENT_EXPECTING;
|
||||||
}
|
}
|
@ -53,7 +53,8 @@
|
|||||||
|
|
||||||
(assert (= (struct 1 2 3 4 5 6 7 8) (struct 7 8 5 6 3 4 1 2)) "struct order does not matter")
|
(assert (= (struct 1 2 3 4 5 6 7 8) (struct 7 8 5 6 3 4 1 2)) "struct order does not matter")
|
||||||
|
|
||||||
"Serialization tests"
|
# Serialization tests
|
||||||
|
|
||||||
(def scheck (fn [x]
|
(def scheck (fn [x]
|
||||||
(def dat (serialize x))
|
(def dat (serialize x))
|
||||||
(def deser (deserialize dat))
|
(def deser (deserialize dat))
|
||||||
@ -80,7 +81,7 @@
|
|||||||
(assert (= athread-result "hello, world!") "thread error result")
|
(assert (= athread-result "hello, world!") "thread error result")
|
||||||
(assert (= (status athread) "error") "thread error status")
|
(assert (= (status athread) "error") "thread error status")
|
||||||
|
|
||||||
"yield tests"
|
# yield tests
|
||||||
|
|
||||||
(def t (thread (fn [] (tran nil 1) (tran nil 2) 3)))
|
(def t (thread (fn [] (tran nil 1) (tran nil 2) 3)))
|
||||||
|
|
||||||
@ -89,7 +90,7 @@
|
|||||||
(assert (= 3 (tran t)) "return from thread")
|
(assert (= 3 (tran t)) "return from thread")
|
||||||
(assert (= (status t) "dead") "finished thread is dead")
|
(assert (= (status t) "dead") "finished thread is dead")
|
||||||
|
|
||||||
"report"
|
# report
|
||||||
|
|
||||||
(print num-tests-passed "of" num-tests-run "tests passed")
|
(print num-tests-passed "of" num-tests-run "tests passed")
|
||||||
(exit! 0)
|
(exit! 0)
|
@ -360,6 +360,7 @@ struct GstParser {
|
|||||||
uint32_t count;
|
uint32_t count;
|
||||||
uint32_t cap;
|
uint32_t cap;
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
|
uint32_t line;
|
||||||
uint32_t quoteCount;
|
uint32_t quoteCount;
|
||||||
enum {
|
enum {
|
||||||
GST_PARSER_PENDING = 0,
|
GST_PARSER_PENDING = 0,
|
||||||
@ -367,6 +368,11 @@ struct GstParser {
|
|||||||
GST_PARSER_ERROR,
|
GST_PARSER_ERROR,
|
||||||
GST_PARSER_ROOT
|
GST_PARSER_ROOT
|
||||||
} status;
|
} status;
|
||||||
|
enum {
|
||||||
|
GST_PCOMMENT_NOT,
|
||||||
|
GST_PCOMMENT_EXPECTING,
|
||||||
|
GST_PCOMMENT_INSIDE
|
||||||
|
} comment;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Compilation state */
|
/* Compilation state */
|
||||||
|
Loading…
Reference in New Issue
Block a user