mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Fix peg RULE_SET op code when at tail of string in some cases.
This commit is contained in:
parent
4754fa3902
commit
14657a762c
@ -211,6 +211,7 @@ tail:
|
||||
}
|
||||
|
||||
case RULE_SET: {
|
||||
if (text >= s->text_end) return NULL;
|
||||
uint32_t word = rule[1 + (text[0] >> 5)];
|
||||
uint32_t mask = (uint32_t)1 << (text[0] & 0x1F);
|
||||
return (text < s->text_end && (word & mask))
|
||||
|
@ -27,4 +27,15 @@
|
||||
(assert (deep= (tabseq [i :in (range 3)] i)
|
||||
@{}))
|
||||
|
||||
(def- sym-prefix-peg
|
||||
(peg/compile
|
||||
~{:symchar (+ (range "\x80\xff" "AZ" "az" "09") (set "!$%&*+-./:<?=>@^_"))
|
||||
:anchor (drop (cmt ($) ,|(= $ 0)))
|
||||
:cap (* (+ (> -1 (not :symchar)) :anchor) (* ($) '(some :symchar)))
|
||||
:recur (+ :cap (> -1 :recur))
|
||||
:main (> -1 :recur)}))
|
||||
|
||||
(assert (deep= (peg/match sym-prefix-peg @"123" 3) @[0 "123"]) "peg lookback")
|
||||
(assert (deep= (peg/match sym-prefix-peg @"1234" 4) @[0 "1234"]) "peg lookback 2")
|
||||
|
||||
(end-suite)
|
||||
|
Loading…
Reference in New Issue
Block a user