Changeset 31397 in project


Ignore:
Timestamp:
09/12/14 04:33:55 (5 years ago)
Author:
Ivan Raikov
Message:

ersatz: further updates to new line handling in lexer logic mode

Location:
release/4/ersatz/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/ersatz/trunk/make-ersatz-lexer.scm

    r31396 r31397  
    3636                           (end-expand '("}}" "}}\n"))
    3737                           (begin-logic "{%")
    38                            (end-logic "%}")
     38                           (end-logic '("%}" "%}\n"))
    3939                           )
    4040
     
    125125
    126126  (fprintf output-port #<<EOF
    127 ~S     (cases lexer-mode (lexer-curmode)
     127~A     (cases lexer-mode (lexer-curmode)
    128128              (LexerPlain ()
    129129                 (let ((text (lexer-get-text)))
     
    137137
    138138EOF
    139    begin-logic)
    140 
    141   (fprintf output-port #<<EOF
    142 ~S     (cases lexer-mode (lexer-curmode)
     139  (cond ((string? begin-logic)
     140         (sprintf "~S" begin-logic))
     141        ((pair? begin-logic)
     142         (string-join (map (lambda (s) (sprintf "~S" s)) begin-logic) "|"))
     143        (else (error 'ersatz "invalid begin-logic specification" begin-logic))))
     144
     145  (fprintf output-port #<<EOF
     146~A     (cases lexer-mode (lexer-curmode)
    143147              (LexerLogic ()
    144148                (lexer-curmode (LexerPlain))
     
    148152
    149153EOF
    150     end-logic)
     154  (cond ((string? end-logic)
     155         (sprintf "~S" end-logic))
     156        ((pair? end-logic)
     157         (string-join (map (lambda (s) (sprintf "~S" s)) end-logic) "|"))
     158        (else (error 'ersatz "invalid end-logic specification" end-logic))))
     159
    151160
    152161(fprintf output-port #<<EOF
  • release/4/ersatz/trunk/tests/run.scm

    r31396 r31397  
    280280  (test
    281281#<<EOF
    282 
    283282  <div class="blog-post">
    284283    <h3>Post One title</h3>
     
    286285     Post One body    </div>
    287286  </div>
    288 
    289287  <div class="blog-post">
    290288    <h3>Post Two title</h3>
     
    387385               (tval-equal? (Tstr (from-file "extends.tmpl"
    388386                                             env: (template-std-env search-path: '("tests/tmpl" "tmpl"))))
    389                             (Tstr "extended\n\n")))
     387                            (Tstr "extended")))
    390388
    391389  (test-assert "include"
    392390               (tval-equal? (Tstr (from-file "include.tmpl"
    393391                                             env: (template-std-env search-path: '("tests/tmpl" "tmpl"))))
    394                             (Tstr "this is included\n\n")))
     392                            (Tstr "this is included\n")))
    395393 
    396394  (let ((macro-three-words #<<EOF
     
    407405                         (string-append macro-three-words
    408406                                        "{{ three_words(\"this\", \"is\", \"it!\") }}")))
    409                   (Tstr "\nthis is it!")))
     407                  (Tstr "this is it!")))
    410408       
    411409  (test-assert "caller"
     
    418416                                         "{% endcall %}")
    419417                                        )))
    420                   (Tstr "\nthis is it! by chicken scheme")))
     418                  (Tstr "this is it! by chicken scheme")))
    421419
    422420)
  • release/4/ersatz/trunk/tests/tmpl/cheatsheet.tmpl

    r28550 r31397  
    1212
    13131+1 = {{ 1 + 1 }}
     14
    14151-1 = {{ 1 - 1 }}
     16
    15172*4 = {{ 2 * 4 }}
     18
    16194/2 = {{ 4 / 2 }}
     20
    17218^3 = {{ 8 ** 3 }}
     22
    18238%3 = {{ 8 % 3 }}
     24
    1925not true = {{ !true }}
     26
    2027not true(2) = {{ not true }}
    2128
     
    3138{% set danger = "<script>alert(1)</script>" %}
    3239expand with escape = {{ danger }}
     40
    3341expand with safe = {{ danger|safe }}
    3442
     
    7886
    7987name = {{obj.name}}
     88
    8089age = {{obj.age}}
     90
    8191obj["name"] = {{ obj["name"] }}
     92
    8293obj["age"] = {{ obj["age"] }}
    8394
     
    8697
    8798upper test:{{ "must be upper"|upper }}
     99
    88100word count for "hoge hage hige" = {{ "hoge hage hige"|wordcount}}
     101
    89102
    90103func test
     
    92105
    93106range(0,3) = {% for x in range(0,3) %}{{x}}{% endfor %}
     107
    94108range(3,0) = {% for x in range(3,0) %}{{x}}{% endfor %}
    95109
    96110strlen("testtest") = {{ strlen("testtest") }}
     111
    97112strlen("日本語") = {{ strlen("日本語") }}
    98113
    99114round floor of 1.5 = {{1.5|round("floor")|int}}
     115
    100116round ceil of 1.5 = {{1.5|round("ceil")|int}}
    101117
    102118join(",", [1,2,3,4,5]) = {{ join(",", [1,2,3,4,5]) }}
     119
    103120
    104121{% with long_list =  [10,20,30,40,50,60,70,80,90,100] %}
    105122{% for row in slice(4, long_list) %}
    106   {% set y = loop.index %}
    107   {% for col in row %}
    108   {% set x = loop.index %}
     123{% set y = loop.index %}
     124{% for col in row %}
     125{% set x = loop.index %}
    109126  {{x}},{{y}} = {{col}}
    110   {% endfor %}
     127
     128{% endfor %}
    111129{% endfor %}
    112130{% endwith %}
     
    124142
    125143{% for x in [1,2,3,4.5,"str"] %}{{x}}{% endfor %}
     144
    126145{% for x in [] %}{{x}}{% endfor %}
    127146
     
    129148
    130149{{ "{{" }}
     150
    131151
    132152syntax test "is"
     
    134154
    1351556 is divisibleby 4 = {{ 6 is divisibleby(4) }}
     156
    1361576 is divisibleby 3 = {{ 6 is divisibleby(3) }}
     158
    1371596 is divisibleby 2 = {{ 6 is divisibleby(2) }}
     160
    1381616 is divisibleby 2 = {{ 6 is divisibleby 2 }}
     162
    1391636 is divisibleby 3 via func = {{ divisibleby(3,6) }}
    140164
     
    158182inner text!
    159183args of call = {{a}},{{b}}
     184
    160185macro name = {{delay_macro.name}}
     186
    161187via caller = {{delay_macro.caller}}
    162188{% endcall %}
     
    166192<h2>{{subject}}</h2>
    167193{{ caller() }}
     194
    168195<a href="#top">back to top</a>
    169196{% endmacro %}
     
    185212
    186213{{ test_macro(30,40) }}
     214
    187215{{ other_macro(50,60) }}
    188216
     
    192220this is test_caller
    193221age={{age}}
     222
    194223class={{kwargs.class}}
     224
    195225{{caller (x,y,z,kw_from_test_caller="yeah")}}
     226
    196227{% endmacro %}
    197228
     
    199230{% call(a,b=100) test_caller(100,200,300,class="mytest") %}
    200231name={{test_caller.name}}
     232
    201233caller={{test_caller.caller}}
     234
    202235catch_kwargs={{test_caller.catch_kwargs}}
     236
    203237catch_vargs={{test_caller.catch_vargs}}
     238
    204239kw_from_test_caller={{kwargs.kw_from_test_caller}}
     240
    205241{% endcall %}
    206242
     
    217253{% set hige = 20 %}
    218254inner with hige = {{hige}}
     255
    219256hige is defined = {{ hige is defined }}
     257
    220258{% endwith %}
    221259
    222260after with hige = {{hige}}
     261
    223262hige is defined = {{ hige is defined }}
    224263
     
    256295{% autoescape false %}
    257296{{ script }}
     297
    258298{% endautoescape %}
    259299
     
    264304
    265305person["age"] = {{ person["age"] }}
     306
    266307person.age = {{ person.age }}
     308
    267309person["name"] = {{ person["name"] }}
     310
    268311person.name = {{ person.name }}
     312
    269313
    270314eval
Note: See TracChangeset for help on using the changeset viewer.