toy_lang 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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: /\A\d+/,
18
- open_block: /\A\{/,
19
- close_block: /\A\}/,
20
- open_parentheses: /\A\(/,
21
- close_parentheses: /\A\)/,
22
- comma: /\A,/
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]
@@ -1,3 +1,3 @@
1
1
  module ToyLang
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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: -3501641450620113713
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: -3501641450620113713
90
+ hash: 380981334131383254
91
91
  requirements: []
92
92
  rubyforge_project:
93
93
  rubygems_version: 1.8.24