layo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. data/LICENSE +26 -0
  2. data/README.mkd +103 -0
  3. data/Rakefile +21 -0
  4. data/UnicodeData.txt +23697 -0
  5. data/bin/layo +22 -0
  6. data/layo.gemspec +23 -0
  7. data/lib/layo.rb +11 -0
  8. data/lib/layo/ast.rb +5 -0
  9. data/lib/layo/ast/block.rb +13 -0
  10. data/lib/layo/ast/expression.rb +14 -0
  11. data/lib/layo/ast/node.rb +6 -0
  12. data/lib/layo/ast/program.rb +9 -0
  13. data/lib/layo/ast/statement.rb +10 -0
  14. data/lib/layo/interpreter.rb +360 -0
  15. data/lib/layo/lexer.rb +162 -0
  16. data/lib/layo/parser.rb +371 -0
  17. data/lib/layo/peekable.rb +31 -0
  18. data/lib/layo/runtime_error.rb +9 -0
  19. data/lib/layo/syntax_error.rb +14 -0
  20. data/lib/layo/tokenizer.rb +119 -0
  21. data/lib/layo/unexpected_token_error.rb +13 -0
  22. data/lib/layo/unicode.rb +23614 -0
  23. data/lib/layo/unknown_token_error.rb +7 -0
  24. data/spec/interpreter_spec.rb +52 -0
  25. data/spec/lexer_spec.rb +176 -0
  26. data/spec/parser_spec.rb +373 -0
  27. data/spec/source/basic/comments.lol +16 -0
  28. data/spec/source/basic/comments.out +2 -0
  29. data/spec/source/basic/line-continuation.lol +8 -0
  30. data/spec/source/basic/line-continuation.out +2 -0
  31. data/spec/source/basic/line-endings.lol +5 -0
  32. data/spec/source/basic/line-endings.out +3 -0
  33. data/spec/source/basic/minimal.lol +2 -0
  34. data/spec/source/casting/boolean.lol +8 -0
  35. data/spec/source/casting/boolean.out +5 -0
  36. data/spec/source/casting/float.lol +10 -0
  37. data/spec/source/casting/float.out +5 -0
  38. data/spec/source/casting/int.lol +9 -0
  39. data/spec/source/casting/int.out +4 -0
  40. data/spec/source/casting/nil.lol +9 -0
  41. data/spec/source/casting/nil.out +4 -0
  42. data/spec/source/casting/string.lol +5 -0
  43. data/spec/source/casting/string.out +2 -0
  44. data/spec/source/expressions/boolean.lol +30 -0
  45. data/spec/source/expressions/boolean.out +17 -0
  46. data/spec/source/expressions/cast.lol +28 -0
  47. data/spec/source/expressions/cast.out +20 -0
  48. data/spec/source/expressions/function.lol +24 -0
  49. data/spec/source/expressions/function.out +4 -0
  50. data/spec/source/expressions/math.lol +9 -0
  51. data/spec/source/expressions/math.out +7 -0
  52. data/spec/source/expressions/string.lol +20 -0
  53. data/spec/source/expressions/string.out +7 -0
  54. data/spec/source/statements/assignment.lol +8 -0
  55. data/spec/source/statements/assignment.out +3 -0
  56. data/spec/source/statements/cast.lol +11 -0
  57. data/spec/source/statements/cast.out +3 -0
  58. data/spec/source/statements/declaration.lol +9 -0
  59. data/spec/source/statements/declaration.out +2 -0
  60. data/spec/source/statements/expression.lol +10 -0
  61. data/spec/source/statements/expression.out +2 -0
  62. data/spec/source/statements/if_then_else.lol +42 -0
  63. data/spec/source/statements/if_then_else.out +3 -0
  64. data/spec/source/statements/input.in +1 -0
  65. data/spec/source/statements/input.lol +4 -0
  66. data/spec/source/statements/input.out +1 -0
  67. data/spec/source/statements/loop.lol +50 -0
  68. data/spec/source/statements/loop.out +20 -0
  69. data/spec/source/statements/print.lol +7 -0
  70. data/spec/source/statements/print.out +2 -0
  71. data/spec/source/statements/switch.lol +95 -0
  72. data/spec/source/statements/switch.out +12 -0
  73. data/spec/tokenizer_spec.rb +105 -0
  74. metadata +135 -0
