hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

README (959B)


      1 This module provides support for formatting of large or complex strings beyond
      2 the scope of [[fmt::]]. A template is compiled using [[compile]], then executed
      3 with [[execute]] to print formatted text to an [[io::handle]].
      4 
      5 The template format is a string with variables substituted using "$". Variable
      6 names consist of alphanumeric ASCII characters (i.e. for which
      7 [[ascii::isalnum]] returns true) or underscores ('_'). A literal "$" may be
      8 printed by using it twice: "$$". Variables may also be used with braces, i.e.
      9 ${variable}, so that they can be placed immediately next to alphanumeric
     10 characters; such variables may include non-alphanumeric characters other than
     11 '{' and '}'.
     12 
     13 	const src = "Hello, $user! Your balance is $$$balance.\n";
     14 	const template = template::compile(src)!;
     15 	defer template::finish(&template);
     16 	template::execute(&template, os::stdout,
     17 		("user", "ddevault"),
     18 		("balance", 1000),
     19 	)!; // "Hello, ddevault! Your balance is $1000.