Changeset 38231 in project


Ignore:
Timestamp:
03/08/20 21:47:35 (3 weeks ago)
Author:
Kon Lovett
Message:

add file, line, date, time macros (inspired by Kooda on #chicken irc Mar 7 23:39)

Location:
release/5/moremacros/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • release/5/moremacros/trunk/moremacros.egg

    r37955 r38231  
    22
    33((synopsis "More miscellaneous macros")
    4  (version "2.1.0")
     4 (version "2.2.0")
    55 (category lang-exts)
    66 (author "[[kon lovett]]")
  • release/5/moremacros/trunk/moremacros.scm

    r37954 r38231  
    66
    77(;export
     8  __date__ __time__
     9  __line__ __file__
    810  switch
    911  ->boolean
     
    2224  $grlaux$ )
    2325
    24 (import scheme
    25   (chicken base)
    26   (chicken syntax)
    27   (only (chicken string) ->string)
    28   (only miscmacros repeat define-parameter))
     26(import scheme)
     27(import (chicken base))
     28(import (chicken syntax))
     29(import (only (chicken string) ->string))
     30(import (only miscmacros repeat define-parameter))
    2931
    3032;;; Helpers
    3133
    32 (import-for-syntax (only (chicken string) conc))
     34(import-for-syntax (only (chicken string) conc string-split))
     35(import-for-syntax (only (chicken time posix) seconds->local-time time->string))
    3336
    3437; maybe a problem with expansion environment namespace pollution
    3538(define-for-syntax (make-identifier . elts)
    3639  (string->symbol (apply conc (map strip-syntax elts))) )
     40
     41;;;
     42
     43(define-syntax __date__
     44  (er-macro-transformer
     45    (lambda (e r c)
     46      (time->string (seconds->local-time) "%v" #;"%b %e %Y") ) ) )
     47
     48(define-syntax __time__
     49  (er-macro-transformer
     50    (lambda (e r c)
     51      (time->string (seconds->local-time) "%T") ) ) )
     52
     53;inspired by Kooda on #chicken irc Mar 7 23:39
     54
     55(define-for-syntax (line-info-values e)
     56  (let ((v (get-line-number e)))
     57    (cond
     58      ((not v)
     59        (values #f #f) )
     60      ((string? v)
     61        (apply values (string-split v ":" #t)) )
     62      (else
     63        (values v #f) ) ) ) )
     64
     65(define-syntax __line__
     66  (er-macro-transformer
     67    (lambda (e r c)
     68      (let-values (((f l) (line-info-values e)))
     69        (and l (string->number l)) ) ) ) )
     70
     71(define-syntax __file__
     72  (er-macro-transformer
     73    (lambda (e r c)
     74      (let-values (((f l) (line-info-values e)))
     75        f ) ) ) )
    3776
    3877;;;
  • release/5/moremacros/trunk/tests/moremacros-test.scm

    r37954 r38231  
    11(import test)
    22
     3(include "test-gloss.incl")
     4
     5;;
     6
     7(test-begin "More Macros")
     8
    39(import moremacros)
     10
     11;;
     12
     13(cond-expand
     14  (compiling
     15    (test-group "Expansion Time Info"
     16      (let ((lno (__line__)))
     17        (glossf "(__date__): ~S" (__date__))
     18        (glossf "(__time__): ~S" (__time__))
     19        (glossf "(__file__): ~S" (__file__))
     20        (glossf "(__line__): ~S" lno)
     21        (test "(__file__)" "moremacros-test.scm" (__file__))
     22        (test "(__line__)" 16 lno) ) ) )
     23  (else) )
    424
    525;;
     
    124144;;
    125145
     146(test-end  "More Macros")
     147
    126148(test-exit)
Note: See TracChangeset for help on using the changeset viewer.