From b4934ceddc453c5535097fecd629b1a455814b26 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 17 Jan 2019 23:43:46 -0500 Subject: [PATCH] Make parser errors a bit better for files with no closing delimiters. --- Makefile | 1 + src/core/core.janet | 6 ++++++ src/core/parse.c | 2 +- src/core/peg.c | 15 ++++++++------- test/suite2.janet | 2 +- test/suite3.janet | 5 +++++ tools/highlight.janet | 17 ++--------------- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 7a6463b9..8cb71616 100644 --- a/Makefile +++ b/Makefile @@ -192,6 +192,7 @@ install: $(JANET_TARGET) cp $(JANET_LIBRARY) $(LIBDIR)/libjanet.so mkdir -p $(JANET_PATH) cp tools/cook.janet $(JANET_PATH) + cp tools/highlight.janet $(JANET_PATH) cp janet.1 /usr/local/share/man/man1/ mandb $(LDCONFIG) diff --git a/src/core/core.janet b/src/core/core.janet index c2179c0d..fe43528e 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -1454,6 +1454,12 @@ value, one key will be ignored." nil where)))) + (if (= (parser/status p) :pending) + (onstatus :parse + (string "unmatched delimiters " (parser/state p)) + nil + where)) + (set *env* oldenv) env) diff --git a/src/core/parse.c b/src/core/parse.c index 5cc1c079..df988e8f 100644 --- a/src/core/parse.c +++ b/src/core/parse.c @@ -476,7 +476,7 @@ static int root(JanetParser *p, JanetParseState *state, uint8_t c) { { Janet ds; if (p->statecount == 1) { - p->error = "mismatched delimiter"; + p->error = "unexpected delimiter"; return 1; } if ((c == ')' && (state->flags & PFLAG_PARENS)) || diff --git a/src/core/peg.c b/src/core/peg.c index 9ac10d6d..097ea2f2 100644 --- a/src/core/peg.c +++ b/src/core/peg.c @@ -24,6 +24,7 @@ #include #include "util.h" #include "vector.h" +#include "util.h" /* * Runtime @@ -1085,15 +1086,15 @@ static Janet cfun_match(int32_t argc, Janet *argv) { static const JanetReg cfuns[] = { {"peg/compile", cfun_compile, - "(peg/compile peg)\n\n" - "Compiles a peg source data structure into a . This will speed up matching " - "if the same peg will be used multiple times." + JDOC("(peg/compile peg)\n\n" + "Compiles a peg source data structure into a . This will speed up matching " + "if the same peg will be used multiple times.") }, {"peg/match", cfun_match, - "(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." + JDOC("(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.") }, {NULL, NULL, NULL} }; diff --git a/test/suite2.janet b/test/suite2.janet index f791c1f0..e82aff27 100644 --- a/test/suite2.janet +++ b/test/suite2.janet @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Calvin Rose +#' Copyright (c) 2019 Calvin Rose # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to diff --git a/test/suite3.janet b/test/suite3.janet index 7966f91e..4c7b9a49 100644 --- a/test/suite3.janet +++ b/test/suite3.janet @@ -330,4 +330,9 @@ (check-match '(* (? "hi") -1) "hi" true) (check-match '(* (? "hi") -1) "no" false) +# Drop + +(check-deep '(drop '"hello") "hello" @[]) +(check-deep '(drop "hello") "hello" @[]) + (end-suite) diff --git a/tools/highlight.janet b/tools/highlight.janet index 027fb3ca..7643e935 100644 --- a/tools/highlight.janet +++ b/tools/highlight.janet @@ -21,8 +21,8 @@ (defn check-number [text] (and (scan-number text) text)) (defn- make-grammar - "Creates the grammar based on the paint function and some - wraping constants." + "Creates the grammar based on the paint function, which + colorizes fragments of text." [paint] (defn <-c @@ -128,19 +128,6 @@ ```) -(def- html-boiler-prefix -``` - - - - title - - - - - -```) - (defn- html-escape "Escape special characters for HTML encoding." [str]