@@ -0,0 +1,16 @@
1
+ BTW One line comment
2
+ HAI 1.2
3
+ BTW another comment
4
+ VISIBLE "comment test"
5
+
6
+ OBTW
7
+ it's multiline
8
+ comment. All BTW comments here are ignored
9
+ BTW TLDR, VISIBLE "multiline test"
10
+ KTHXBYE
11
+
12
+ OBTW
13
+ another multiline
14
+ comment
15
+ VISIBLE "commented out"
16
+ TLDR
@@ -0,0 +1,2 @@
1
+ comment test
2
+ multiline test
@@ -0,0 +1,8 @@
1
+ HAI 1.2
2
+ VISIBLE "Triple dot is a line "...
3
+ "continuation"
4
+
5
+ VISIBLE "Unicode ellipsis character"…
6
+ " is a line"…
7
+ " continuation too"
8
+ KTHXBYE
@@ -0,0 +1,2 @@
1
+ Triple dot is a line continuation
2
+ Unicode ellipsis character is a line continuation too
@@ -0,0 +1,5 @@
1
+ HAI 1.2
2
+ VISIBLE "Usual line ending"
3
+
4
+ VISIBLE "Commas act as", VISIBLE "virtual newlines"
5
+ KTHXBYE
@@ -0,0 +1,3 @@
1
+ Usual line ending
2
+ Commas act as
3
+ virtual newlines
@@ -0,0 +1,2 @@
1
+ HAI 1.2
2
+ KTHXBYE
@@ -0,0 +1,8 @@
1
+ HAI 1.2
2
+ I HAS A flag ITZ FAIL
3
+ VISIBLE flag
4
+ VISIBLE MAEK flag A NUMBR
5
+ VISIBLE MAEK flag A NUMBAR
6
+ VISIBLE MAEK WIN A NUMBR
7
+ VISIBLE MAEK WIN A NUMBAR
8
+ KTHXBYE
@@ -0,0 +1,5 @@
1
+ FAIL
2
+ 0
3
+ 0.0
4
+ 1
5
+ 1.0
@@ -0,0 +1,10 @@
1
+ HAI 1.2
2
+
3
+ I HAS A weight ITZ 10.756
4
+ VISIBLE weight
5
+ VISIBLE MAEK weight A NUMBR
6
+ VISIBLE MAEK weight A TROOF
7
+ VISIBLE MAEK 0.0 A TROOF
8
+ VISIBLE -102.5
9
+
10
+ KTHXBYE
@@ -0,0 +1,5 @@
1
+ 10.75
2
+ 10
3
+ WIN
4
+ FAIL
5
+ -102.5
@@ -0,0 +1,9 @@
1
+ HAI 1.2
2
+
3
+ I HAS A price ITZ 25
4
+ VISIBLE price
5
+ VISIBLE MAEK price A NUMBAR
6
+ VISIBLE MAEK price A TROOF
7
+ VISIBLE MAEK 0 A TROOF
8
+
9
+ KTHXBYE
@@ -0,0 +1,4 @@
1
+ 25
2
+ 25.0
3
+ WIN
4
+ FAIL
@@ -0,0 +1,9 @@
1
+ HAI 1.2
2
+
3
+ I HAS A name
4
+ VISIBLE NOT name
5
+ VISIBLE MAEK name A NUMBR
6
+ VISIBLE MAEK name A NUMBAR
7
+ VISIBLE MAEK name A YARN
8
+
9
+ KTHXBYE
@@ -0,0 +1,4 @@
1
+ WIN
2
+ 0
3
+ 0.0
4
+
@@ -0,0 +1,5 @@
1
+ HAI 1.2
2
+ I HAS A name ITZ "layo"
3
+ VISIBLE name
4
+ VISIBLE MAEK name A TROOF
5
+ KTHXBYE
@@ -0,0 +1,2 @@
1
+ layo
2
+ WIN
@@ -0,0 +1,30 @@
1
+ HAI 1.2
2
+
3
+ BTW boolean logic
4
+ BTW and
5
+ VISIBLE BOTH OF WIN AN FAIL
6
+ VISIBLE BOTH OF 1 AN 5
7
+ BTW or
8
+ VISIBLE EITHER OF 0 AN 0
9
+ VISIBLE EITHER OF WIN AN 0
10
+ BTW xor
11
+ VISIBLE WON OF 1 AN 0
12
+ VISIBLE WON OF FAIL AN FAIL
13
+ BTW not
14
+ I HAS A var ITZ 5
15
+ VISIBLE NOT FAIL
16
+ VISIBLE NOT WIN
17
+ VISIBLE NOT var
18
+ BTW n-ary and
19
+ VISIBLE ALL OF WIN AN WIN AN WIN AN WIN MKAY
20
+ VISIBLE ALL OF FAIL AN WIN AN WIN
21
+ BTW n-ary or
22
+ VISIBLE ANY OF WIN AN FAIL MKAY
23
+ VISIBLE ANY OF FAIL AN FAIL AN FAIL
24
+
25
+ BTW comparison
26
+ VISIBLE BOTH SAEM 5 AN 4
27
+ VISIBLE BOTH SAEM 4 AN 4
28
+ VISIBLE DIFFRINT 4 AN 3
29
+ VISIBLE DIFFRINT 5.22 5.22
30
+ KTHXBYE
@@ -0,0 +1,17 @@
1
+ FAIL
2
+ WIN
3
+ FAIL
4
+ WIN
5
+ WIN
6
+ FAIL
7
+ WIN
8
+ FAIL
9
+ FAIL
10
+ WIN
11
+ FAIL
12
+ WIN
13
+ FAIL
14
+ FAIL
15
+ WIN
16
+ WIN
17
+ FAIL
@@ -0,0 +1,28 @@
1
+ HAI 1.2
2
+ I HAS A var
3
+ VISIBLE MAEK var A YARN
4
+ VISIBLE MAEK var A NUMBR
5
+ VISIBLE MAEK var A NUMBAR
6
+ VISIBLE MAEK var A TROOF
7
+
8
+ VISIBLE MAEK "abc" A YARN
9
+ VISIBLE MAEK "-19" A NUMBR
10
+ VISIBLE MAEK "22.56" A NUMBAR
11
+ VISIBLE MAEK "abc" A TROOF
12
+
13
+ VISIBLE MAEK 12 A YARN
14
+ VISIBLE MAEK 12 A NUMBR
15
+ VISIBLE MAEK 12 A NUMBAR
16
+ VISIBLE MAEK 12 A TROOF
17
+
18
+ VISIBLE MAEK WIN A YARN
19
+ VISIBLE MAEK WIN A NUMBR
20
+ VISIBLE MAEK WIN A NUMBAR
21
+ VISIBLE MAEK WIN A TROOF
22
+
23
+ VISIBLE MAEK FAIL A YARN
24
+ VISIBLE MAEK FAIL A NUMBR
25
+ VISIBLE MAEK FAIL A NUMBAR
26
+ VISIBLE MAEK FAIL A TROOF
27
+
28
+ KTHXBYE
@@ -0,0 +1,20 @@
1
+
2
+ 0
3
+ 0.0
4
+ FAIL
5
+ abc
6
+ -19
7
+ 22.56
8
+ WIN
9
+ 12
10
+ 12
11
+ 12.0
12
+ WIN
13
+ WIN
14
+ 1
15
+ 1.0
16
+ WIN
17
+ FAIL
18
+ 0
19
+ 0.0
20
+ FAIL
@@ -0,0 +1,24 @@
1
+ HAI 1.2
2
+
3
+ HOW DUZ I x_mul_y_plus_z YR x AN YR y AN YR z
4
+ I HAS A var ITZ PRODUKT OF x AN y
5
+ var R SUM OF var AN z
6
+ FOUND YR var
7
+ IF U SAY SO
8
+
9
+ VISIBLE "1 * 2 + 3 = " x_mul_y_plus_z 1 2 3 " one more arg for VISIBLE"
10
+
11
+ BTW This function uses implicit variable to return value, just like in Ruby
12
+ HOW DUZ I greeting YR name
13
+ SMOOSH "Greetings, " AN name
14
+ IF U SAY SO
15
+
16
+ VISIBLE greeting "Shrek"
17
+ VISIBLE greeting "Princess Fiona"
18
+
19
+ HOW DUZ I nil_func
20
+ GTFO
21
+ IF U SAY SO
22
+
23
+ VISIBLE MAEK nil_func A NUMBR
24
+ KTHXBYE
@@ -0,0 +1,4 @@
1
+ 1 * 2 + 3 = 5 one more arg for VISIBLE
2
+ Greetings, Shrek
3
+ Greetings, Princess Fiona
4
+ 0
@@ -0,0 +1,9 @@
1
+ HAI 1.2
2
+ VISIBLE SUM OF 2 AN 3
3
+ VISIBLE DIFF OF 5 AN 6
4
+ VISIBLE PRODUKT OF 10 AN 4
5
+ VISIBLE QUOSHUNT OF 12 AN 3
6
+ VISIBLE MOD OF "16" AN 3
7
+ VISIBLE BIGGR OF 0.55 AN "0.56"
8
+ VISIBLE SMALLR OF "-9.8" AN -22
9
+ KTHXBYE
@@ -0,0 +1,7 @@
1
+ 5
2
+ -1
3
+ 40
4
+ 4
5
+ 1
6
+ 0.56
7
+ -22.0
@@ -0,0 +1,20 @@
1
+ HAI 1.2
2
+ I HAS A str ITZ SMOOSH "Hello " "World"
3
+ VISIBLE str
4
+
5
+ BTW SMOOSH operator concatenates all arguments
6
+ VISIBLE SMOOSH "Let " AN "me " AN "be " AN "with " AN "you" MKAY "!"
7
+
8
+ BTW Escape sequences
9
+ VISIBLE "Escape sequences :) :>:" :::""
10
+
11
+ BTW Unicode code points and normative names
12
+ VISIBLE "Unicode :(2A), :[LATIN CAPITAL LETTER A]"
13
+
14
+ BTW Variable interpolation
15
+ I HAS A name ITZ "Alice"
16
+ VISIBLE "Hello :{name}"
17
+ SUM OF 2 AN 3
18
+ VISIBLE "2 + 3 = :{IT}"
19
+
20
+ KTHXBYE
@@ -0,0 +1,7 @@
1
+ Hello World
2
+ Let me be with you!
3
+ Escape sequences
4
+ " :"
5
+ Unicode *, A
6
+ Hello Alice
7
+ 2 + 3 = 5
@@ -0,0 +1,8 @@
1
+ HAI 1.2
2
+ I HAS A var ITZ 0
3
+ VISIBLE var
4
+ var R 75
5
+ VISIBLE var
6
+ var R "now string"
7
+ VISIBLE var
8
+ KTHXBYE
@@ -0,0 +1,3 @@
1
+ 0
2
+ 75
3
+ now string
@@ -0,0 +1,11 @@
1
+ HAI 1.2
2
+ I HAS A v ITZ 0
3
+ v IS NOW A TROOF
4
+ VISIBLE v
5
+ I HAS A v2 ITZ "50"
6
+ v2 IS NOW A NUMBR
7
+ VISIBLE v2
8
+ I HAS A emptyvar
9
+ emptyvar IS NOW A YARN
10
+ VISIBLE emptyvar
11
+ KTHXBYE
@@ -0,0 +1,3 @@
1
+ FAIL
2
+ 50
3
+
@@ -0,0 +1,9 @@
1
+ HAI 1.2
2
+ I HAS A var
3
+ BTW initially var is NOOB, i.e. nil value
4
+ VISIBLE MAEK var A TROOF
5
+
6
+ BTW using intialization
7
+ I HAS A var2 ITZ "cool"
8
+ VISIBLE var2
9
+ KTHXBYE
@@ -0,0 +1,2 @@
1
+ FAIL
2
+ cool
@@ -0,0 +1,10 @@
1
+ HAI 1.2
2
+
3
+ SUM OF 2 AN 2
4
+ VISIBLE IT
5
+
6
+ I HAS A var ITZ "Hello world"
7
+ var
8
+ VISIBLE IT
9
+
10
+ KTHXBYE
@@ -0,0 +1,2 @@
1
+ 4
2
+ Hello world
@@ -0,0 +1,42 @@
1
+ HAI 1.2
2
+
3
+ I HAS A animal ITZ "fish"
4
+
5
+ BOTH SAEM animal AN "fish", O RLY?
6
+ YA RLY
7
+ VISIBLE "I hav a fish"
8
+ MEBBE BOTH SAEM animal AN "cat"
9
+ VISIBLE "I hav a cat"
10
+ MEBBE BOTH SAEM animal AN "dog"
11
+ VISIBLE "I hav a dog"
12
+ NO WAI
13
+ VISIBLE "I hav unknown creature"
14
+ OIC
15
+
16
+ animal R "cat"
17
+
18
+ BOTH SAEM animal AN "fish", O RLY?
19
+ YA RLY
20
+ VISIBLE "I hav a fish"
21
+ MEBBE BOTH SAEM animal AN "cat"
22
+ VISIBLE "I hav a cat"
23
+ MEBBE BOTH SAEM animal AN "dog"
24
+ VISIBLE "I hav a dog"
25
+ NO WAI
26
+ VISIBLE "I hav unknown creature"
27
+ OIC
28
+
29
+ animal R "robot"
30
+
31
+ BOTH SAEM animal AN "fish", O RLY?
32
+ YA RLY
33
+ VISIBLE "I hav a fish"
34
+ MEBBE BOTH SAEM animal AN "cat"
35
+ VISIBLE "I hav a cat"
36
+ MEBBE BOTH SAEM animal AN "dog"
37
+ VISIBLE "I hav a dog"
38
+ NO WAI
39
+ VISIBLE "I hav unknown creature"
40
+ OIC
41
+
42
+ KTHXBYE
@@ -0,0 +1,3 @@
1
+ I hav a fish
2
+ I hav a cat
3
+ I hav unknown creature
@@ -0,0 +1 @@
1
+ Alisa
@@ -0,0 +1,4 @@
1
+ HAI 1.2
2
+ GIMMEH name
3
+ VISIBLE name
4
+ KTHXBYE