-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfendo.fs
303 lines (238 loc) · 8.88 KB
/
fendo.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
.( fendo.fs ) cr
\ This file is part of Fendo
\ (http://programandala.net/en.program.fendo.html).
\ This file is the main one; it loads all the modules.
\ Last modified 202011160218.
\ See change log at the end of the file.
\ Copyright (C) 2012,2013,2014,2015,2017,2018,2020 Marcos Cruz (programandala.net)
\ Fendo 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 2 of the License, or
\ (at your option) any later version.
\
\ Fendo 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://gnu.org/licenses>.
\ Fendo is written in Forth (http://forth-standard.org)
\ with Gforth (http://www.gnu.org/software/gforth).
\ ==============================================================
\ Debug {{{1
false value [bug_thread] immediate \ XXX TMP
\ ==============================================================
\ Requirements {{{1
only forth definitions
\ ------------------------------
\ From Gforth
require string.fs \ dynamic strings
\ ------------------------------
\ From Forth Foundation Library
\ require ffl/str.fs
\ require ffl/tos.fs
\ require ffl/xos.fs
\ ------------------------------
\ From Galope
\ First load the stringer and replace the original `s"` and `s+` with
\ the stringer variants, in order to make sure the rest of the modules
\ use the stringer:
require galope/stringer.fs \ `stringer`
require galope/s-s-plus.fs \ `ss+`
require galope/s-s-quote.fs \ `ss"`
64 1024 dup * * allocate-stringer \ 64-MiB buffer by default
synonym s" ss" \ Replace `s"` with the `stringer` version `ss"`
synonym s+ ss+ \ Replace `s+` with the `stringer` version `ss+`
\ Then load the rest of the required modules:
require galope/three-dup.fs
require galope/anew.fs
require galope/backslash-end-of-file.fs \ `\eof`
require galope/bracket-false.fs \ `[false]`
require galope/buffer-colon.fs \ `buffer:`
require galope/colon-alias.fs \ `:alias`
require galope/colon-create.fs \ `:create`
require galope/dollar-variable.fs \ `$variable`
require galope/enum.fs \ `enum`
require galope/minus-extension.fs \ `-extension`
require galope/minus-leading.fs \ `-leading`
require galope/minus-suffix.fs \ `-suffix`
require galope/parse-name-question.fs \ `parse-name?`
require galope/paren-star.fs \ `(*`
require galope/sconstant.fs \ `sconstant`
require galope/sides-slash.fs \ `sides/`
require galope/slash-sides.fs \ `/sides`
require galope/tilde-tilde.fs \ improved `~~` for debugging
require galope/trim.fs \ `trim`
\ Safer alternatives for words of Gforth's string.fs
\ (they will not be defined if Gforth >= 0.8):
require galope/dollar-fetch.fs \ `$@`
require galope/dollar-fetch-len.fs \ `$@len`
\ ------------------------------
\ Other
: empty? ( ca len -- f )
nip 0= ;
\ Is a string empty?
\ ==============================================================
anew -fendo
false [if] \ XXX TODO
false \ Gforth's dynamic strings instead of FFL's?
dup constant gforth-strings?
dup constant [gforth-strings?] immediate
0= dup constant ffl-strings?
constant [ffl-strings?] immediate
[then]
\ ==============================================================
\ Wordlists {{{1
table constant fendo_markup_html_entities_wid \ HTML entities
table constant fendo_markup_macros_wid \ user macros
wordlist constant fendo_markup_wid \ markup, except HTML entities and user macros
wordlist constant fendo_wid \ program, except markup and HTML entities
wordlist constant fendo_pid_wid \ page IDs
: forth>current ( -- )
forth-wordlist set-current ;
: markup>current ( -- )
fendo_markup_wid set-current ;
: entities>current ( -- )
fendo_markup_html_entities_wid set-current ;
\ XXX OLD
\ variable recognize_macros? \ flag, turned off for parsing HTML parameters
\ recognize_macros? on
: markup_wids ( -- wid'1 ... wid'n )
\ Return the wordlists that contain markup to be recognized.
\ wid'1 = highest priority wordlist
\ wid'n = lowest priority wordlist
\ XXX OLD
\ recognize_macros? @ if
fendo_markup_macros_wid
\ then
fendo_markup_html_entities_wid
fendo_markup_wid ;
: markup_order ( -- wid'1 ... wid'n n )
\ Return the wordlist order required for the markup parsing.
\ wid'1 = highest priority wordlist
\ wid'n = lowest priority wordlist
depth >r markup_wids depth r> - ;
: markup>order ( -- )
markup_order 0 ?do >order loop ;
: set_markup_order ( -- )
markup_order set-order ;
: [markup>order] ( -- )
markup>order ; immediate
: markup<order ( -- )
markup_order 0 ?do drop previous loop ;
: [markup<order] ( -- )
markup<order ; immediate
: fendo>current ( -- )
fendo_wid set-current ;
: fendo>order ( -- )
fendo_wid >order ;
: fendo<order ( -- )
previous ;
: [fendo>order] ( -- )
fendo>order ; immediate
: [fendo<order] ( -- )
fendo<order ; immediate
: forth>order ( -- )
forth-wordlist >order ;
: [forth>order] ( -- )
forth>order ; immediate
: set_forth_order ( -- )
only forth>order ;
: set_fendo_order ( -- )
set_forth_order fendo>order ;
: markup_definitions ( -- )
set_forth_order markup>order fendo>order markup>current ;
: fendo_definitions ( -- )
set_fendo_order fendo>current ;
: forth_definitions ( -- )
set_forth_order forth>current ;
fendo_definitions
\ ==============================================================
\ Config {{{1
require VERSION.fs
: generator ( -- ca len )
s" Fendo (Forth Engine for Net DOcuments) " fendo_version s+ ;
false constant link_text_as_attribute? \ XXX TMP -- experimental
\ ==============================================================
\ Modules {{{1
false value multilingual? \ to be changed by <addons/multilingual.fs>
depth [if] abort [then] \ XXX DEBUGGING
include ./fendo.config.fs
depth [if] abort [then] \ XXX DEBUGGING
defer unshortcut \ defined in <fendo.shortcuts.fs>
defer just_unshortcut \ defined in <fendo.shortcuts.fs>
defer dry_unshortcut \ defined in <fendo.shortcuts.fs> \ XXX TMP
defer -anchor \ defined in <fendo.links.fs> \ XXX TMP
defer -anchor! \ defined in <fendo.links.fs> \ XXX TMP
defer -anchor?! \ defined in <fendo.links.fs> \ XXX TMP
defer link_anchor \ dynamic string, defined in <fendo.links.fs>
defer link_text \ dynamic string, defined in <fendo.links.fs>
defer link_anchor+ \ defined in <fendo.links.fs> \ XXX TMP
include ./fendo.data.fs
depth [if] abort [then] \ XXX DEBUGGING
include ./fendo.echo.fs
depth [if] abort [then] \ XXX DEBUGGING
include ./fendo.files.fs
depth [if] abort [then] \ XXX DEBUGGING
include ./fendo.links.fs
depth [if] abort [then] \ XXX DEBUGGING
include ./fendo.markup.fs
depth [if] abort [then] \ XXX DEBUGGING
include ./fendo.parser.fs
depth [if] abort [then] \ XXX DEBUGGING
.( fendo.fs compiled) cr
\ ==============================================================
\ Change log {{{1
\ 2012-06-30: Start.
\
\ 2013-04-28: New: <fendo_data.fs>, <fendo_content.fs>.
\
\ 2013-05-07: New: <fendo_require.fs>.
\
\ 2013-06: New: Generic tool words; wordlists.
\
\ 2013-07-09: Change: `parse-name?` moved to Galope.
\
\ 2014-02-05: New: `fendo_markup_macros_wid`.
\
\ 2014-02-05: New: `markup_wids`, `markup_order`, `set_markup_order`;
\ they are written to make the parser kernel simpler and easier to
\ expand.
\
\ 2014-02-05: Change: `markup>order` and `markup<order` rewritten with
\ the new word `markup_order`.
\
\ 2014-03-18: Fix checking "gforth" with `environment?`.
\
\ 2014-04-20: New: `markup_definitions`, `fendo_definitions`,
\ `forth_definitions`, `forth>current`...; this makes some thing
\ easier, e.g. modules that define markups and require libraries. The
\ requirements section of all Fendo files is updated with
\ `forth_definitions` and `fendo_definitions`.
\
\ 2014-06-14: New: `recognize_macros?`.
\
\ 2014-06-15: Change: `recognize_macros?` is commented out. The
\ problem was solved with `evaluate_the_markup?` in <fendo.parser.fs>.
\
\ 2015-02-11: Change: requirements reorganized and tidied.
\
\ 2015-02-12: Change: `link_anchor` and `link_text` are defered here
\ and defined in <fendo.fs>. Required because of a fix.
\
\ 2017-06-22: Update source style, layout and header.
\
\ 2017-11-04: Update to Galope 0.103.0: Remove <galope/minus-path.fs>
\ and use Gforth's `basename` instead.
\
\ 2018-12-08: Update notation of Forth words in comments and strings.
\
\ 2018-12-08: Update notation of page IDs in comments and strings.
\
\ 2018-12-08: Update notation of page IDs in comments and strings.
\
\ 2020-01-19: Use the stringer and replace `s"` and `s+` with their
\ stringer versions `ss"` and `ss+`. This partly avoids memory
\ allocation errors when hundreds of pages are built at once.
\ vim: filetype=gforth