@@ -85,33 +85,35 @@ create \-escape-table
85
85
endif
86
86
c, char+ ;
87
87
88
- Defer string-lineend
89
88
$Variable mlstringpos
90
89
91
90
s" End of string expected" exception >r
92
91
93
- : singleline-strings ( -- ) \ gforth-experimental
94
- \G set strings to end within a line (default).
95
- [: ( -- never ) [ r@ ]L throw ;] is string-lineend ;
96
-
97
- : multiline-strings ( -- ) \ gforth-experimental
98
- \G set strings to span multiple lines
99
- [: ( -- parse-area parse-end ) #lf c,
100
- source-id 0= IF
101
- success-color ." string" default-color cr
102
- input-color THEN
103
- refill IF source ELSE
104
- mlstringpos get-stack 2 - -rot 2>r restore-input drop
105
- 2r> source drop + swap input-lexeme! [ r> ]L throw THEN
106
- over + ;] is string-lineend ;
107
-
108
- singleline-strings
109
-
110
- : \"-parse ( "string"<"> -- c-addr u ) \ gforth-internal backslash-quote-parse
92
+ : singleline-string ( -- never ) \ gforth-experimental
93
+ \G throw exception when string reaches the end of a line
94
+ [ r@ ]L throw ;
95
+
96
+ : multiline-string ( -- parse-area parse-end ) \ gforth-experimental
97
+ \G parses multiline strings
98
+ #lf c,
99
+ source-id 0= IF
100
+ success-color ." string" default-color cr
101
+ input-color THEN
102
+ refill IF
103
+ source
104
+ \ skip auto-indent blanks
105
+ mlstringpos stack> dup mlstringpos >stack
106
+ 0 U+DO over c@ bl = IF 1 safe/string THEN LOOP
107
+ ELSE
108
+ mlstringpos get-stack 2 - -rot 2>r restore-input drop
109
+ 2r> source drop + swap input-lexeme! [ r> ]L throw THEN
110
+ over + ;
111
+
112
+ : \"-parse ( "string"<"> xt -- c-addr u ) \ gforth-internal backslash-quote-parse
111
113
\G parses string, translating @code{\}-escapes to characters (as in
112
114
\G C). The resulting string resides at @code{here}. See @code{S\"}
113
115
\G for the supported @code{\-escapes}.
114
- here >r
116
+ { xt: string-lineend } here >r
115
117
save-input input-lexeme 2@ swap source drop - rot 2 + mlstringpos set-stack
116
118
>in @ chars source chars over + >r + begin ( parse-area R: here parse-end )
117
119
dup r@ u>= IF
@@ -130,8 +132,8 @@ singleline-strings
130
132
here r> - dup negate allot
131
133
here swap char/ ;
132
134
133
- :noname \"-parse save-mem ;
134
- :noname \"-parse save-mem 2dup postpone sliteral drop free throw ;
135
+ :noname ['] singleline-string \"-parse save-mem ;
136
+ :noname ['] singleline-string \"-parse save-mem 2dup postpone sliteral drop free throw ;
135
137
interpret/compile: s\" ( Interpretation 'ccc" ' -- c-addr u ) \ core-ext,file-ext s-backslash-quote
136
138
\G Interpretation: Parse the string @i{ccc} delimited by a @code{"}
137
139
\G (but not @code{\"}), and convert escaped characters as described
@@ -146,7 +148,7 @@ interpret/compile: s\" ( Interpretation 'ccc"' -- c-addr u ) \ core-ext,file-ext
146
148
\G Run-time @code{( -- c-addr u )}: Push a descriptor for the
147
149
\G resulting string.
148
150
149
- :noname \"-parse type ;
151
+ :noname ['] singleline-string \"-parse type ;
150
152
:noname postpone s\" postpone type ;
151
153
interpret/compile: .\" ( compilation 'ccc"' -- ; run-time -- ) \ gforth dot-backslash-quote
152
154
\G Like @code{."}, but translates C-like \-escape-sequences (see
0 commit comments