Advertisement
djowel

Untitled

Oct 22nd, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 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. Function:
  91. Forward declarations:
  92.  
  93. [decl [foo]]
  94.  
  95. [decl [dup a]]
  96.  
  97. Forward declarations are good for recursion and is always perfect
  98. for documenting functions.
  99.  
  100. Definitions:
  101.  
  102. [def [foo] body] [/ nullary function def ]
  103.  
  104. [def foo body] [/ short for nullary function def ]
  105.  
  106. [def [dup a] [a][a]] [/ arguments always need to be evaluated, e.g. [a] ]
  107.  
  108. [def [cat a b] [a][b]]
  109.  
  110. Function invocation:
  111.  
  112. [foo] [/ nullary function ]
  113.  
  114. [dup apple pie] [/ unary function. argument is a string. ]
  115.  
  116. [dup [apple pie]] [/ unary function. argument is a 1-element list. ]
  117.  
  118. [cat [apple][pie]] [/ 2 arguments. argument is a 2-element list. ]
  119.  
  120. Function identifier:
  121.  
  122. Function identifiers can either consist of:
  123.  
  124. An initial alphabetic character or the underscore,
  125. followed by zero or more alphanumeric characters or
  126. the underscore. This is similar to your typical C/C++ identifier.
  127. One to four character operator (a non-alphanumeric printable character)
  128.  
  129. Formal Arguments
  130.  
  131. Formal arguments are identifiers consisting of an initial
  132. alphabetic character or the underscore, followed by zero
  133. or more alphanumeric characters or the underscore. This is
  134. similar to your typical C/C++ identifier.
  135.  
  136. Example:
  137.  
  138. [def [f3 a b c]
  139. [def d de Guzman]
  140. [a] [d], [b] [d], [c] [d]
  141. ]
  142.  
  143. [f3 [Joel][Mariel][Tenji]] [/ returns Joel de Guzman, Mariel de Guzman, Tenji de Guzman ]
  144.  
  145. Variable args:
  146.  
  147. [decl [table title . rows]]
  148.  
  149. The dot '.' before the last formal argument signifies variable
  150. number of arguments. It is only allowed before the final formal
  151. argument. The actual arguments passed are collected in one list.
  152.  
  153. Example invocation:
  154.  
  155. [table title
  156. [[Heading 1] [Heading 2] [Heading 3]]
  157. [[R0-C0] [R0-C1] [R0-C2]]
  158. ]
  159.  
  160. Intrinsics:
  161.  
  162. [decl [head x]] [/ Get first element from x. ]
  163. [decl [tail x]] [/ Return a list or string without the first element of x. ]
  164. [decl [empty x]] [/ Return 1 if x is empty else 0. ]
  165. [decl [at x n]] [/ Return the nth element of x. ]
  166. [decl [size x]] [/ Return size of x. ]
  167. [decl [append x e]] [/ Append e to x. ]
  168. [decl [insert x e n]] [/ Insert e to x at position n. ]
  169. [decl [reverse x]] [/ Reverse x. ]
  170. [decl [join x y]] [/ Join x and y as one longer list. ]
  171.  
  172. [decl [fold x s f]] [/ For a list x, initial state s, and binary function f,
  173. fold returns the result of the repeated application of
  174. [f e s] for each element e of list x, to the result
  175. of the previous f invocation (s if it is the first call). ]
  176.  
  177. Many list operations can be implemented using fold. Yet, for the sake
  178. of efficiency, we provide these common operations as intrinsics.
  179.  
  180. [decl [transform x f]] [/ For a list x and function f, transform returns a new
  181. list with elements created by applying [f e] to each
  182. element e of x. ]
  183.  
  184. Since strings are just special forms of lists, all functions that accept
  185. lists can also accept strings.
  186.  
  187.  
  188. [decl [+ a b]] [/ Add a and b. both a and b are numeric integer strings. ]
  189. [decl [- a b]] [/ Subract a and b. both a and b are numeric integer strings. ]
  190. [decl [* a b]] [/ Multiply a and b. both a and b are numeric integer strings. ]
  191. [decl [/ a b]] [/ Divide a and b. both a and b are numeric integer strings. ]
  192. [decl [% a b]] [/ Remainder of a / b. both a and b are numeric integer strings. ]
  193.  
  194. [decl [== a b]] [/ Returns 1 if a == b. ]
  195. [decl [< a b]] [/ Returns 1 if a is less than b. ]
  196. [decl [&& a b]] [/ Returns a and b (boolean logic). ]
  197. [decl [|| a b]] [/ Returns a or b (boolean logic). ]
  198. [decl [if cond then else]] [/ Returns then if cond is 1, otherwise returns else. ]
  199.  
  200. Other comparisons and booleans can be synthesized from the basics above.
  201. For example ! can be defined as [def [! x] [if [x][0][1]]], != can be defined
  202. as [def [!= a b] [![==[a][b]]]], etc.
  203.  
  204. [decl [>> file]] [/ Loads file. ]
  205. [decl [<< file x]] [/ Saves x to file. ]
  206.  
  207. >> processes files (i.e. markups are significant). If you want to load
  208. files verbatim, enclose it in the escape markup. Example:
  209.  
  210. [""[>> text.gia]""]
  211.  
  212. Lambda Functions:
  213.  
  214. Functions are first class and can be passed to and returned from other
  215. functions. For example, the transform intrinsic requires a lambda function
  216. for its last (f) argument.
  217.  
  218. Here's an example of a lambda function:
  219.  
  220. [lambda [x] [dup [x]]]
  221.  
  222. Its syntax resembles a function definition.
  223.  
  224. Here's a sample invocation of transform:
  225.  
  226. [transform [list] [lambda [x] [dup [x]]]]
  227.  
  228. This doubles all elements of the list.
  229.  
  230.  
  231.  
  232.  
  233.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement