Changeset 37863 in project


Ignore:
Timestamp:
09/01/19 05:06:30 (3 weeks ago)
Author:
Kon Lovett
Message:

refactor

Location:
release/5/string-utils/trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • release/5/string-utils/trunk/string-interpolation-body.scm

    r37862 r37863  
    66;; Issues
    77;;
    8 ;; - #{...} is a WART! Use #..., hello!
    9 ;;
    108;; - Uses ##sys#print-to-string
    119
    12 (: string-interpolate/sanity (string #!rest --> list))
     10(: string-interpolate (string #!rest --> list))
    1311;
    14 (define (string-interpolate/sanity str #!key (eval-tag #\#) (insane #f))
     12(define (string-interpolate str #!key (eval-tag #\#) #;(insane #f))
    1513  (let ((strp (open-input-string str)))
    1614    ;objs - LIFO queue (list) of objects
    1715    ;chrs - LIFO queue (list) of chars
    1816    (let advance ((objs '()) (chrs #f))
    19 
     17      ;
    2018      ;"inject" char in front
    2119      (define (push-char ch)
    2220        `(,ch ,@(or chrs '())) )
    23 
     21      ;
    2422      ;end of, possible, intermediate string
    2523      (define (pop-string)
     
    2725          objs
    2826          `(,(reverse-list->string chrs) ,@objs) ) )
    29 
     27      ;
    3028      ;"inject" object in front
    3129      (define (push-object obj)
    3230        `(,obj ,@(pop-string)) )
    33 
     31      ;
    3432      ;in the body or not
    3533      (let ((ch (read-char strp)))
    3634        (cond
    37 
     35          ;
    3836          ;we're done?
    3937          ((eof-object? ch)
    4038            `(##sys#print-to-string (list ,@(reverse! (pop-string)))) )
    41 
     39          ;
    4240          ;we're interpolating?
    4341          ((char=? eval-tag ch)
     42            ;lookahead 1
    4443            (let ((ch (peek-char strp)))
    4544              (cond
    46                 ;trailing eval-tag? then literal
     45                ;
     46                ;trailing tag? then literal
    4747                ((eof-object? ch)
    4848                  (advance objs (push-char eval-tag)) )
    49                 ;<tag><tag> -> <tag>
     49                ;
     50                ;read tag : <tag><tag> -> <tag>
    5051                ((char=? eval-tag ch)
    51                   (begin
    52                     (read-char strp) ;drop char
    53                     (advance objs (push-char eval-tag)) ) )
     52                  (advance objs (push-char (read-char strp))) )
     53                ;
    5454                ;WART read wrapped expression
    55                 ((and insane (char=? #\{ ch))
     55                #;((and insane (char=? #\{ ch))
    5656                  ;!!! we do not test for #\} !!!
    5757                  (advance (push-object (car (read strp))) #f) )
     58                ;
    5859                ;read expression
    5960                (else
    6061                  (advance (push-object (read strp)) #f) ) ) ) )
    61 
     62          ;
    6263          ;ordinary char!
    6364          (else
    6465            (advance objs (push-char ch)) ) ) ) ) ) )
    6566
    66 (: string-interpolate (string #!rest --> list))
     67#|
     68(: string-interpolate/insanity (string #!rest --> list))
    6769;
    68 (define (string-interpolate str #!key (eval-tag #\#))
    69   (parameterize ((parentheses-synonyms #t))
    70     (string-interpolate/sanity str #:eval-tag eval-tag #:insane #t) ) )
    71 
    72 ;;;
    73 
    74 (set-sharp-string-interpolation-syntax
    75   (if (feature? 'sanity)
    76     string-interpolate/sanity
    77     string-interpolate))
     70(define (string-interpolate/insanity str #!key (eval-tag #\#))
     71  (string-interpolate str #:eval-tag eval-tag $:insane #t) )
     72|#
  • release/5/string-utils/trunk/string-interpolation.scm

    r37858 r37863  
    33;;;; Kon Lovett, Sep '17
    44
    5 (module string-interpolation
    6 
    7 (;export
    8   string-interpolate)
     5(module string-interpolation () #;(string-interpolate)
    96
    107;reverse-list->string
     
    129(import scheme
    1310  (chicken base)
    14   (chicken platform)
    15   (chicken type)
    16   (only (chicken string) ->string reverse-list->string)
    17   (only (srfi 1) reverse!)
    18   (only (srfi 13) string-concatenate-reverse)
     11  string-interpolator
    1912  string-interpolation-syntax)
    2013
    21 ;refs parentheses-synonyms
     14;;;
    2215
    23 (include "string-interpolation-body")
     16(set-sharp-string-interpolation-syntax string-interpolate)
     17
     18#;
     19(set-sharp-string-interpolation-syntax
     20  (if (feature? 'insanity)
     21    string-interpolate/insanity
     22    string-interpolate))
    2423
    2524) ;string-interpolation
  • release/5/string-utils/trunk/string-utils.egg

    r37858 r37863  
    33
    44((synopsis "String Utilities")
    5  (version "2.2.1")
     5 (version "2.3.0")
    66 (category data)
    77 (author "[[kon lovett]]")
     
    1616 (test-dependencies test)
    1717 (components
     18  (extension string-interpolation-syntax
     19    #;(inline-file)
     20    (types-file)
     21    (csc-options "-local" "-O3" "-d1" "-no-procedure-checks") )
     22  (extension string-interpolator
     23    #;(inline-file)
     24    (types-file)
     25    (source-dependencies string-interpolation-body.scm)
     26    (csc-options "-local" "-O3" "-d1" "-no-procedure-checks") )
     27  (extension utf8-string-interpolator
     28    #;(inline-file)
     29    (types-file)
     30    (source-dependencies string-interpolation-body.scm)
     31    (csc-options "-local" "-O3" "-d1" "-no-procedure-checks") )
     32  (extension string-interpolation
     33    #;(inline-file)
     34    (types-file)
     35    (component-dependencies string-interpolator string-interpolation-syntax)
     36    (csc-options "-local" "-O3" "-d1" "-no-procedure-checks") )
     37  (extension utf8-string-interpolation
     38    #;(inline-file)
     39    (types-file)
     40    (component-dependencies utf8-string-interpolator string-interpolation-syntax)
     41    (csc-options "-local" "-O3" "-d1" "-no-procedure-checks") )
    1842  (extension to-hex
    1943    #;(inline-file)
     
    3458    (component-dependencies unicode-utils)
    3559    (csc-options "-local" "-O3" "-d1" "-no-procedure-checks") )
    36   (extension string-interpolation-syntax
    37     #;(inline-file)
    38     (types-file)
    39     (csc-options "-local" "-O3" "-d1" "-no-procedure-checks") )
    40   (extension string-interpolation
    41     #;(inline-file)
    42     (types-file)
    43     (component-dependencies string-interpolation-syntax)
    44     (csc-options "-local" "-O3" "-d1" "-no-procedure-checks") )
    45   (extension utf8-string-interpolation
    46     #;(inline-file)
    47     (types-file)
    48     (component-dependencies string-interpolation-syntax)
    49     (csc-options "-local" "-O3" "-d1" "-no-procedure-checks") )
    5060  (extension string-utils
    5161    #;(inline-file)
  • release/5/string-utils/trunk/tests/string-utils-test.scm

    r37679 r37863  
    7070;;
    7171
    72 (import string-interpolation)
     72(import string-interpolation-trans)
    7373
    7474(test-group "String Interpolation"
     
    8080)
    8181
    82 (import (prefix utf8-string-interpolation utf8::))
     82(import (prefix utf8-string-interpolation-trans utf8::))
    8383
    8484(test-group "String Interpolation (UTF-8)"
     
    9494;must be "top level"; cannot be test-group
    9595(test-begin "String Interpolation SYNTAX")
     96  ;
    9697  (set-sharp-string-interpolation-syntax string-interpolate)
     98  (test
     99    '((##sys#print-to-string (list "foo " (+ 1 2) " bar")))
     100    (list (call-with-input-string "#\"foo #(+ 1 2) bar\"" read)))
    97101  (test
    98102    '((##sys#print-to-string (list "foo " (+ 1 2) " bar")))
    99103    (list (call-with-input-string "#\"foo #{(+ 1 2)} bar\"" read)))
    100104  (set-sharp-string-interpolation-syntax #f)
    101 
    102   (set-sharp-string-interpolation-syntax
    103     (cute string-interpolate <> eval-tag: #\$))
     105  ;
     106  (set-sharp-string-interpolation-syntax (cute string-interpolate <> eval-tag: #\$))
     107  (test
     108    '((##sys#print-to-string (list "foo " (+ 1 2) " bar")))
     109    (list (call-with-input-string "#\"foo $(+ 1 2) bar\"" read)))
    104110  (test
    105111    '((##sys#print-to-string (list "foo " (+ 1 2) " bar")))
  • release/5/string-utils/trunk/utf8-string-interpolation.scm

    r37858 r37863  
    33;;;; Kon Lovett, Sep '17
    44
    5 (module utf8-string-interpolation
     5(module utf8-string-interpolation () #;(string-interpolate)
    66
    7 (;export
    8   string-interpolate)
    9 
    10 (import (except scheme read-char #;peek-char #;read)
     7(import scheme
    118  (chicken base)
    12   (chicken platform)
    13   (chicken type)
    14   (only (chicken string) ->string)
    15   (only (srfi 1) reverse!)
    16   (only utf8-srfi-13 string-concatenate-reverse #;reverse-list->string)
    17   (only utf8 read-char list->string #;peek-char #;read)
     9  utf8-string-interpolator
    1810  string-interpolation-syntax)
    1911
    20 ;refs parentheses-synonyms
     12;;;
    2113
    22 (define-inline (reverse-list->string clist)
    23   (list->string (reverse! clist)) )
     14(set-sharp-string-interpolation-syntax string-interpolate)
    2415
    25 (include "string-interpolation-body")
     16#;
     17(set-sharp-string-interpolation-syntax
     18  (if (feature? 'insanity)
     19    string-interpolate/insanity
     20    string-interpolate))
    2621
    2722) ;utf8-string-interpolation
Note: See TracChangeset for help on using the changeset viewer.