Changeset 28939ac15506b95f59142a06b7d6794a801f8198

Show
Ignore:
Timestamp:
08/27/10 18:32:04 (18 months ago)
Author:
Antti-Juhani Kaijanaho <antti-juhani@…>
Children:
92c18c14e163e2ab3200ccad6c6c0e6ee5c3e1a6
Parents:
19a2630635324aeed23f74061133ba433a639cd4
git-committer:
Antti-Juhani Kaijanaho <antti-juhani@…> (08/27/10 18:32:04)
Message:

Allow templates access to literal special characters

The variable "_" refers by default now to a structured value having
the following members:

  • hash containing "#"
  • dollar containing "$"
  • obrace containing "{"
  • cbrace containing "}"

So, for example, $_.dollar$ in a template will, in general, expand to
the dollar sign.

Closes #75.

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

Location:
tlate
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • tlate/tlate-test.cc

    r868b365 r28939ac  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    185185                BOOST_CHECK_EQUAL("\n", tester("\n",am)); 
    186186        } 
     187 
     188        BOOST_AUTO_TEST_CASE(std_hash) 
     189        { 
     190                tlate::data_model::ptr am(new tlate::data_model); 
     191                BOOST_CHECK_EQUAL("#", tester("$_.hash$",am)); 
     192        } 
     193 
     194        BOOST_AUTO_TEST_CASE(std_dollar) 
     195        { 
     196                tlate::data_model::ptr am(new tlate::data_model); 
     197                BOOST_CHECK_EQUAL("$", tester("$_.dollar$",am)); 
     198        } 
     199 
     200        BOOST_AUTO_TEST_CASE(std_obrace) 
     201        { 
     202                tlate::data_model::ptr am(new tlate::data_model); 
     203                BOOST_CHECK_EQUAL("{", tester("$_.obrace$",am)); 
     204        } 
     205        BOOST_AUTO_TEST_CASE(std_cbrace) 
     206        { 
     207                tlate::data_model::ptr am(new tlate::data_model); 
     208                BOOST_CHECK_EQUAL("}", tester("$_.cbrace$",am)); 
     209        } 
    187210} 
  • tlate/var.cc

    r868b365 r28939ac  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    1818 */ 
    1919 
     20#include "std_value.hh" 
    2021#include "var.hh" 
    2122 
     
    3233                if (!rv || rv->is_missing()) 
    3334                { 
    34                         logger::logline ll; 
    35                         ll << pos()  
    36                            << ": access of a missing variable '" << name << "'"; 
     35                        if (name == "_") 
     36                                rv = std_value::singleton; 
     37                        else 
     38                        { 
     39                                logger::logline ll; 
     40                                ll << pos()  
     41                                   << ": access of a missing variable '" 
     42                                   << name << "'"; 
     43                        } 
    3744                } 
    3845                return rv;