1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 08:20:27 +00:00

Make parser errors a bit better for files with no closing

delimiters.
This commit is contained in:
Calvin Rose 2019-01-17 23:43:46 -05:00
parent c4114fbcdb
commit b4934ceddc
7 changed files with 24 additions and 24 deletions

View File

@ -192,6 +192,7 @@ install: $(JANET_TARGET)
cp $(JANET_LIBRARY) $(LIBDIR)/libjanet.so cp $(JANET_LIBRARY) $(LIBDIR)/libjanet.so
mkdir -p $(JANET_PATH) mkdir -p $(JANET_PATH)
cp tools/cook.janet $(JANET_PATH) cp tools/cook.janet $(JANET_PATH)
cp tools/highlight.janet $(JANET_PATH)
cp janet.1 /usr/local/share/man/man1/ cp janet.1 /usr/local/share/man/man1/
mandb mandb
$(LDCONFIG) $(LDCONFIG)

View File

@ -1454,6 +1454,12 @@ value, one key will be ignored."
nil nil
where)))) where))))
(if (= (parser/status p) :pending)
(onstatus :parse
(string "unmatched delimiters " (parser/state p))
nil
where))
(set *env* oldenv) (set *env* oldenv)
env) env)

View File

@ -476,7 +476,7 @@ static int root(JanetParser *p, JanetParseState *state, uint8_t c) {
{ {
Janet ds; Janet ds;
if (p->statecount == 1) { if (p->statecount == 1) {
p->error = "mismatched delimiter"; p->error = "unexpected delimiter";
return 1; return 1;
} }
if ((c == ')' && (state->flags & PFLAG_PARENS)) || if ((c == ')' && (state->flags & PFLAG_PARENS)) ||

View File

@ -24,6 +24,7 @@
#include <string.h> #include <string.h>
#include "util.h" #include "util.h"
#include "vector.h" #include "vector.h"
#include "util.h"
/* /*
* Runtime * Runtime
@ -1085,15 +1086,15 @@ static Janet cfun_match(int32_t argc, Janet *argv) {
static const JanetReg cfuns[] = { static const JanetReg cfuns[] = {
{"peg/compile", cfun_compile, {"peg/compile", cfun_compile,
"(peg/compile peg)\n\n" JDOC("(peg/compile peg)\n\n"
"Compiles a peg source data structure into a <core/peg>. This will speed up matching " "Compiles a peg source data structure into a <core/peg>. This will speed up matching "
"if the same peg will be used multiple times." "if the same peg will be used multiple times.")
}, },
{"peg/match", cfun_match, {"peg/match", cfun_match,
"(peg/match peg text [,start=0])\n\n" 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. " "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 " "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." "similar to those defined by LPeg, and have similar capabilities.")
}, },
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };

View File

@ -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 # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to # of this software and associated documentation files (the "Software"), to

View File

@ -330,4 +330,9 @@
(check-match '(* (? "hi") -1) "hi" true) (check-match '(* (? "hi") -1) "hi" true)
(check-match '(* (? "hi") -1) "no" false) (check-match '(* (? "hi") -1) "no" false)
# Drop
(check-deep '(drop '"hello") "hello" @[])
(check-deep '(drop "hello") "hello" @[])
(end-suite) (end-suite)

View File

@ -21,8 +21,8 @@
(defn check-number [text] (and (scan-number text) text)) (defn check-number [text] (and (scan-number text) text))
(defn- make-grammar (defn- make-grammar
"Creates the grammar based on the paint function and some "Creates the grammar based on the paint function, which
wraping constants." colorizes fragments of text."
[paint] [paint]
(defn <-c (defn <-c
@ -128,19 +128,6 @@
</style> </style>
```) ```)
(def- html-boiler-prefix
```<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>
</body>
</html>
```)
(defn- html-escape (defn- html-escape
"Escape special characters for HTML encoding." "Escape special characters for HTML encoding."
[str] [str]