Position Independent Source Code

Artifact Content
Login

Artifact fa0d490fa3ef579e08e31f3080733c8f9f564318:


     1  #Change this function to set properties
     2  : *props* ( -- data )
     3  "
     4  DateTime Time
     5  String Message
     6  " process-props ;
     7  
     8  : main ( -- ) 
     9    [  "LogEntry" *props*  ] :args
    10    args gen-immutable-class
    11    args gen-ctor-call
    12  ;
    13  
    14  : NL ( -- nl ) "<br/>" ;
    15  
    16  : TAB ( -- t ) "&nbsp;&nbsp;&nbsp;&nbsp;" ;
    17  
    18  : process-props ( str -- props ) 
    19  str-trim "\n" str-split [
    20      ";" "" str-replace " " str-split
    21      splat :n :t <dict> $n <<-name $t <<-type
    22  ] vec-map 
    23  ;
    24  
    25  : gen-ctor ( name exposed-props -- str ) 
    26  	:props :name
    27  	${ 
    28  	    # Gen args
    29            "public " $name "(" NL 
    30  
    31  	    { $props [ :q ${ TAB $q ->type " " $q ->name } ] vec-each } ${ "," NL } str-join
    32  	    ")" NL 
    33  	    "{" NL
    34  	    # Gen assignments
    35  	    $props [ ->name :name TAB "this._" $name " = " $name ";" NL ] vec-each 
    36  	    "}" NL
    37  	}
    38  ;
    39  
    40  : gen-immutable-class ( name exposed-props -- str ) 
    41      :props :name
    42  	${
    43      	"class " $name " {" NL
    44      	# emit public get-only properties
    45      	$props [ :q $q ->type :t $q ->name :n
    46  			TAB "public " $t " " $n " { get { return _" $n "; } } " NL
    47      	] vec-each 
    48  	    NL
    49  
    50  	    # emit ctor
    51  	    $name $props gen-ctor NL   
    52  
    53  	    # emit private backing fields
    54  	    $props [ :q $q ->type :t $q ->name :n 
    55  	        TAB "private readonly " $t " _" $n ";" NL
    56  	    ] vec-each
    57  	   "}"
    58      }
    59  ;
    60  
    61  : gen-ctor-call ( name exposed-props -- str ) 
    62  	:props :name
    63  	${ "new " $name "(" NL
    64  	    { $props [ :q ${ TAB $q ->name ": " } ] vec-each } ${ "," NL } str-join
    65  	    ");"
    66  	}   
    67  ;
    68  
    69  main