"1" token ,
"." token ,
{ "0" "1" } one-of ,
- ] seq* [ concat >string ] action ;
+ ] seq* [ "" concat-as ] action ;
PEG: parse-request-line ( string -- triple )
#! Triple is { method url version }
! We can't use n*quot, narray and firstn from generalizations because
! they're macros, and macros use memoize!
: (n*quot) ( n quot -- quotquot )
- <repetition> concat >quotation ;
+ <repetition> [ ] concat-as ;
: [nsequence] ( length exemplar -- quot )
[ [ [ 1 - ] keep ] dip '[ _ _ _ new-sequence ] ]
MultiLineComment = "/*" (!("*/") .)* "*/" => [[ ignore ]]
Space = " " | "\t" | "\r" | "\n" | SingleLineComment | MultiLineComment
Spaces = Space* => [[ ignore ]]
-Number = Digits:ws '.' Digits:fs => [[ ws "." fs 3array concat >string string>number ast-number boa ]]
+Number = Digits:ws '.' Digits:fs => [[ ws "." fs 3array "" concat-as string>number ast-number boa ]]
| Digits => [[ >string string>number ast-number boa ]]
Special = "(" | ")" | "{" | "}" | "[" | "]" | "," | ";"
| "?" | ":" | "!==" | "~=" | "===" | "==" | "=" | ">="
"]]" token ensure-not ,\r
"]?" token ensure-not ,\r
[ drop t ] satisfy ,\r
- ] seq* repeat0 [ concat >string ] action ;\r
+ ] seq* repeat0 [ "" concat-as ] action ;\r
\r
: 'ensure-not' ( -- parser )\r
#! Parses the '!' syntax to ensure that \r
[ [ hex> ] dip ] assoc-map ;
: process-data ( index data -- hash )
- (process-data) [ hex> ] assoc-map [ nip ] assoc-filter >hashtable ;
+ (process-data) [ hex> ] assoc-map [ nip ] H{ } assoc-filter-as ;
: (chain-decomposed) ( hash value -- newvalue )
[
: assure-no-duplicates ( attrs-alist -- attrs-alist )
H{ } clone 2dup '[ swap _ push-at ] assoc-each
- [ nip length 2 >= ] assoc-filter >alist
+ [ nip length 2 >= ] { } assoc-filter-as
[ first first2 duplicate-attr ] unless-empty ;
: middle-tag ( -- attrs-alist )
#! Advance code past any whitespace, including newlines
[ blank? not ] skip-until ;
+: next-matching ( pos ch str -- pos' )
+ [ over ] dip nth eq? [ 1 + ] [ drop 0 ] if ;
+
: string-matcher ( str -- quot: ( pos char -- pos ? ) )
- dup length 1 - '[
- over _ nth eq? [ 1 + ] [ drop 0 ] if dup _ >
- ] ; inline
+ dup length 1 - '[ _ next-matching dup _ > ] ; inline
: take-string ( match -- string )
[ 0 swap string-matcher take-until nip ] keep
1024 <sbuf> [ spot get (parse-char) ] keep >string ; inline
: assure-no-]]> ( pos char -- pos' )
- over "]]>" nth eq? [ 1 + ] [ drop 0 ] if
- dup 2 > [ text-w/]]> ] when ;
+ "]]>" next-matching dup 2 > [ text-w/]]> ] when ;
:: parse-text ( -- string )
0 :> pos!
[ exchange-unsafe ]
3tri ;
+: midpoint@ ( seq -- n ) length 2/ ; inline
+
: reverse! ( seq -- seq )
[
- [ length 2/ iota ] [ length ] [ ] tri
+ [ midpoint@ iota ] [ length ] [ ] tri
[ [ over - 1 - ] dip exchange-unsafe ] 2curry each
] keep ;
: insert-nth ( elt n seq -- seq' )
swap cut-slice [ swap suffix ] dip append ;
-: midpoint@ ( seq -- n ) length 2/ ; inline
-
: halves ( seq -- first-slice second-slice )
dup midpoint@ cut-slice ;
'identifier-middle' ,
'identifier-ends' ,
] seq* [
- concat >string f ast-identifier boa
+ "" concat-as f ast-identifier boa
] action ;
Letter = [a-zA-Z]
Digit = [0-9]
Digits = Digit+
-Number = Digits '.' Digits => [[ concat >string string>number ast-number boa ]]
+Number = Digits '.' Digits => [[ "" concat-as string>number ast-number boa ]]
| Digits => [[ >string string>number ast-number boa ]]
Space = " " | "\n" | "\r" | "\t"
Spaces = Space* => [[ ignore ]]
| "while"
| "with") !(NameRest)
Name = !(Keyword) iName => [[ ast-name boa ]]
-Number = Digits:ws '.' Digits:fs => [[ ws "." fs 3array concat >string string>number ast-number boa ]]
+Number = Digits:ws '.' Digits:fs => [[ ws "." fs 3array "" concat-as string>number ast-number boa ]]
| Digits => [[ >string string>number ast-number boa ]]
EscapeChar = "\\n" => [[ 10 ]]