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.
- data/LICENSE +26 -0
- data/README.mkd +103 -0
- data/Rakefile +21 -0
- data/UnicodeData.txt +23697 -0
- data/bin/layo +22 -0
- data/layo.gemspec +23 -0
- data/lib/layo.rb +11 -0
- data/lib/layo/ast.rb +5 -0
- data/lib/layo/ast/block.rb +13 -0
- data/lib/layo/ast/expression.rb +14 -0
- data/lib/layo/ast/node.rb +6 -0
- data/lib/layo/ast/program.rb +9 -0
- data/lib/layo/ast/statement.rb +10 -0
- data/lib/layo/interpreter.rb +360 -0
- data/lib/layo/lexer.rb +162 -0
- data/lib/layo/parser.rb +371 -0
- data/lib/layo/peekable.rb +31 -0
- data/lib/layo/runtime_error.rb +9 -0
- data/lib/layo/syntax_error.rb +14 -0
- data/lib/layo/tokenizer.rb +119 -0
- data/lib/layo/unexpected_token_error.rb +13 -0
- data/lib/layo/unicode.rb +23614 -0
- data/lib/layo/unknown_token_error.rb +7 -0
- data/spec/interpreter_spec.rb +52 -0
- data/spec/lexer_spec.rb +176 -0
- data/spec/parser_spec.rb +373 -0
- data/spec/source/basic/comments.lol +16 -0
- data/spec/source/basic/comments.out +2 -0
- data/spec/source/basic/line-continuation.lol +8 -0
- data/spec/source/basic/line-continuation.out +2 -0
- data/spec/source/basic/line-endings.lol +5 -0
- data/spec/source/basic/line-endings.out +3 -0
- data/spec/source/basic/minimal.lol +2 -0
- data/spec/source/casting/boolean.lol +8 -0
- data/spec/source/casting/boolean.out +5 -0
- data/spec/source/casting/float.lol +10 -0
- data/spec/source/casting/float.out +5 -0
- data/spec/source/casting/int.lol +9 -0
- data/spec/source/casting/int.out +4 -0
- data/spec/source/casting/nil.lol +9 -0
- data/spec/source/casting/nil.out +4 -0
- data/spec/source/casting/string.lol +5 -0
- data/spec/source/casting/string.out +2 -0
- data/spec/source/expressions/boolean.lol +30 -0
- data/spec/source/expressions/boolean.out +17 -0
- data/spec/source/expressions/cast.lol +28 -0
- data/spec/source/expressions/cast.out +20 -0
- data/spec/source/expressions/function.lol +24 -0
- data/spec/source/expressions/function.out +4 -0
- data/spec/source/expressions/math.lol +9 -0
- data/spec/source/expressions/math.out +7 -0
- data/spec/source/expressions/string.lol +20 -0
- data/spec/source/expressions/string.out +7 -0
- data/spec/source/statements/assignment.lol +8 -0
- data/spec/source/statements/assignment.out +3 -0
- data/spec/source/statements/cast.lol +11 -0
- data/spec/source/statements/cast.out +3 -0
- data/spec/source/statements/declaration.lol +9 -0
- data/spec/source/statements/declaration.out +2 -0
- data/spec/source/statements/expression.lol +10 -0
- data/spec/source/statements/expression.out +2 -0
- data/spec/source/statements/if_then_else.lol +42 -0
- data/spec/source/statements/if_then_else.out +3 -0
- data/spec/source/statements/input.in +1 -0
- data/spec/source/statements/input.lol +4 -0
- data/spec/source/statements/input.out +1 -0
- data/spec/source/statements/loop.lol +50 -0
- data/spec/source/statements/loop.out +20 -0
- data/spec/source/statements/print.lol +7 -0
- data/spec/source/statements/print.out +2 -0
- data/spec/source/statements/switch.lol +95 -0
- data/spec/source/statements/switch.out +12 -0
- data/spec/tokenizer_spec.rb +105 -0
- metadata +135 -0
@@ -0,0 +1 @@
|
|
1
|
+
Alisa
|
@@ -0,0 +1,50 @@
|
|
1
|
+
HAI 1.2
|
2
|
+
|
3
|
+
I HAS A i ITZ 1
|
4
|
+
IM IN YR foreverloop
|
5
|
+
VISIBLE i
|
6
|
+
BOTH SAEM i AN 3, O RLY?
|
7
|
+
YA RLY
|
8
|
+
GTFO
|
9
|
+
OIC
|
10
|
+
i R SUM OF i AN 1
|
11
|
+
IM OUTTA YR foreverloop
|
12
|
+
|
13
|
+
IM IN YR loop UPPIN YR counter
|
14
|
+
VISIBLE counter
|
15
|
+
BOTH SAEM counter AN 3
|
16
|
+
O RLY?
|
17
|
+
YA RLY
|
18
|
+
GTFO
|
19
|
+
OIC
|
20
|
+
IM OUTTA YR loop
|
21
|
+
|
22
|
+
IM IN YR loop NERFIN YR counter
|
23
|
+
VISIBLE counter
|
24
|
+
BOTH SAEM counter AN -2
|
25
|
+
O RLY?
|
26
|
+
YA RLY
|
27
|
+
GTFO
|
28
|
+
OIC
|
29
|
+
IM OUTTA YR loop
|
30
|
+
|
31
|
+
BTW for (int counter = 0; counter <= 3; counter++)
|
32
|
+
IM IN YR loop UPPIN YR counter WILE BOTH SAEM counter AN SMALLR OF counter AN 3
|
33
|
+
VISIBLE counter
|
34
|
+
IM OUTTA YR loop
|
35
|
+
|
36
|
+
BTW for (int counter = 0; counter > -3; counter--)
|
37
|
+
IM IN YR loop NERFIN YR counter TIL BOTH SAEM counter AN SMALLR OF counter AN -3
|
38
|
+
VISIBLE counter
|
39
|
+
IM OUTTA YR loop
|
40
|
+
|
41
|
+
HOW DUZ I threePlus YR var
|
42
|
+
FOUND YR SUM OF 3 AN var
|
43
|
+
IF U SAY SO
|
44
|
+
|
45
|
+
BTW using custom unary function to change loop variable
|
46
|
+
IM IN YR loop threePlus YR counter TIL BOTH SAEM counter AN 9
|
47
|
+
VISIBLE counter
|
48
|
+
IM OUTTA YR loop
|
49
|
+
|
50
|
+
KTHXBYE
|
@@ -0,0 +1,95 @@
|
|
1
|
+
HAI 1.2
|
2
|
+
|
3
|
+
I HAS A color ITZ "R"
|
4
|
+
VISIBLE color
|
5
|
+
color, WTF?
|
6
|
+
OMG "R"
|
7
|
+
VISIBLE "RED FISH"
|
8
|
+
GTFO
|
9
|
+
OMG "Y"
|
10
|
+
VISIBLE "YELLOW FISH"
|
11
|
+
OMG "G"
|
12
|
+
OMG "B"
|
13
|
+
VISIBLE "FISH HAS A FLAVOR"
|
14
|
+
GTFO
|
15
|
+
OMGWTF
|
16
|
+
VISIBLE "FISH IS TRANSPARENT"
|
17
|
+
OIC
|
18
|
+
|
19
|
+
color R "Y"
|
20
|
+
VISIBLE color
|
21
|
+
color, WTF?
|
22
|
+
OMG "R"
|
23
|
+
VISIBLE "RED FISH"
|
24
|
+
GTFO
|
25
|
+
OMG "Y"
|
26
|
+
VISIBLE "YELLOW FISH"
|
27
|
+
OMG "G"
|
28
|
+
OMG "B"
|
29
|
+
VISIBLE "FISH HAS A FLAVOR"
|
30
|
+
GTFO
|
31
|
+
OMGWTF
|
32
|
+
VISIBLE "FISH IS TRANSPARENT"
|
33
|
+
OIC
|
34
|
+
|
35
|
+
color R "G"
|
36
|
+
VISIBLE color
|
37
|
+
color, WTF?
|
38
|
+
OMG "R"
|
39
|
+
VISIBLE "RED FISH"
|
40
|
+
GTFO
|
41
|
+
OMG "Y"
|
42
|
+
VISIBLE "YELLOW FISH"
|
43
|
+
OMG "G"
|
44
|
+
OMG "B"
|
45
|
+
VISIBLE "FISH HAS A FLAVOR"
|
46
|
+
GTFO
|
47
|
+
OMGWTF
|
48
|
+
VISIBLE "FISH IS TRANSPARENT"
|
49
|
+
OIC
|
50
|
+
|
51
|
+
color R "B"
|
52
|
+
VISIBLE color
|
53
|
+
color, WTF?
|
54
|
+
OMG "R"
|
55
|
+
VISIBLE "RED FISH"
|
56
|
+
GTFO
|
57
|
+
OMG "Y"
|
58
|
+
VISIBLE "YELLOW FISH"
|
59
|
+
OMG "G"
|
60
|
+
OMG "B"
|
61
|
+
VISIBLE "FISH HAS A FLAVOR"
|
62
|
+
GTFO
|
63
|
+
OMGWTF
|
64
|
+
VISIBLE "FISH IS TRANSPARENT"
|
65
|
+
OIC
|
66
|
+
|
67
|
+
color R "N"
|
68
|
+
VISIBLE color
|
69
|
+
color, WTF?
|
70
|
+
OMG "R"
|
71
|
+
VISIBLE "RED FISH"
|
72
|
+
GTFO
|
73
|
+
OMG "Y"
|
74
|
+
VISIBLE "YELLOW FISH"
|
75
|
+
OMG "G"
|
76
|
+
OMG "B"
|
77
|
+
VISIBLE "FISH HAS A FLAVOR"
|
78
|
+
GTFO
|
79
|
+
OMGWTF
|
80
|
+
VISIBLE "FISH IS TRANSPARENT"
|
81
|
+
OIC
|
82
|
+
|
83
|
+
BTW switch expressions should match both the type and value of IT variable
|
84
|
+
I HAS A str ITZ "5"
|
85
|
+
str, WTF?
|
86
|
+
OMG 5
|
87
|
+
VISIBLE "str is 5"
|
88
|
+
GTFO
|
89
|
+
OMG 5.0
|
90
|
+
VISIBLE "str is 5.0"
|
91
|
+
GTFO
|
92
|
+
OMG "5"
|
93
|
+
VISIBLE "str is '5'"
|
94
|
+
OIC
|
95
|
+
KTHXBYE
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'layo'
|
5
|
+
|
6
|
+
include Layo
|
7
|
+
|
8
|
+
describe Tokenizer do
|
9
|
+
before do
|
10
|
+
@lexer = Lexer.new(StringIO.new)
|
11
|
+
@tokenizer = Tokenizer.new(@lexer)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should recognize all plain tokens' do
|
15
|
+
tokens = {}
|
16
|
+
['HAI', 'KTHXBYE', 'NOOB', 'TROOF', 'NUMBR', 'NUMBAR',
|
17
|
+
'YARN', 'I HAS A', 'ITZ', 'R', 'SUM OF', 'DIFF OF', 'PRODUKT OF',
|
18
|
+
'QUOSHUNT OF', 'MOD OF', 'BIGGR OF', 'SMALLR OF', 'BOTH OF', 'EITHER OF',
|
19
|
+
'WON OF', 'NOT', 'ALL OF', 'ANY OF', 'BOTH SAEM', 'DIFFRINT',
|
20
|
+
'SMOOSH', 'MAEK', 'IS NOW A', 'A', 'VISIBLE', 'GIMMEH', 'MKAY', 'AN',
|
21
|
+
'O RLY?', 'YA RLY', 'NO WAI', 'MEBBE', 'OIC', 'WTF?', 'OMG', 'OMGWTF',
|
22
|
+
'GTFO', 'IM IN YR', 'YR', 'TIL', 'WILE', 'IM OUTTA YR', 'UPPIN',
|
23
|
+
'NERFIN', 'HOW DUZ I', 'AN YR', 'IF U SAY SO', 'FOUND YR'
|
24
|
+
].each { |t| tokens[t.gsub(' ', '_').downcase.to_sym] = t.split(' ') }
|
25
|
+
tokens.each do |type, value|
|
26
|
+
# Assign line number and position to each lexeme
|
27
|
+
value.map! { |item| [item, 1, 1] }
|
28
|
+
lexer = Lexer.new(StringIO.new)
|
29
|
+
lexer.stubs(:next_item).returns(*value)
|
30
|
+
@tokenizer.lexer = lexer
|
31
|
+
@tokenizer.next[:type].must_equal type
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should recognize newline tokens' do
|
36
|
+
@lexer.stubs(:next_item).returns(["\n", 1, 1])
|
37
|
+
@tokenizer.next[:type].must_equal :newline
|
38
|
+
end
|
39
|
+
|
40
|
+
it' should recognize exclamation mark token' do
|
41
|
+
@lexer.stubs(:next_item).returns ['!', 1, 1]
|
42
|
+
@tokenizer.next[:type].must_equal :exclamation
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should recognize string tokens' do
|
46
|
+
@lexer.stubs(:next_item).returns ['"some string lexeme"', 1, 1]
|
47
|
+
token = @tokenizer.next
|
48
|
+
token[:type].must_equal :string
|
49
|
+
token[:data].must_equal 'some string lexeme'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should recognize float tokens' do
|
53
|
+
[0.255, -1234.02].each do |number|
|
54
|
+
@lexer.stubs(:next_item).returns [number.to_s, 1, 1]
|
55
|
+
token = @tokenizer.next
|
56
|
+
token[:type].must_equal :float
|
57
|
+
token[:data].must_equal number
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should recognize integer tokens' do
|
62
|
+
[25, -9, 0].each do |number|
|
63
|
+
@lexer.stubs(:next_item).returns [number.to_s, 1, 1]
|
64
|
+
token = @tokenizer.next
|
65
|
+
token[:type].must_equal :integer
|
66
|
+
token[:data].must_equal number
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should recognize boolean tokens' do
|
71
|
+
['WIN', 'FAIL'].each do |value|
|
72
|
+
@lexer.stubs(:next_item).returns [value, 1, 1]
|
73
|
+
token = @tokenizer.next
|
74
|
+
token[:type].must_equal :boolean
|
75
|
+
token[:data].must_equal (value == 'WIN')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should recognize identifier tokens' do
|
80
|
+
['layo', 'lAYO123', 'Layo_layo_3'].each do |value|
|
81
|
+
@lexer.stubs(:next_item).returns [value, 1, 1]
|
82
|
+
token = @tokenizer.next
|
83
|
+
token[:type].must_equal :identifier
|
84
|
+
token[:data].must_equal value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should return eof token if lexeme is nil' do
|
89
|
+
@lexer.stubs(:next_item).returns [nil, 1, 1]
|
90
|
+
@tokenizer.next[:type].must_equal :eof
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should raise exception if token is unknown' do
|
94
|
+
['abc:', '%sdf', '- 25', '-', '.333'].each do |value|
|
95
|
+
@lexer.stubs(:next_item).returns [value, 1, 1]
|
96
|
+
lambda { @tokenizer.next }.must_raise Layo::UnknownTokenError
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should consume all lexemes of multi-lexeme token' do
|
101
|
+
@lexer.stubs(:next_item).returns(['ALL', 1, 1], ['OF', 1, 1], ['NOOB', 1, 1])
|
102
|
+
@tokenizer.next[:type].must_equal :all_of
|
103
|
+
@tokenizer.next[:type].must_equal :noob
|
104
|
+
end
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: layo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Galymzhan Kozhayev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mocha
|
16
|
+
requirement: &78148240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *78148240
|
25
|
+
description: ! " Layo is a LOLCODE interpreter written in plain Ruby. It tries
|
26
|
+
to conform to\n the LOLCODE 1.2 specification and supports everything described
|
27
|
+
there.\n"
|
28
|
+
email: kozhayev@gmail.com
|
29
|
+
executables:
|
30
|
+
- layo
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.mkd
|
36
|
+
- Rakefile
|
37
|
+
- UnicodeData.txt
|
38
|
+
- bin/layo
|
39
|
+
- layo.gemspec
|
40
|
+
- lib/layo.rb
|
41
|
+
- lib/layo/ast.rb
|
42
|
+
- lib/layo/ast/block.rb
|
43
|
+
- lib/layo/ast/expression.rb
|
44
|
+
- lib/layo/ast/node.rb
|
45
|
+
- lib/layo/ast/program.rb
|
46
|
+
- lib/layo/ast/statement.rb
|
47
|
+
- lib/layo/interpreter.rb
|
48
|
+
- lib/layo/lexer.rb
|
49
|
+
- lib/layo/parser.rb
|
50
|
+
- lib/layo/peekable.rb
|
51
|
+
- lib/layo/runtime_error.rb
|
52
|
+
- lib/layo/syntax_error.rb
|
53
|
+
- lib/layo/tokenizer.rb
|
54
|
+
- lib/layo/unexpected_token_error.rb
|
55
|
+
- lib/layo/unicode.rb
|
56
|
+
- lib/layo/unknown_token_error.rb
|
57
|
+
- spec/interpreter_spec.rb
|
58
|
+
- spec/lexer_spec.rb
|
59
|
+
- spec/parser_spec.rb
|
60
|
+
- spec/source/basic/comments.lol
|
61
|
+
- spec/source/basic/comments.out
|
62
|
+
- spec/source/basic/line-continuation.lol
|
63
|
+
- spec/source/basic/line-continuation.out
|
64
|
+
- spec/source/basic/line-endings.lol
|
65
|
+
- spec/source/basic/line-endings.out
|
66
|
+
- spec/source/basic/minimal.lol
|
67
|
+
- spec/source/casting/boolean.lol
|
68
|
+
- spec/source/casting/boolean.out
|
69
|
+
- spec/source/casting/float.lol
|
70
|
+
- spec/source/casting/float.out
|
71
|
+
- spec/source/casting/int.lol
|
72
|
+
- spec/source/casting/int.out
|
73
|
+
- spec/source/casting/nil.lol
|
74
|
+
- spec/source/casting/nil.out
|
75
|
+
- spec/source/casting/string.lol
|
76
|
+
- spec/source/casting/string.out
|
77
|
+
- spec/source/expressions/boolean.lol
|
78
|
+
- spec/source/expressions/boolean.out
|
79
|
+
- spec/source/expressions/cast.lol
|
80
|
+
- spec/source/expressions/cast.out
|
81
|
+
- spec/source/expressions/function.lol
|
82
|
+
- spec/source/expressions/function.out
|
83
|
+
- spec/source/expressions/math.lol
|
84
|
+
- spec/source/expressions/math.out
|
85
|
+
- spec/source/expressions/string.lol
|
86
|
+
- spec/source/expressions/string.out
|
87
|
+
- spec/source/statements/assignment.lol
|
88
|
+
- spec/source/statements/assignment.out
|
89
|
+
- spec/source/statements/cast.lol
|
90
|
+
- spec/source/statements/cast.out
|
91
|
+
- spec/source/statements/declaration.lol
|
92
|
+
- spec/source/statements/declaration.out
|
93
|
+
- spec/source/statements/expression.lol
|
94
|
+
- spec/source/statements/expression.out
|
95
|
+
- spec/source/statements/if_then_else.lol
|
96
|
+
- spec/source/statements/if_then_else.out
|
97
|
+
- spec/source/statements/input.in
|
98
|
+
- spec/source/statements/input.lol
|
99
|
+
- spec/source/statements/input.out
|
100
|
+
- spec/source/statements/loop.lol
|
101
|
+
- spec/source/statements/loop.out
|
102
|
+
- spec/source/statements/print.lol
|
103
|
+
- spec/source/statements/print.out
|
104
|
+
- spec/source/statements/switch.lol
|
105
|
+
- spec/source/statements/switch.out
|
106
|
+
- spec/tokenizer_spec.rb
|
107
|
+
homepage: http://github.com/galymzhan/layo
|
108
|
+
licenses: []
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.9.2
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.12
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: LOLCODE interpreter written in plain Ruby
|
131
|
+
test_files:
|
132
|
+
- spec/interpreter_spec.rb
|
133
|
+
- spec/lexer_spec.rb
|
134
|
+
- spec/parser_spec.rb
|
135
|
+
- spec/tokenizer_spec.rb
|