Diff for /gforth/quotes.fs between versions 1.8 and 1.12

version 1.8, 2003/03/09 15:16:52 version 1.12, 2007/08/18 08:57:59
Line 1 Line 1
 \ quote: S\" and .\" words  \ quote: S\" and .\" words
   
 \ Copyright (C) 2002,2003 Free Software Foundation, Inc.  \ Copyright (C) 2002,2003,2005 Free Software Foundation, Inc.
   
 \ This file is part of Gforth.  \ This file is part of Gforth.
   
Line 20 Line 20
   
 : char/ ; immediate  : char/ ; immediate
   
 : parse-num-x  ( c-addr1 base -- c-addr2 c )  : parse-num-x  ( c-addr1 umax -- c-addr2 c )
     base !      >r 0. rot source chars + over - char/ r> umin >number
     0. rot source chars + over - char/ >number  
     drop rot rot drop ;      drop rot rot drop ;
   
 : parse-num ( c-addr1 base -- c-addr2 c )  : parse-num ( c-addr1 umax base -- c-addr2 c )
     base @ >r      ['] parse-num-x swap base-execute ;
     ['] parse-num-x catch  
     r> base ! throw ;  
   
 create \-escape-table  create \-escape-table
     7 c,        8 c,  char c c,  char d c,      27 c,      12 c,  char g c,   7 c, #bs c,  'c c,   'd c, #esc c,   #ff c,   'g c,
 char h c,  char i c,  char j c,  char k c,  char l c,  char m c,      10 c,  'h c,  'i c,  'j c,   'k c,  #lf c,   #lf c,  #lf c,
 char o c,  char p c,  char " c,      13 c,  char s c,       9 c,  char u c,  'o c,  'p c,  '" c,  #cr c,   's c,  #tab c,   'u c,
     11 c,  11 c,  'w c,  'x c,   'y c,    0 c,
   
 : \-escape ( c-addr1 -- c-addr2 c )  : \-escape ( c-addr1 -- c-addr2 c )
     \ c-addr1 points at a char right after a '\', c-addr2 points right      \ c-addr1 points at a char right after a '\', c-addr2 points right
     \ after the whole sequence, c is the translated char      \ after the whole sequence, c is the translated char
     dup c@      dup c@
     dup [char] x = if      dup 'x = if
         drop char+ 16 parse-num exit          drop char+ 2 16 parse-num exit
     endif      endif
     dup [char] 0 [char] 8 within if      dup '0 '8 within if
         drop 8 parse-num exit          drop 3 8 parse-num exit
     endif      endif
     dup [char] n = if      dup 'n = if
         \ \-escapes were designed to translate to one character, so          \ \-escapes were designed to translate to one character, so
         \ this is quite ugly: copy all but the last char right away          \ this is quite ugly: copy all but the last char right away
         drop newline 1-          drop newline 1-
         2dup here swap chars dup allot move          2dup here swap chars dup allot move
         chars + c@          chars + c@
     else      else
         dup [char] a [char] w within if          dup 'm = if \ crlf; ugly, because it's two characters
             [char] a - chars \-escape-table + c@              #cr c, \ first half, the rest follows below
           endif
           dup 'a '{ within if
               'a - chars \-escape-table + c@
         endif          endif
     endif      endif
     1 chars under+ ;      1 chars under+ ;
   
 : \"-parse ( "string"<"> -- c-addr u )  : \"-parse ( "string"<"> -- c-addr u ) \ gforth-internal  backslash-quote-parse
 \G parses string, translating @code{\}-escapes to characters (as in  \G parses string, translating @code{\}-escapes to characters (as in
 \G C).  The resulting string resides at @code{here char+}.  The  \G C).  The resulting string resides at @code{here}.  See @code{S\"}
 \G supported @code{\-escapes} are: @code{\a} BEL (alert), @code{\b}  \G for the supported @code{\-escapes}.
 \G BS, @code{\e} ESC (not in C99), @code{\f} FF, @code{\n} newline,  
 \G @code{\r} CR, @code{\t} HT, @code{\v} VT, @code{\"} ",  
 \G @code{\}[0-7]+ octal numerical character value, @code{\x}[0-9a-f]+  
 \G hex numerical character value; a @code{\} before any other  
 \G character represents that character (only ', \, ? in C99).  
     here >r      here >r
     >in @ chars source chars over + >r + begin ( parse-area R: here parse-end )      >in @ chars source chars over + >r + begin ( parse-area R: here parse-end )
         dup r@ < while          dup r@ < while
             dup c@ [char] " <> while              dup c@ '" <> while
                 dup c@ dup [char] \ = if ( parse-area c R: here parse-end )                  dup c@ dup '\ = if ( parse-area c R: here parse-end )
                     drop char+ dup r@ = abort" unfinished \-escape"                      drop char+ dup r@ = abort" unfinished \-escape"
                     \-escape c,                      \-escape c,
                 else                  else
Line 87  char o c,  char p c,  char " c,      13 Line 82  char o c,  char p c,  char " c,      13
 :noname \"-parse save-mem ;  :noname \"-parse save-mem ;
 :noname \"-parse save-mem 2dup postpone sliteral drop free throw ;  :noname \"-parse save-mem 2dup postpone sliteral drop free throw ;
 interpret/compile: s\" ( compilation 'ccc"' -- ; run-time -- c-addr u ) \ gforth        s-backslash-quote  interpret/compile: s\" ( compilation 'ccc"' -- ; run-time -- c-addr u ) \ gforth        s-backslash-quote
 \G Like @code{S"}, but translates C-like \-escape-sequences into  \G Like @code{S"}, but translates C-like \-escape-sequences, as
 \G single characters.  See @code{\"-parse} for details.  \G follows: @code{\a} BEL (alert), @code{\b} BS, @code{\e} ESC (not in
   \G C99), @code{\f} FF, @code{\n} newline, @code{\r} CR, @code{\t} HT,
   \G @code{\v} VT, @code{\"} ", @code{\\} \, @code{\}[0-7]@{1,3@} octal
   \G numerical character value (non-standard), @code{\x}[0-9a-f]@{0,2@}
   \G hex numerical character value (standard only with two digits); a
   \G @code{\} before any other character is reserved.
   
 :noname \"-parse type ;  :noname \"-parse type ;
 :noname postpone s\" postpone type ;  :noname postpone s\" postpone type ;
 interpret/compile: .\" ( compilation 'ccc"' -- ; run-time -- )  \ gforth        dot-backslash-quote  interpret/compile: .\" ( compilation 'ccc"' -- ; run-time -- )  \ gforth        dot-backslash-quote
   \G Like @code{."}, but translates C-like \-escape-sequences (see
   \G @code{S\"}).
   
 0 [if] \ test  0 [if] \ test
     s" 123" drop 10 parse-num-x 123 <> throw drop .s      s" 123" drop 10 parse-num-x 123 <> throw drop .s

Removed from v.1.8  
changed lines
  Added in v.1.12


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>