Advertisement
djowel

Untitled

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