From 82cddef5bb73f990a42b01cfdac29dbdb3df0c14 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Wed, 16 Jan 2019 12:32:33 -0500 Subject: [PATCH] Update man page and add early exit to number scanning for parser. --- janet.1 | 6 +++++- src/core/parse.c | 6 ++++-- src/core/peg.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/janet.1 b/janet.1 index 0f994439..3bcfd368 100644 --- a/janet.1 +++ b/janet.1 @@ -37,7 +37,11 @@ Shows the version text and exits immediately. .TP .BR \-s -Read raw input from stdin, such as from a pipe without printing a prompt. +Read raw input from stdin and forgo prompt history and other readline-like features. + +.TP +.BR \-q +Quiet output. Don't prinpt a repl prompt or expression results to stdout. .TP .BR \-r diff --git a/src/core/parse.c b/src/core/parse.c index 96730f06..ce5f93ca 100644 --- a/src/core/parse.c +++ b/src/core/parse.c @@ -293,9 +293,11 @@ static int tokenchar(JanetParser *p, JanetParseState *state, uint8_t c) { } /* Token finished */ blen = (int32_t) p->bufcount; + int start_dig = p->buf[0] >= '0' && p->buf[0] <= '9'; + int start_num = start_dig || p->buf[0] == '-' || p->buf[0] == '+'; if (p->buf[0] == ':') { ret = janet_keywordv(p->buf + 1, blen - 1); - } else if (!janet_scan_number(p->buf, blen, &numval)) { + } else if (start_num && !janet_scan_number(p->buf, blen, &numval)) { ret = janet_wrap_number(numval); } else if (!check_str_const("nil", p->buf, blen)) { ret = janet_wrap_nil(); @@ -304,7 +306,7 @@ static int tokenchar(JanetParser *p, JanetParseState *state, uint8_t c) { } else if (!check_str_const("true", p->buf, blen)) { ret = janet_wrap_true(); } else if (p->buf) { - if (p->buf[0] >= '0' && p->buf[0] <= '9') { + if (start_dig) { p->error = "symbol literal cannot start with a digit"; return 0; } else { diff --git a/src/core/peg.c b/src/core/peg.c index 93ad9fb7..2fd46132 100644 --- a/src/core/peg.c +++ b/src/core/peg.c @@ -1024,7 +1024,7 @@ static const JanetReg cfuns[] = { "(peg/match peg text [,start=0])\n\n" "Match a Parsing Expression Grammar to a byte string and return an array of captured values. " "Returns nil if text does not match the language defined by peg. The syntax of PEGs are very " - "similar to those defined by LPeg, and have similar capabilities. Still WIP." + "similar to those defined by LPeg, and have similar capabilities." }, {NULL, NULL, NULL} };