mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 08:20:27 +00:00
Add parser/insert and bump to 0.4.0
This commit is contained in:
parent
0c950d0846
commit
4bcf6565cd
@ -2,6 +2,7 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## 0.4.0 - ??
|
## 0.4.0 - ??
|
||||||
|
- Add parser/insert to modify parser state programmatically
|
||||||
- Add debug/stacktrace for easy, pretty stacktraces
|
- Add debug/stacktrace for easy, pretty stacktraces
|
||||||
- Remove the status-pp function
|
- Remove the status-pp function
|
||||||
- Update API to run-context to be much more sane
|
- Update API to run-context to be much more sane
|
||||||
|
@ -1393,12 +1393,14 @@ value, one key will be ignored."
|
|||||||
where
|
where
|
||||||
" around byte "
|
" around byte "
|
||||||
(string (parser/where p))
|
(string (parser/where p))
|
||||||
(or (parser/error p) "unmatched delimiter")))
|
": "
|
||||||
|
(or (parser/error p) "unmatched delimiter")
|
||||||
|
"\n"))
|
||||||
|
|
||||||
(defn bad-compile
|
(defn bad-compile
|
||||||
"Default handler for a compile error."
|
"Default handler for a compile error."
|
||||||
[msg macrof where]
|
[msg macrof where]
|
||||||
(file/write stderr msg " while compiling " where "\n")
|
(file/write stderr "compile error: " msg " while compiling " where "\n")
|
||||||
(when macrof (debug/stacktrace macrof)))
|
(when macrof (debug/stacktrace macrof)))
|
||||||
|
|
||||||
(defn getline
|
(defn getline
|
||||||
|
@ -649,6 +649,39 @@ static Janet cfun_parse_consume(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_integer(i);
|
return janet_wrap_integer(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Janet cfun_parse_insert(int32_t argc, Janet *argv) {
|
||||||
|
janet_fixarity(argc, 2);
|
||||||
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
|
JanetParseState *s = p->states + p->statecount - 1;
|
||||||
|
if (s->consumer == tokenchar) {
|
||||||
|
janet_parser_consume(p, ' ');
|
||||||
|
p->offset--;
|
||||||
|
s = p->states + p->statecount - 1;
|
||||||
|
}
|
||||||
|
if (s->flags & PFLAG_CONTAINER) {
|
||||||
|
s->argn++;
|
||||||
|
if (p->statecount == 1) p->pending++;
|
||||||
|
push_arg(p, argv[1]);
|
||||||
|
} else if (s->flags & (PFLAG_STRING | PFLAG_LONGSTRING)) {
|
||||||
|
const uint8_t *str = janet_to_string(argv[1]);
|
||||||
|
int32_t slen = janet_string_length(str);
|
||||||
|
size_t newcount = p->bufcount + slen;
|
||||||
|
if (p->bufcap > p->bufcount + slen) {
|
||||||
|
size_t newcap = 2 * newcount;
|
||||||
|
p->buf = realloc(p->buf, newcap);
|
||||||
|
if (p->buf == NULL) {
|
||||||
|
JANET_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
p->bufcap = newcap;
|
||||||
|
}
|
||||||
|
memcpy(p->buf + p->bufcount, str, slen);
|
||||||
|
p->bufcount = newcount;
|
||||||
|
} else {
|
||||||
|
janet_panic("cannot insert value into parser");
|
||||||
|
}
|
||||||
|
return argv[0];
|
||||||
|
}
|
||||||
|
|
||||||
static Janet cfun_parse_has_more(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_has_more(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
@ -807,6 +840,13 @@ static const JanetReg parse_cfuns[] = {
|
|||||||
"in the byte stream as a tuple (line, column). Lines and columns are counted from "
|
"in the byte stream as a tuple (line, column). Lines and columns are counted from "
|
||||||
"1, (the first byte is line 1, column 1) and a newline is considered ASCII 0x0A.")
|
"1, (the first byte is line 1, column 1) and a newline is considered ASCII 0x0A.")
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"parser/insert", cfun_parse_insert,
|
||||||
|
JDOC("(parser/insert parser value)\n\n"
|
||||||
|
"Insert a value into the parser. This means that the parser state can be manipulated "
|
||||||
|
"in between chunks of bytes. This would allow a user to add extra elements to arrays "
|
||||||
|
"and tuples, for example. Returns the parser.")
|
||||||
|
},
|
||||||
{NULL, NULL, NULL}
|
{NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ extern "C" {
|
|||||||
|
|
||||||
/***** START SECTION CONFIG *****/
|
/***** START SECTION CONFIG *****/
|
||||||
|
|
||||||
#define JANET_VERSION "0.3.0"
|
#define JANET_VERSION "0.4.0"
|
||||||
|
|
||||||
#ifndef JANET_BUILD
|
#ifndef JANET_BUILD
|
||||||
#define JANET_BUILD "local"
|
#define JANET_BUILD "local"
|
||||||
|
Loading…
Reference in New Issue
Block a user