toy_lang 0.0.2 → 0.0.3
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/README.md +3 -1
- data/lib/toy_lang/scanner.rb +24 -6
- data/lib/toy_lang/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -33,7 +33,9 @@ Or install it yourself as:
|
|
33
33
|
# Set the program
|
34
34
|
@parser.program = "methodname(1,3)"
|
35
35
|
# Generate the AST
|
36
|
-
puts @parser.program
|
36
|
+
# puts @parser.program
|
37
|
+
# For the time being, only statement is implemented
|
38
|
+
puts @parser.statement
|
37
39
|
|
38
40
|
TODO: Find better names to avoid collision between 'program =' and
|
39
41
|
program
|
data/lib/toy_lang/scanner.rb
CHANGED
@@ -13,13 +13,31 @@ module ToyLang
|
|
13
13
|
IDENTIFIER = /\A[a-z]+/
|
14
14
|
WHITESPACE = /\A\s+/
|
15
15
|
|
16
|
+
private
|
17
|
+
# These two utility functions help us
|
18
|
+
# create the set of regulars expressions
|
19
|
+
# that form the syntax of the language
|
20
|
+
#
|
21
|
+
# \A => begining of the string
|
22
|
+
def self.reg_exp(reg_exp)
|
23
|
+
/\A#{reg_exp}/
|
24
|
+
end
|
25
|
+
|
26
|
+
# For characters that have to be escaped
|
27
|
+
# in the regular expression
|
28
|
+
def self.escaped_reg_exp(reg_exp)
|
29
|
+
regular_expression = "\\#{reg_exp}"
|
30
|
+
/\A#{regular_expression}/
|
31
|
+
end
|
32
|
+
|
33
|
+
public
|
16
34
|
LANGUAGE_TOKENS = {
|
17
|
-
number:
|
18
|
-
open_block:
|
19
|
-
close_block:
|
20
|
-
open_parentheses:
|
21
|
-
close_parentheses:
|
22
|
-
comma:
|
35
|
+
number: reg_exp('\d+'),
|
36
|
+
open_block: escaped_reg_exp('{'),
|
37
|
+
close_block: escaped_reg_exp('}'),
|
38
|
+
open_parentheses: escaped_reg_exp('('),
|
39
|
+
close_parentheses: escaped_reg_exp(')'),
|
40
|
+
comma: reg_exp(',')
|
23
41
|
}
|
24
42
|
|
25
43
|
RESERVED_WORDS = %w[return def]
|
data/lib/toy_lang/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toy_lang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
segments:
|
80
80
|
- 0
|
81
|
-
hash:
|
81
|
+
hash: 380981334131383254
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
segments:
|
89
89
|
- 0
|
90
|
-
hash:
|
90
|
+
hash: 380981334131383254
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
93
|
rubygems_version: 1.8.24
|