Advertisement
Guest User

Untitled

a guest
Oct 19th, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 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. [/
  15. ["
  16. [""
  17. [`
  18. \[
  19. \]
  20.  
  21. (the last 2 is for escaping [ and ])
  22.  
  23. Comments:
  24.  
  25. [/ nested comments. ]
  26. [/ nested [/ nested comments] comments. ]
  27. [/ balanced square braces [ and ] (i.e starts with [ and ends with ] and
  28. with equal number of [ and ]), are allowed inside comments. This is a
  29. good way to comment out code. ]
  30.  
  31. Lists:
  32.  
  33. [a][b][c] [/ 1st ]
  34. [[a][b][c]] [/ 2nd ]
  35. [[a][[b][c]]] [/ 3rd ]
  36.  
  37. Lists can form linear or hierarchical data structures. 1st is a
  38. 3-element list. 2nd is a single element list with 3 elements. 3rd is a
  39. 2-element list where the first element is a single element list and the
  40. second has 2 elements. Formatting makes it clear:
  41.  
  42. 1st:
  43.  
  44. [a][b][c]
  45.  
  46. 2nd:
  47.  
  48. [
  49. [a][b][c]
  50. ]
  51.  
  52. 3rd:
  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. 123 is a numeric string
  68.  
  69. Markups ([...]) are always significant, except inside escapes
  70. (see ["" Escapes below). Like HTML/XML spaces are coalesced unless
  71. they are inside the preformatted markup (see [" Preformatted below).
  72.  
  73. A string is just a special form of list with single character elements.
  74.  
  75. Unicode Code Points:
  76.  
  77. [u2018] [/ Generates unicode code point (hexadecimal). ]
  78.  
  79. Escapes:
  80.  
  81. \[ [/ Escapes the open bracket]
  82. \] [/ Escapes the close bracket]
  83. ["" x] [/ Escapes all occurances of [ and ] in x. ]
  84.  
  85. Preformatted:
  86.  
  87. [" some-text] [/ Make spaces, tabs and newlines significant ]
  88.  
  89. Identifiers:
  90.  
  91. This-is-an-identifier
  92. ?
  93. *
  94. ==
  95. ?WTH
  96.  
  97. Identifiers can be just about any string without spaces and the
  98. reserved [ and ] characters.
  99.  
  100. Function:
  101. Forward declarations:
  102.  
  103. [def foo]
  104. [def dup a]
  105.  
  106. Definitions:
  107.  
  108. [def foo][body]
  109.  
  110. [def dup a][[`a][`a]]
  111.  
  112. [def follow a b][[`a][`b]]
  113.  
  114. Function invocation:
  115.  
  116. [`f0] [/ nullary function ]
  117. [`f1 apple pie] [/ unary function. argument is a string. ]
  118. [`f1 [apple pie]] [/ unary function. argument is a 1-element list. ]
  119. [`f2 [apple][pie]] [/ 2 arguments. argument is a 2-element list. ]
  120.  
  121. [/ Function invocations are explicit in Gaea to remove the
  122. ambiguity between invocations and lists and also to make
  123. functions first-class objects that can be passed as arguments
  124. ]
  125.  
  126. Intrinsics:
  127.  
  128. [def head x] [/ Get first element from x. ]
  129. [def tail x] [/ Return a list or string without the first element of x. ]
  130. [def empty x] [/ Return 1 if x is empty else 0. ]
  131. [def at x n] [/ Return the nth element of x. ]
  132. [def size x] [/ Return size of x. ]
  133. [def append x e] [/ Append e to x. ]
  134. [def insert x e n] [/ Insert e to x at position n. ]
  135. [def reverse x] [/ Reverse x. ]
  136. [def join x y] [/ Join x and y as one longer list. ]
  137.  
  138. [def fold x s f] [/ For a list x, initial state s, and binary function f,
  139. fold returns the result of the repeated application of
  140. [f e s] for each element e of list x, to the result
  141. of the previous f invocation (s if it is the first call). ]
  142.  
  143. [/ Many list operations can be implemented using fold. Yet, for the sake
  144. of efficiency, we provide these common operations as intrinsics.
  145. ]
  146.  
  147. [def transform x f] [/ For a list x and function f, transform returns a new
  148. list with elements created by applying [f e] to each
  149. element e of x. ]
  150.  
  151. [/ Since strings are just special forms of lists, all functions that accept
  152. lists can also accept strings.
  153. ]
  154.  
  155. [def + a b] [/ Add a and b. both a and b are numeric integer strings. ]
  156. [def - a b] [/ Subract a and b. both a and b are numeric integer strings. ]
  157. [def * a b] [/ Multiply a and b. both a and b are numeric integer strings. ]
  158. [def / a b] [/ Divide a and b. both a and b are numeric integer strings. ]
  159. [def % a b] [/ Remainder of a / b. both a and b are numeric integer strings. ]
  160.  
  161. [def == a b] [/ Returns 1 if a == b. ]
  162. [def < a b] [/ Returns 1 if a is less than b. ]
  163. [def && a b] [/ Returns a and b (boolean logic). ]
  164. [def || a b] [/ Returns a or b (boolean logic). ]
  165. [def if cond then else] [/ Returns then if cond is 1, otherwise returns else. ]
  166.  
  167. [/ Other comparisons and booleans can be synthesized from the basics above.
  168. For example ! can be defined as [def ! x][[`if [`x][0][1]]], != can be defined
  169. as [def != a b][[`![`==[`a][`b]]]], etc.
  170. ]
  171.  
  172. [def >> file] [/ Loads file. ]
  173. [def << file x] [/ Saves x to file. ]
  174.  
  175. [/ >> processes files (i.e. markups are significant). If you want to load
  176. files verbatim, enclose it in the escape markup. Example:
  177.  
  178. [""[>> text.gia]]
  179. ]
  180.  
  181. Example:
  182.  
  183. [def f3 a b c]
  184. [
  185. [def d][de Guzman]
  186. [`a] [`d], [`b] [`d], [`c] [`d]
  187. ]
  188.  
  189. [`f3 [Joel][Mariel][Tenji]] [/ returns Joel de Guzman, Mariel de Guzman, Tenji de Guzman ]
  190.  
  191. Error conditions:
  192.  
  193.  
  194.  
  195.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement