-
Notifications
You must be signed in to change notification settings - Fork 1
/
split.rule
103 lines (93 loc) · 2.74 KB
/
split.rule
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
DiaGrammar [Options: [
grammar-only?: false
ruleset: true
hovering: true
string-input: false
case-parsing: false
live-edit?: true
live-parse?: true
iterate-times: 1
max-iterate: 5
save-bookmarks?: true
nav-history: ["position" "count" "split-test" "split-test+" "delimiter" "delim-modifier" "ordinal" "keyword"]
font-size: 11
selected-rule: "split-test+"
latest-inputs: [
"split.inp" %../../greggirwin/red-split/split.inp
"split-grammar.test" %../../greggirwin/red-split/split-grammar.test
]
]]
; Red SPLIT function dialect
; For testing inputs in DiaGrammar
split-test+: [some into split-test]
split-test: ['split [word! | string! | block!] split]
split: [
integer! ("Into parts of size N, last may be shorter")
;integer! ("Split the series at the given index (think SKIP not AT); returns the two parts.")
;| 'into integer! ("Into parts of size N, last may be shorter")
;| into [some integer!] ("into parts at relative offsets")
| delimiter ("At every delimiter")
| any-function! ("into 2 groups; pass/fail test, partition by func")
| ahead block! into [
multi-split
| some integer! ("into parts at relative offsets")
| opt 'every integer! ("Into parts of size N, last may be shorter")
| 'into integer! opt ['parts | 'pieces | 'chunks] ("Into N parts, last may be longer; tail word is a no-op")
| [some any-function!] ("into N+1 groups, partition by func; last group = default")
| [
'once opt delim-modifier
| opt delim-modifier opt 'every
]
opt ordinal
[
delimiter
| position
]
opt count
]
]
multi-split: [
opt 'first 'by split ['then] opt 'by split
]
keyword: [
'every | 'once | 'as-delim
| 'into | 'parts
| 'first | 'last | 'next | 'then | 'by ("first/next/then/by go with multi-split")
| 'times ("Goes with count")
| ordinal
| delim-modifier
]
delimiter: [
;'as-delim integer! ("Treat as literal value, not position or rule")
'as-delim [integer! | block! | word! | paren!] ("Treat as literal value, not position or rule")
;| any-type!
| not [
integer!
| block!
| any-function!
| unset!
]
skip
]
;delimiter: [any-type!]
;delimiter: [
; 'as-delim [integer! | block!] ("Treat as literal value, not position or rule")
;]
position: [integer!]
; Delim modifiers are only compatible with delimiters, not positions.
delim-modifier: [
'before | 'at | 'after ("before+first/after+last with position make no sense")
]
; First/Last are compatible with delimiters and positions.
; Nth is only compatible with delimiters.
ordinal: [
[
'first | 'last
; | Nth
] ("Implies once")
]
count: [opt ['up 'to] integer! 'times]
; No, this is not how I think we should do it. Just playing.
;Nth: [
; ahead block! into [integer! ['st | 'nd | 'rd]]
;]