djowel

Untitled

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