-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.fs
79 lines (63 loc) · 2.53 KB
/
config.fs
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
\ config file reader/writer
\ Author: Bernd Paysan
\ Copyright (C) 2016 Bernd Paysan
\ This program is free software: you can redistribute it and/or modify
\ it under the terms of the GNU General Public License as published by
\ the Free Software Foundation, either version 3 of the License, or
\ (at your option) any later version.
\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\ GNU General Public License for more details.
\ You should have received a copy of the GNU General Public License
\ along with this program. If not, see <http://www.gnu.org/licenses/>.
require rec-scope.fs
require recognizer-ext.fs
require mkdir.fs
translator: config-translator
Vocabulary config
' config >wordlist Value config-wl
' rec-string ' rec-num ' rec-float 3 recognizer-sequence: config-recognize
\G The config recognizer
s" Config error" exception Value config-throw
\ if you don't want an exception, set config-throw to 0
: .config-err ( -- )
." can't parse config line " sourceline# 0 .r ." : '" source type ." '" cr
config-throw throw ;
: exec-config ( .. addr u char xt1 xt2 -- ) >r >r
[: >r type r> emit ;] $tmp config-wl find-name-in
?dup-IF execute r> execute rdrop
ELSE rdrop r> execute .config-err THEN ;
: eval-config ( .. rec addr u -- ) rot config-translator execute ;
:noname '$' ['] $! [: drop free throw ;] exec-config ;
' translate-string to config-translator
:noname '#' ['] ! ['] drop exec-config ;
' translate-num to config-translator
:noname '&' ['] 2! ['] 2drop exec-config ;
' translate-dnum to config-translator
:noname '%' ['] f! ['] fdrop exec-config ;
' translate-float to config-translator
' .config-err ' notfound to config-translator
: config-line ( -- )
source nip 0= ?EXIT
'=' parse -trailing 2>r
parse-name config-recognize 2r> eval-config
postpone \ ;
: read-config-loop ( -- )
BEGIN refill WHILE config-line REPEAT ;
: read-config ( addr u wid -- ) to config-wl
>included throw ['] read-config-loop execute-parsing-named-file ;
: write-config ( addr u wid -- ) to config-wl
force-open >r
[: config-wl
[: dup name>string 1- 2dup + c@ >r type .\" ="
execute r>
case
'$' of $@ [: '"' emit see-voc:c-\type '"' emit ;] $tmp type cr endof
'#' of @ 0 .r cr endof
'&' of '#' emit 2@ 0 d.r '.' emit cr endof
'%' of f@ fe. cr endof
drop
endcase
;] map-wordlist ;] r@ outfile-execute
r> close-file throw ;