-
Notifications
You must be signed in to change notification settings - Fork 1
/
fendo.addon.forth_blocks_source_code.fs
179 lines (143 loc) · 5.42 KB
/
fendo.addon.forth_blocks_source_code.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
.( fendo.addon.forth_blocks_source_code.fs) cr
\ This file is part of Fendo
\ (http://programandala.net/en.program.fendo.html).
\ This file is the Forth blocks source code addon.
\ Last modified 20220123T1340+0100.
\ See change log at the end of the file.
\ Copyright (C) 2013,2014,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://gnu.org/software/gforth).
\ ==============================================================
\ Requirements {{{1
forth_definitions
require galope/package.fs \ `package`, `private`, `public`, `end-package`
require galope/s-constant.fs \ `sconstant`
fendo_definitions
require ./fendo.addon.source_code.fs
\ ==============================================================
\ Code {{{1
package fendo.addon.forth_blocks_source_code
64 value /forth_block_line \ chars per line
variable forth_block \ counter
variable forth_block_lenght
public
16 value /forth_block \ lines per block
variable forth_block_line \ counter
variable highlight_forth_block_0? \ flag
defer forth_block$ \ "Block" in the current language
private
s" Block" sconstant (default_forth_block$)
' (default_forth_block$) is forth_block$
(*
\ `forth_block$` can be vectored by the application
\ to a multilingual string, e.g.:
s" Block" \ English
s" Bloko" \ Esperanto
s" Bloque" \ Spanish
l18n$ l18n_forth_block$
' l18n_forth_block$ is forth_block$
*)
: echo_forth_block_number ( -- )
[<p>] forth_block$ echo forth_block @ _echo. [</p>] ;
: reset_forth_block ( -- )
0 forth_block_lenght ! new_source_code ;
: next_forth_block ( -- )
1 forth_block +! reset_forth_block ;
: update_forth_block_0_highlighting ( -- )
forth_block @ 0=
if highlight_forth_block_0? @ highlight? and to highlight? then ;
\ Turn off highlighting for Forth block 0, if needed.
: (echo_forth_block) ( -- )
echo_forth_block_number
highlight? \ save
update_forth_block_0_highlighting
source_code@ echo_source_code
to highlight? ; \ restore
: echo_forth_block ( -- )
forth_block_lenght @ if (echo_forth_block) then next_forth_block ;
: forth_block_line++ ( -- n )
forth_block_line @ 1+ dup /forth_block < abs * dup forth_block_line ! ;
\ Increment the counter of Forth block lines.
\ n = new line number
: read_forth_block_line ( -- ca len )
source_line dup /forth_block_line source_code_fid read-file throw
\ 2dup ." «" type ." »" cr \ XXX INFORMER
;
\ Note: `source_line` is a buffer defined in
\ <fendo/fendo_markup_wiki.fs>.
public
: default_tidy_forth_block_line ( ca len -- )
2drop ;
defer tidy_forth_block_line ( ca len -- )
private
' default_tidy_forth_block_line is tidy_forth_block_line
: save_forth_block_line ( ca len -- )
2dup tidy_forth_block_line
-trailing dup forth_block_lenght +!
append_source_code_line
forth_block_line++ 0= if echo_forth_block then ;
public
: (forth_blocks_source_code) ( -- )
s" forth" programming_language?! \ set it if unset
0 forth_block !
0 forth_block_line !
0 forth_block_lenght !
new_source_code
begin read_forth_block_line dup
while save_forth_block_line
repeat 2drop ;
: forth_blocks_source_code ( ca len -- )
highlight_forth_block_0? on \ default
open_source_code (forth_blocks_source_code) close_source_code ;
\ Read the content of a Forth blocks file and echo it.
\ ca len = file name
end-package
.( fendo.addon.forth_blocks_source_code.fs compiled) cr
\ ==============================================================
\ Change log {{{1
\ 2013-11-09: Code extracted from <addons/source_code.fs>.
\
\ 2013-11-18: Change: `programming_language` renamed to
\ `programming_language!`, after the changes in the main code.
\
\ 2013-11-19: Fix: `(echo_forth_block)` and
\ `update_block_0_highlighting` still used `higlight?` as a
\ variable, but it was converted to a value.
\
\ 2013-11-30: Fix: now `forth_block$` is defered; the application must
\ set it, depending on the languages used in the website.
\
\ 2013-12-10: Change: `ql_forth_blocks_source_code` moved to its own file
\ <addons/ql_forth_blocks_source_code.fs>.
\
\ 2013-12-10: Change: All Abersoft Forth code is moved to its own file
\ <addons/abersoft_forth_blocks_source_code.fs>.
\
\ 2014-02-05: Fix: `update_forth_block_0_highlighting` set `highlight?`
\ when it was unset!
\
\ 2014-03-12: Change: module renamed after the filename.
\
\ 2014-10-19: Improvement: the programming language is not set to
\ Forth if it's not empty; this allows other flavours of Forth to be
\ used, e.g. ZX Spectrum`s Abersoft Forth or QL`s SuperForth.
\
\ 2017-06-22: Update source style, layout and header.
\
\ 2018-09-27: Use `package` instead of `module:`.
\
\ 2018-12-08: Update notation of Forth words in comments and strings.
\
\ 2020-04-14: Define strings constants with `sconstant` instead of
\ `2constant`.
\ vim: filetype=gforth