ref: de5bccab8a41542ad7c0dcd91b037c2d0deafa58
parent: ce78898fbea0dbe6d3aa2d1af64357a589a031c7
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Jan 1 17:14:15 EST 2015
Quoted words are now allowed.
--- a/parse.myr
+++ b/parse.myr
@@ -289,23 +289,42 @@
/* word: /wordchar*/
const word = {p : parser#
- var c, r, n
+ var c, n
var start
skipspace(p)
- r = p.rest
- start = r
- n = 0
- while r.len > 0
- c = peekc(p)
- if wordchar(c)
+ c = peekc(p)
+ if c == '"'
+ n = 0
+ nextc(p)
+ start = p.rest
+ while p.rest.len > 0
+ c = peekc(p)
+ if c == '"'
+ nextc(p)
+ goto done
+ elif c == '\\'
+ c = nextc(p)
+ ;;
nextc(p)
n += std.charlen(c)
- else
- break
;;
+ failparse(p, "input ended within quoted word\n")
+ else
+ n = 0
+ start = p.rest
+ while p.rest.len > 0
+ c = peekc(p)
+ if wordchar(c)
+ nextc(p)
+ n += std.charlen(c)
+ else
+ break
+ ;;
+ ;;
;;
+:done
if n > 0
-> `std.Some std.sldup(start[:n])
else