Advertisement
djowel

Untitled

Oct 22nd, 2011
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. [/=============================================================================
  2.  
  3. Gaea text template language!
  4.  
  5. Thanks to hkaiser, VeXocide and heller !!! on Spirit IRC
  6. Thanks to Daniel James and Dave Abrahams for added comments
  7. and suggestions (Boost Docs List).
  8.  
  9. ==============================================================================]
  10.  
  11. Reserved tokens:
  12. [
  13. ]
  14. [u
  15. [def
  16. [decl
  17. [lambda
  18. [/
  19. ["
  20. [""
  21. ""]
  22. \[
  23. \]
  24.  
  25. (the last 2 is for escaping [ and ])
  26.  
  27. Comments:
  28.  
  29. [/ comments. ]
  30. [/ nested [/ nested comments] comments. ]
  31. [/ balanced square braces [ and ] (i.e starts with [ and ends with ] and
  32. with equal number of [ and ]), are allowed inside comments. This is a
  33. good way to comment out code. ]
  34.  
  35. Lists:
  36.  
  37. [[a][b][c]] [/ 1st ]
  38. [[a][[b][c]]] [/ 2nd ]
  39.  
  40. Lists can form linear or hierarchical data structures. 1st is a
  41. 3-element list. 2nd is a 2-element list where the first element
  42. has 1 element and the second has 2 elements.
  43.  
  44. Formatting makes it clear:
  45.  
  46. 1st:
  47.  
  48. [
  49. [a][b][c]
  50. ]
  51.  
  52. 2nd:
  53.  
  54. [
  55. [a]
  56. [
  57. [b][c]
  58. ]
  59. ]
  60.  
  61. Strings:
  62.  
  63. This is a string
  64.  
  65. Jack and Jill went up the hill to fetch a pail of water.
  66. Jack fell down and broke his crown, and Jill came tumbling after.
  67.  
  68. 123 is a numeric string
  69.  
  70. Markups ([...]) are always significant, except inside escapes
  71. (see ["" Escapes below). Like HTML/XML spaces are coalesced unless
  72. they are inside the preformatted markup (see [" Preformatted below).
  73.  
  74. A string is just a special form of list with single character elements.
  75.  
  76. Unicode Code Points:
  77.  
  78. [u2018] [/ Generates unicode code point (hexadecimal). ]
  79.  
  80. Escapes:
  81.  
  82. \[ [/ Escapes the open bracket]
  83. \] [/ Escapes the close bracket]
  84. [""[x]""] [/ Escapes all occurances of [ and ] in x. ]
  85.  
  86. Preformatted:
  87.  
  88. [" some-text] [/ Make spaces, tabs and newlines significant ]
  89.  
  90. Symbols:
  91.  
  92. This-is-a-symbol
  93. ?
  94. *
  95. ==
  96. ?WTH
  97.  
  98. Symbols can be just about any string without spaces and the
  99. reserved tokens.
  100.  
  101. Function:
  102. Forward declarations:
  103.  
  104. [decl [foo]]
  105.  
  106. [decl [dup a]]
  107.  
  108. Forward declarations are good for recursion and is always perfect
  109. for documenting functions.
  110.  
  111. Definitions:
  112.  
  113. [def [foo] body] [/ nullary function def ]
  114.  
  115. [def foo body] [/ short for nullary function def ]
  116.  
  117. [def [dup a] [a][a]] [/ arguments always need to be evaluated, e.g. [a] ]
  118.  
  119. [def [cat a b] [a][b]]
  120.  
  121. Function invocation:
  122.  
  123. [foo] [/ nullary function ]
  124.  
  125. [dup apple pie] [/ unary function. argument is a string. ]
  126.  
  127. [dup [apple pie]] [/ unary function. argument is a 1-element list. ]
  128.  
  129. [cat [apple][pie]] [/ 2 arguments. argument is a 2-element list. ]
  130.  
  131. Example:
  132.  
  133. [def [f3 a b c]
  134. [def d de Guzman]
  135. [a] [d], [b] [d], [c] [d]
  136. ]
  137.  
  138. [f3 [Joel][Mariel][Tenji]] [/ returns Joel de Guzman, Mariel de Guzman, Tenji de Guzman ]
  139.  
  140. Variable args:
  141.  
  142. [decl [table title . rows]]
  143.  
  144. The dot '.' before the last formal argument signifies variable
  145. number of arguments. It is only allowed before the final formal
  146. argument. The actual arguments passed are collected in one list.
  147.  
  148. Example invocation:
  149.  
  150. [table title
  151. [[Heading 1] [Heading 2] [Heading 3]]
  152. [[R0-C0] [R0-C1] [R0-C2]]
  153. ]
  154.  
  155. Intrinsics:
  156.  
  157. [decl [head x]] [/ Get first element from x. ]
  158. [decl [tail x]] [/ Return a list or string without the first element of x. ]
  159. [decl [empty x]] [/ Return 1 if x is empty else 0. ]
  160. [decl [at x n]] [/ Return the nth element of x. ]
  161. [decl [size x]] [/ Return size of x. ]
  162. [decl [append x e]] [/ Append e to x. ]
  163. [decl [insert x e n]] [/ Insert e to x at position n. ]
  164. [decl [reverse x]] [/ Reverse x. ]
  165. [decl [join x y]] [/ Join x and y as one longer list. ]
  166.  
  167. [decl [fold x s f]] [/ For a list x, initial state s, and binary function f,
  168. fold returns the result of the repeated application of
  169. [f e s] for each element e of list x, to the result
  170. of the previous f invocation (s if it is the first call). ]
  171.  
  172. Many list operations can be implemented using fold. Yet, for the sake
  173. of efficiency, we provide these common operations as intrinsics.
  174.  
  175. [decl [transform x f]] [/ For a list x and function f, transform returns a new
  176. list with elements created by applying [f e] to each
  177. element e of x. ]
  178.  
  179. Since strings are just special forms of lists, all functions that accept
  180. lists can also accept strings.
  181.  
  182.  
  183. [decl [+ a b]] [/ Add a and b. both a and b are numeric integer strings. ]
  184. [decl [- a b]] [/ Subract a and b. both a and b are numeric integer strings. ]
  185. [decl [* a b]] [/ Multiply a and b. both a and b are numeric integer strings. ]
  186. [decl [/ a b]] [/ Divide a and b. both a and b are numeric integer strings. ]
  187. [decl [% a b]] [/ Remainder of a / b. both a and b are numeric integer strings. ]
  188.  
  189. [decl [== a b]] [/ Returns 1 if a == b. ]
  190. [decl [< a b]] [/ Returns 1 if a is less than b. ]
  191. [decl [&& a b]] [/ Returns a and b (boolean logic). ]
  192. [decl [|| a b]] [/ Returns a or b (boolean logic). ]
  193. [decl [if cond then else]] [/ Returns then if cond is 1, otherwise returns else. ]
  194.  
  195. Other comparisons and booleans can be synthesized from the basics above.
  196. For example ! can be defined as [def [! x] [if [x][0][1]]], != can be defined
  197. as [def [!= a b] [![==[a][b]]]], etc.
  198.  
  199. [decl [>> file]] [/ Loads file. ]
  200. [decl [<< file x]] [/ Saves x to file. ]
  201.  
  202. >> processes files (i.e. markups are significant). If you want to load
  203. files verbatim, enclose it in the escape markup. Example:
  204.  
  205. [""[>> text.gia]""]
  206.  
  207. Lambda Functions:
  208.  
  209. Functions are first class and can be passed to and returned from other
  210. functions. For example, the transform intrinsic requires a lambda function
  211. for its last (f) argument.
  212.  
  213. Here's an example of a lambda function:
  214.  
  215. [lambda [x] [dup [x]]]
  216.  
  217. Its syntax resembles a function definition.
  218.  
  219. Here's a sample invocation of transform:
  220.  
  221. [transform [list] [lambda [x] [dup [x]]]]
  222.  
  223. This doubles all elements of the list.
  224.  
  225.  
  226.  
  227.  
  228.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement