wml_action 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0364cfffffdced1188beb5f62ac2c5cf6eefee0
4
- data.tar.gz: 17347228d19ffa2cc46569ece2bd5fff95e914be
3
+ metadata.gz: 5abd36604162ad81ae4384c177cccda0a78be1ba
4
+ data.tar.gz: 48ce5d4e111b731795958249d077ee4c3dd3f108
5
5
  SHA512:
6
- metadata.gz: 05154a8857c5cf039180ee94aaf440148068564cf293d34ff4481eba76f1f4861ec086e3ece8b1a2d9b5b32ff1b7d2e1d8a41d45e89c1be9effc1b949405b4bb
7
- data.tar.gz: e3d5376b9a88ba33f20ffd3c220e81bfc1b16633a9db492076578a4b8fd08e1684241c40810919a01162c0ccb950da757ee0606c4ff27a84179a7984cc5910b1
6
+ metadata.gz: abf8e77bcaeac06f1f2ecf7e31feabafb4de66e65bb235ebe2893ea60af751f020c7f83b7bb3921f947fed20ee0e398e7124612cc707984538e3734ecf159bf7
7
+ data.tar.gz: b539147e04dbf2a71e87738f63ff067fc2c59744693b4eed04da5d847e65235847d60e70dcba3a6a7706353c1739d7abceeb20735824c879bd6bfc91b990677e
data/README.md CHANGED
@@ -92,12 +92,14 @@ File:
92
92
  [unit]
93
93
  hp=10
94
94
  level=2
95
+ name=_ "Archer"
95
96
  [/unit]
96
97
  ```
97
98
  Modifications:
98
99
  ```
99
100
  [unit]
100
101
  hp=`(hp+level)*2`
102
+ name=`"Tough ".name`
101
103
  [/unit]
102
104
  ```
103
105
  Becomes:
@@ -105,6 +107,7 @@ Becomes:
105
107
  [unit]
106
108
  hp=24
107
109
  level=2
110
+ name=_ "Tough Archer"
108
111
  [/unit]
109
112
  ```
110
113
 
@@ -3,53 +3,58 @@ require 'wml_action'
3
3
 
4
4
  module WMLAction
5
5
 
6
- class CLI < Thor
7
- include Log
8
-
9
- class_option :verbose, type: :boolean, aliases: '-v'
10
- class_option :debug, type: :boolean, aliases: '-d'
11
-
12
- desc "modify FILE MODS_FILE", "Modifies a WML"
13
- def modify(original,modlist)
14
- log.level=Logger::INFO if options[:verbose]
15
- log.level=Logger::DEBUG if options[:debug]
16
-
17
- target_name=original
18
- modlist_name=modlist
19
-
20
- unless File.exist?(target_name)
21
- log.fatal "Invalid target file: #{target_name}"
22
- exit
23
- end
24
- unless File.exist?(modlist_name)
25
- log.fatal "Invalid modlist file: #{modlist_name}"
26
- exit
27
- end
28
-
29
- target=Document.from_file(target_name)
30
- modlist=Document.from_file(modlist_name)
31
-
32
- target.root.merge(modlist.root)
33
- print target.root.to_s
34
-
35
- end
36
-
37
- desc "read FILE", "Reads and outputs a wml"
38
- def read(filename)
39
- log.level=Logger::INFO if options[:verbose]
40
- log.level=Logger::DEBUG if options[:debug]
41
- d=Document.from_file(filename)
42
- print d.root.to_s
43
- end
44
-
45
- desc "action_read FILE", "Reads and outputs an action wml"
46
- def action_read(filename)
47
- log.level=Logger::INFO if options[:verbose]
48
- log.level=Logger::DEBUG if options[:debug]
49
- d=Document.from_file(filename)
50
- print d.root.to_s
51
- end
6
+ class CLI < Thor
7
+ include Log
8
+
9
+ class_option :verbose, type: :boolean, aliases: '-v'
10
+ class_option :debug, type: :boolean, aliases: '-d'
11
+
12
+ desc "modify FILE MODS_FILES", "Modifies a WML"
13
+ def modify(target_name,*modlist_names)
14
+ log.level=Logger::INFO if options[:verbose]
15
+ log.level=Logger::DEBUG if options[:debug]
16
+
17
+ unless File.exist?(target_name)
18
+ log.fatal "Invalid target file: #{target_name}"
19
+ exit
20
+ end
21
+
22
+ if modlist_names.empty?
23
+ log.fatal "Need at least one modlist file"
24
+ exit
25
+ end
26
+
27
+ non_exist = modlist_names.clone.delete_if {|f| File.exist? f}
28
+ unless non_exist.empty?
29
+ log.fatal "Modlist files does not exist: #{non_exist.join(" ")}"
30
+ exit
31
+ end
32
+
33
+ target=Document.from_file(target_name)
34
+ modlist_names.each do |name|
35
+ modlist=Document.from_file(name)
36
+ target.root.merge(modlist.root)
37
+ end
38
+
39
+ print target.root.to_s
40
+ end
41
+
42
+ desc "read FILE", "Reads and outputs a wml"
43
+ def read(filename)
44
+ log.level=Logger::INFO if options[:verbose]
45
+ log.level=Logger::DEBUG if options[:debug]
46
+ d=Document.from_file(filename)
47
+ print d.root.to_s
48
+ end
52
49
 
50
+ desc "action_read FILE", "Reads and outputs an action wml"
51
+ def action_read(filename)
52
+ log.level=Logger::INFO if options[:verbose]
53
+ log.level=Logger::DEBUG if options[:debug]
54
+ d=Document.from_file(filename)
55
+ print d.root.to_s
53
56
  end
54
57
 
58
+ end
59
+
55
60
  end
@@ -5,15 +5,15 @@ module WMLAction
5
5
  attr_accessor :line
6
6
 
7
7
  Var = Struct.new(:name) do
8
- def to_s
9
- name.to_s
10
- end
8
+ def to_s
9
+ name.to_s
10
+ end
11
11
  end
12
12
 
13
13
  Op = Struct.new(:value) do
14
- def to_s
15
- value.to_s
16
- end
14
+ def to_s
15
+ value.to_s
16
+ end
17
17
  end
18
18
 
19
19
 
@@ -22,51 +22,61 @@ module WMLAction
22
22
  end
23
23
 
24
24
  def result(vars={})
25
- return '' if @line.empty?
26
- stack=[]
27
- @line.each do |e|
28
- case e
29
- when Var then stack.push vars[e.name]
30
- when Op then
31
- x2 = stack.pop
32
- x1 = stack.pop
33
- raise SyntaxError.new("Invalid expression #{dump}, no values in stack") unless x1 && x2
34
- case e.value
35
- when '+' then stack.push(x1+x2)
36
- when '-' then stack.push(x1-x2)
37
- when '*' then stack.push(x1.to_f*x2)
38
- when '/' then stack.push(x1.to_f/x2)
39
- else raise NoMethodError.new("No such operation #{e.value}")
40
- end
41
- else stack.push e
42
- end
25
+ return '' if @line.empty?
26
+ stack=[]
27
+ @line.each do |e|
28
+ case e
29
+ when Var then stack.push vars[e.name]
30
+ when Op then
31
+ x2 = stack.pop
32
+ x1 = stack.pop
33
+ raise SyntaxError.new("Invalid expression #{dump}, no values in stack") unless x1 && x2
34
+ case e.value
35
+ when '+' then stack.push(x1+x2)
36
+ when '-' then stack.push(x1-x2)
37
+ when '*' then stack.push(x1.to_f*x2)
38
+ when '/' then stack.push(x1.to_f/x2)
39
+ when '.' then stack.push(dot_concat(x1,x2))
40
+ else raise NoMethodError.new("No such operation #{e.value}")
41
+ end
42
+ else stack.push e
43
43
  end
44
- raise SyntaxError.new("Invalid expression #{dump}, still have #{stack.size} values") unless stack.size == 1
45
- return stack[0].to_i if stack[0].class==Float
46
- return stack[0]
44
+ end
45
+ raise SyntaxError.new("Invalid expression #{dump}, still have #{stack.size} values") unless stack.size == 1
46
+ return stack[0].to_i if stack[0].class==Float
47
+ return stack[0]
48
+ end
49
+
50
+ def dot_concat(s1,s2)
51
+ quote=/\"/
52
+ m1=s1.match(quote)
53
+ m2=s2.match(quote)
54
+ raise NoMethodError.new("Can not dot-concat #{s1} and #{s2}, all have quotes") if m1 && m2
55
+ return s1.clone.insert(s1.rindex(quote),s2) if m1
56
+ return s2.clone.insert(s2.index(quote)+1,s1) if m2
47
57
  end
48
58
 
49
59
  def ==(other)
50
- @line==other.line
60
+ @line==other.line
51
61
  end
52
62
 
53
63
  def to_s
54
- #TODO should revert to infix notation for file output
55
- # needed to read outputted file
56
- dump
64
+ #TODO should revert to infix notation for file output
65
+ # needed to read outputted file
66
+ dump
57
67
  end
58
68
 
59
69
  def dump
60
- @line.join(' ')
70
+ @line.join(' ')
61
71
  end
62
72
 
63
73
  def <<(other)
64
- @line=@line+other.line
65
- return self
74
+ @line=@line+other.line
75
+ return self
66
76
  end
67
77
 
68
78
  def self.[](*elements)
69
- new elements
79
+ new elements
70
80
  end
71
81
 
72
82
  end
@@ -49,10 +49,11 @@ rule
49
49
  :INEXPR /\*/ { [:EMUL,text] }
50
50
  :INEXPR /\// { [:EDIV,text] }
51
51
  :INEXPR /\-/ { [:EMINUS,text] }
52
+ :INEXPR /\./ { [:EDOT,text] }
52
53
  :INEXPR /\(/ { [text,text] }
53
54
  :INEXPR /\)/ { [text,text] }
54
55
  :INEXPR /#{ANUMBER}/ { [:ENUM,text.to_f] }
55
- :INEXPR /#{ASTR}/ { [:ESTR,text] }
56
+ :INEXPR /#{ASTR}/ { [:ESTR,text.slice(1..-2)] }
56
57
  :INEXPR /#{VAR}/ { [:EVAR,text] }
57
58
 
58
59
  /./
@@ -132,6 +132,8 @@ class Parser < Racc::Parser
132
132
  action { [:EDIV,text] }
133
133
  when text = ss.scan(/\-/) then
134
134
  action { [:EMINUS,text] }
135
+ when text = ss.scan(/\./) then
136
+ action { [:EDOT,text] }
135
137
  when text = ss.scan(/\(/) then
136
138
  action { [text,text] }
137
139
  when text = ss.scan(/\)/) then
@@ -139,7 +141,7 @@ class Parser < Racc::Parser
139
141
  when text = ss.scan(/#{ANUMBER}/) then
140
142
  action { [:ENUM,text.to_f] }
141
143
  when text = ss.scan(/#{ASTR}/) then
142
- action { [:ESTR,text] }
144
+ action { [:ESTR,text.slice(1..-2)] }
143
145
  when text = ss.scan(/#{VAR}/) then
144
146
  action { [:EVAR,text] }
145
147
  else
@@ -16,59 +16,63 @@ require 'wml_action/log'
16
16
  module WMLAction
17
17
  class Parser < Racc::Parser
18
18
 
19
- module_eval(<<'...end parser.y/module_eval...', 'parser.y', 62)
19
+ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 70)
20
20
  include Log
21
21
 
22
22
  ...end parser.y/module_eval...
23
23
  ##### State transition tables begin ###
24
24
 
25
25
  racc_action_table = [
26
- 4, 8, 14, 22, 33, 4, 45, 21, 31, 34,
27
- 47, 35, 36, 37, 39, 16, 17, 18, 23, 25,
28
- 26, 28, 29, 18, 19, 33, 41, 42, 43, 44,
29
- 34, 33, 35, 36, 37, 38, 34, 33, 35, 36,
30
- 37, 7, 34, 33, 35, 36, 37, 5, 34, 33,
31
- 35, 36, 37, 4, 34, nil, 35, 36, 37, 41,
32
- 42, 43, 44, nil, nil, nil, 52, 40, 41, 42,
33
- 43, 44, 41, 42, 43, 44, 41, 42, 43, 44,
34
- 41, 42, 43, 44 ]
26
+ 16, 17, 31, 4, 8, 14, 22, 41, 42, 43,
27
+ 44, 45, 48, 39, 54, 18, 38, 46, 18, 23,
28
+ 25, 26, 28, 29, 33, 19, 4, 7, 21, 34,
29
+ 33, 35, 36, 37, 5, 34, 33, 35, 36, 37,
30
+ 4, 34, 33, 35, 36, 37, nil, 34, 33, 35,
31
+ 36, 37, nil, 34, 33, 35, 36, 37, nil, 34,
32
+ 33, 35, 36, 37, nil, 34, nil, 35, 36, 37,
33
+ 40, 41, 42, 43, 44, 45, 41, 42, 43, 44,
34
+ 45, 41, 42, 43, 44, 45, 41, 42, 43, 44,
35
+ 45, 41, 42, 43, 44, 45, 41, 42, 43, 44,
36
+ 45 ]
35
37
 
36
38
  racc_action_check = [
37
- 6, 6, 6, 18, 42, 15, 33, 15, 19, 42,
38
- 38, 42, 42, 42, 29, 6, 6, 6, 18, 18,
39
- 18, 18, 18, 19, 6, 34, 48, 48, 48, 48,
40
- 34, 43, 34, 34, 34, 24, 43, 41, 43, 43,
41
- 43, 5, 41, 44, 41, 41, 41, 1, 44, 22,
42
- 44, 44, 44, 0, 22, nil, 22, 22, 22, 46,
43
- 46, 46, 46, nil, nil, nil, 46, 32, 32, 32,
44
- 32, 32, 51, 51, 51, 51, 49, 49, 49, 49,
45
- 50, 50, 50, 50 ]
39
+ 6, 6, 19, 6, 6, 6, 18, 47, 47, 47,
40
+ 47, 47, 38, 29, 47, 19, 24, 33, 6, 18,
41
+ 18, 18, 18, 18, 43, 6, 15, 5, 15, 43,
42
+ 34, 43, 43, 43, 1, 34, 44, 34, 34, 34,
43
+ 0, 44, 41, 44, 44, 44, nil, 41, 22, 41,
44
+ 41, 41, nil, 22, 45, 22, 22, 22, nil, 45,
45
+ 42, 45, 45, 45, nil, 42, nil, 42, 42, 42,
46
+ 32, 32, 32, 32, 32, 32, 51, 51, 51, 51,
47
+ 51, 50, 50, 50, 50, 50, 52, 52, 52, 52,
48
+ 52, 49, 49, 49, 49, 49, 53, 53, 53, 53,
49
+ 53 ]
46
50
 
47
51
  racc_action_pointer = [
48
- 51, 47, nil, nil, nil, 41, -2, nil, nil, nil,
49
- nil, nil, nil, nil, nil, 3, nil, nil, -2, 4,
50
- nil, nil, 42, nil, 10, nil, nil, nil, nil, -9,
51
- nil, nil, 62, -4, 18, nil, nil, nil, -11, nil,
52
- nil, 30, -3, 24, 36, nil, 53, nil, 20, 70,
53
- 74, 66, nil ]
52
+ 32, 34, nil, nil, nil, 27, -5, nil, nil, nil,
53
+ nil, nil, nil, nil, nil, 18, nil, nil, -5, -8,
54
+ nil, nil, 35, nil, -13, nil, nil, nil, nil, -14,
55
+ nil, nil, 59, 0, 17, nil, nil, nil, -13, nil,
56
+ nil, 29, 47, 11, 23, 41, nil, -5, nil, 79,
57
+ 69, 64, 74, 84, nil ]
54
58
 
55
59
  racc_action_default = [
56
- -1, -37, -2, -3, -5, -37, -37, 53, -4, -6,
57
- -7, -8, -9, -10, -11, -37, -24, -25, -26, -37,
58
- -22, -23, -37, -27, -28, -29, -30, -31, -32, -37,
59
- -35, -36, -37, -37, -37, -19, -20, -21, -37, -33,
60
- -12, -37, -37, -37, -37, -17, -37, -34, -13, -14,
61
- -15, -16, -18 ]
60
+ -1, -38, -2, -3, -5, -38, -38, 55, -4, -6,
61
+ -7, -8, -9, -10, -11, -38, -25, -26, -27, -38,
62
+ -23, -24, -38, -28, -29, -30, -31, -32, -33, -38,
63
+ -36, -37, -38, -38, -38, -20, -21, -22, -38, -34,
64
+ -12, -38, -38, -38, -38, -38, -18, -38, -35, -13,
65
+ -14, -15, -16, -17, -19 ]
62
66
 
63
67
  racc_goto_table = [
64
68
  32, 3, 12, 1, 9, 10, 6, 11, 13, 27,
65
- 2, 15, 46, 24, nil, 30, 20, nil, nil, 48,
66
- 49, 50, 51 ]
69
+ 2, 15, 47, 24, nil, 30, 20, nil, nil, 49,
70
+ 50, 51, 52, 53 ]
67
71
 
68
72
  racc_goto_check = [
69
73
  10, 3, 7, 1, 5, 6, 4, 3, 8, 9,
70
74
  2, 11, 10, 12, nil, 7, 3, nil, nil, 10,
71
- 10, 10, 10 ]
75
+ 10, 10, 10, 10 ]
72
76
 
73
77
  racc_goto_pointer = [
74
78
  nil, 3, 10, 1, 2, -2, -1, -4, 2, -9,
@@ -80,77 +84,82 @@ racc_goto_default = [
80
84
 
81
85
  racc_reduce_table = [
82
86
  0, 0, :racc_error,
83
- 0, 28, :_reduce_none,
84
- 1, 28, :_reduce_2,
85
- 1, 29, :_reduce_3,
86
- 3, 30, :_reduce_4,
87
- 0, 31, :_reduce_5,
88
- 2, 31, :_reduce_6,
89
- 1, 32, :_reduce_none,
90
- 1, 32, :_reduce_8,
91
- 1, 32, :_reduce_none,
92
- 1, 32, :_reduce_none,
93
- 1, 32, :_reduce_11,
94
- 3, 36, :_reduce_12,
95
- 3, 37, :_reduce_13,
96
- 3, 37, :_reduce_14,
97
- 3, 37, :_reduce_15,
98
- 3, 37, :_reduce_16,
99
- 2, 37, :_reduce_17,
100
- 3, 37, :_reduce_18,
101
- 1, 37, :_reduce_19,
102
- 1, 37, :_reduce_20,
103
- 1, 37, :_reduce_21,
104
- 2, 33, :_reduce_22,
105
- 2, 33, :_reduce_23,
106
- 1, 38, :_reduce_none,
107
- 1, 38, :_reduce_none,
108
- 1, 34, :_reduce_26,
109
- 2, 34, :_reduce_27,
110
- 2, 34, :_reduce_28,
111
- 2, 34, :_reduce_29,
112
- 2, 34, :_reduce_30,
113
- 2, 34, :_reduce_31,
114
- 1, 39, :_reduce_32,
115
- 2, 39, :_reduce_33,
116
- 3, 39, :_reduce_34,
117
- 2, 35, :_reduce_35,
118
- 2, 35, :_reduce_36 ]
119
-
120
- racc_reduce_n = 37
121
-
122
- racc_shift_n = 53
87
+ 0, 32, :_reduce_none,
88
+ 1, 32, :_reduce_2,
89
+ 1, 33, :_reduce_3,
90
+ 3, 34, :_reduce_4,
91
+ 0, 35, :_reduce_5,
92
+ 2, 35, :_reduce_6,
93
+ 1, 36, :_reduce_none,
94
+ 1, 36, :_reduce_8,
95
+ 1, 36, :_reduce_none,
96
+ 1, 36, :_reduce_none,
97
+ 1, 36, :_reduce_11,
98
+ 3, 40, :_reduce_12,
99
+ 3, 41, :_reduce_13,
100
+ 3, 41, :_reduce_14,
101
+ 3, 41, :_reduce_15,
102
+ 3, 41, :_reduce_16,
103
+ 3, 41, :_reduce_17,
104
+ 2, 41, :_reduce_18,
105
+ 3, 41, :_reduce_19,
106
+ 1, 41, :_reduce_20,
107
+ 1, 41, :_reduce_21,
108
+ 1, 41, :_reduce_22,
109
+ 2, 37, :_reduce_23,
110
+ 2, 37, :_reduce_24,
111
+ 1, 42, :_reduce_none,
112
+ 1, 42, :_reduce_none,
113
+ 1, 38, :_reduce_27,
114
+ 2, 38, :_reduce_28,
115
+ 2, 38, :_reduce_29,
116
+ 2, 38, :_reduce_30,
117
+ 2, 38, :_reduce_31,
118
+ 2, 38, :_reduce_32,
119
+ 1, 43, :_reduce_33,
120
+ 2, 43, :_reduce_34,
121
+ 3, 43, :_reduce_35,
122
+ 2, 39, :_reduce_36,
123
+ 2, 39, :_reduce_37 ]
124
+
125
+ racc_reduce_n = 38
126
+
127
+ racc_shift_n = 55
123
128
 
124
129
  racc_token_table = {
125
130
  false => 0,
126
131
  :error => 1,
127
- :OTAG => 2,
128
- :CTAG => 3,
129
- :MACRO => 4,
130
- :BACKQ => 5,
131
- :EPLUS => 6,
132
- :EMINUS => 7,
133
- :EMUL => 8,
134
- :EDIV => 9,
135
- :ENUMBER => 10,
136
- :EUMIN => 11,
137
- "(" => 12,
138
- ")" => 13,
139
- :ESTR => 14,
140
- :ENUM => 15,
141
- :EVAR => 16,
142
- "+" => 17,
143
- "-" => 18,
144
- :ATTR => 19,
145
- :APLAIN => 20,
146
- :AMACRO => 21,
147
- :ANUMBER => 22,
148
- :ASTR => 23,
149
- :UNDERSC => 24,
150
- :APLUS => 25,
151
- :SLASH => 26 }
152
-
153
- racc_nt_base = 27
132
+ :EUMIN => 2,
133
+ "*" => 3,
134
+ "/" => 4,
135
+ "+" => 5,
136
+ "-" => 6,
137
+ "." => 7,
138
+ :OTAG => 8,
139
+ :CTAG => 9,
140
+ :MACRO => 10,
141
+ :BACKQ => 11,
142
+ :EPLUS => 12,
143
+ :EMINUS => 13,
144
+ :EMUL => 14,
145
+ :EDIV => 15,
146
+ :EDOT => 16,
147
+ :ENUMBER => 17,
148
+ "(" => 18,
149
+ ")" => 19,
150
+ :ESTR => 20,
151
+ :ENUM => 21,
152
+ :EVAR => 22,
153
+ :ATTR => 23,
154
+ :APLAIN => 24,
155
+ :AMACRO => 25,
156
+ :ANUMBER => 26,
157
+ :ASTR => 27,
158
+ :UNDERSC => 28,
159
+ :APLUS => 29,
160
+ :SLASH => 30 }
161
+
162
+ racc_nt_base = 31
154
163
 
155
164
  racc_use_result_var = true
156
165
 
@@ -173,6 +182,12 @@ Racc_arg = [
173
182
  Racc_token_to_s_table = [
174
183
  "$end",
175
184
  "error",
185
+ "EUMIN",
186
+ "\"*\"",
187
+ "\"/\"",
188
+ "\"+\"",
189
+ "\"-\"",
190
+ "\".\"",
176
191
  "OTAG",
177
192
  "CTAG",
178
193
  "MACRO",
@@ -181,15 +196,13 @@ Racc_token_to_s_table = [
181
196
  "EMINUS",
182
197
  "EMUL",
183
198
  "EDIV",
199
+ "EDOT",
184
200
  "ENUMBER",
185
- "EUMIN",
186
201
  "\"(\"",
187
202
  "\")\"",
188
203
  "ESTR",
189
204
  "ENUM",
190
205
  "EVAR",
191
- "\"+\"",
192
- "\"-\"",
193
206
  "ATTR",
194
207
  "APLAIN",
195
208
  "AMACRO",
@@ -220,35 +233,35 @@ Racc_debug_parser = false
220
233
 
221
234
  # reduce 1 omitted
222
235
 
223
- module_eval(<<'.,.,', 'parser.y', 3)
236
+ module_eval(<<'.,.,', 'parser.y', 10)
224
237
  def _reduce_2(val, _values, result)
225
238
  log.debug 'Found a target'
226
239
  result
227
240
  end
228
241
  .,.,
229
242
 
230
- module_eval(<<'.,.,', 'parser.y', 5)
243
+ module_eval(<<'.,.,', 'parser.y', 12)
231
244
  def _reduce_3(val, _values, result)
232
245
  log.debug 'Found a doc'
233
246
  result
234
247
  end
235
248
  .,.,
236
249
 
237
- module_eval(<<'.,.,', 'parser.y', 7)
250
+ module_eval(<<'.,.,', 'parser.y', 14)
238
251
  def _reduce_4(val, _values, result)
239
252
  log.debug("Creating tag #{val[0]}"); return Tag.new(name: val[0], content: val[1])
240
253
  result
241
254
  end
242
255
  .,.,
243
256
 
244
- module_eval(<<'.,.,', 'parser.y', 9)
257
+ module_eval(<<'.,.,', 'parser.y', 16)
245
258
  def _reduce_5(val, _values, result)
246
259
  return []
247
260
  result
248
261
  end
249
262
  .,.,
250
263
 
251
- module_eval(<<'.,.,', 'parser.y', 10)
264
+ module_eval(<<'.,.,', 'parser.y', 17)
252
265
  def _reduce_6(val, _values, result)
253
266
  log.debug("Append #{val[1]} to #{val[0]}"); return val[0]? val[0].push(val[1]) : [val[1]]
254
267
  result
@@ -257,7 +270,7 @@ module_eval(<<'.,.,', 'parser.y', 10)
257
270
 
258
271
  # reduce 7 omitted
259
272
 
260
- module_eval(<<'.,.,', 'parser.y', 13)
273
+ module_eval(<<'.,.,', 'parser.y', 20)
261
274
  def _reduce_8(val, _values, result)
262
275
  log.debug "Found a content subtag #{val[0]}"
263
276
  result
@@ -268,173 +281,180 @@ module_eval(<<'.,.,', 'parser.y', 13)
268
281
 
269
282
  # reduce 10 omitted
270
283
 
271
- module_eval(<<'.,.,', 'parser.y', 16)
284
+ module_eval(<<'.,.,', 'parser.y', 23)
272
285
  def _reduce_11(val, _values, result)
273
286
  log.debug "Found a macro #{val[0]}"; return Tag::Macro[val[0]]
274
287
  result
275
288
  end
276
289
  .,.,
277
290
 
278
- module_eval(<<'.,.,', 'parser.y', 18)
291
+ module_eval(<<'.,.,', 'parser.y', 25)
279
292
  def _reduce_12(val, _values, result)
280
293
  return val[1]
281
294
  result
282
295
  end
283
296
  .,.,
284
297
 
285
- module_eval(<<'.,.,', 'parser.y', 20)
298
+ module_eval(<<'.,.,', 'parser.y', 27)
286
299
  def _reduce_13(val, _values, result)
287
300
  log.debug "Found a #{val[0]} #{val[1]} #{val[2]} expression"; return val[0] << val[2] << Tag::Expr[Tag::Expr::Op[val[1]]]
288
301
  result
289
302
  end
290
303
  .,.,
291
304
 
292
- module_eval(<<'.,.,', 'parser.y', 21)
305
+ module_eval(<<'.,.,', 'parser.y', 28)
293
306
  def _reduce_14(val, _values, result)
294
307
  log.debug "Found a #{val[0]} #{val[1]} #{val[2]} expression"; return val[0] << val[2] << Tag::Expr[Tag::Expr::Op[val[1]]]
295
308
  result
296
309
  end
297
310
  .,.,
298
311
 
299
- module_eval(<<'.,.,', 'parser.y', 22)
312
+ module_eval(<<'.,.,', 'parser.y', 29)
300
313
  def _reduce_15(val, _values, result)
301
314
  log.debug "Found a #{val[0]} #{val[1]} #{val[2]} expression"; return val[0] << val[2] << Tag::Expr[Tag::Expr::Op[val[1]]]
302
315
  result
303
316
  end
304
317
  .,.,
305
318
 
306
- module_eval(<<'.,.,', 'parser.y', 23)
319
+ module_eval(<<'.,.,', 'parser.y', 30)
307
320
  def _reduce_16(val, _values, result)
308
321
  log.debug "Found a #{val[0]} #{val[1]} #{val[2]} expression"; return val[0] << val[2] << Tag::Expr[Tag::Expr::Op[val[1]]]
309
322
  result
310
323
  end
311
324
  .,.,
312
325
 
313
- module_eval(<<'.,.,', 'parser.y', 24)
326
+ module_eval(<<'.,.,', 'parser.y', 31)
314
327
  def _reduce_17(val, _values, result)
315
- return Tag:Expr[-val[1]]
328
+ log.debug "Found a #{val[0]} #{val[1]} #{val[2]} expression"; return val[0] << val[2] << Tag::Expr[Tag::Expr::Op[val[1]]]
316
329
  result
317
330
  end
318
331
  .,.,
319
332
 
320
- module_eval(<<'.,.,', 'parser.y', 25)
333
+ module_eval(<<'.,.,', 'parser.y', 32)
321
334
  def _reduce_18(val, _values, result)
322
- return val[1]
335
+ return Tag:Expr[-val[1]]
323
336
  result
324
337
  end
325
338
  .,.,
326
339
 
327
- module_eval(<<'.,.,', 'parser.y', 26)
340
+ module_eval(<<'.,.,', 'parser.y', 33)
328
341
  def _reduce_19(val, _values, result)
329
- log.debug "Found a string #{val[0]}"; return Tag::Expr[val[0]]
342
+ return val[1]
330
343
  result
331
344
  end
332
345
  .,.,
333
346
 
334
- module_eval(<<'.,.,', 'parser.y', 27)
347
+ module_eval(<<'.,.,', 'parser.y', 34)
335
348
  def _reduce_20(val, _values, result)
336
- log.debug "Found a number #{val[0]}"; return Tag::Expr[val[0]]
349
+ log.debug "Found a string #{val[0]}"; return Tag::Expr[val[0]]
337
350
  result
338
351
  end
339
352
  .,.,
340
353
 
341
- module_eval(<<'.,.,', 'parser.y', 28)
354
+ module_eval(<<'.,.,', 'parser.y', 35)
342
355
  def _reduce_21(val, _values, result)
343
- log.debug "Found a variable #{val[0]}"; return Tag::Expr[Tag::Expr::Var[val[0]]]
356
+ log.debug "Found a number #{val[0]}"; return Tag::Expr[val[0]]
344
357
  result
345
358
  end
346
359
  .,.,
347
360
 
348
- module_eval(<<'.,.,', 'parser.y', 30)
361
+ module_eval(<<'.,.,', 'parser.y', 36)
349
362
  def _reduce_22(val, _values, result)
350
- log.debug "Found a action tag #{val[0]}:#{val[1]}"; return Tag::Action[val[1],val[0]]
363
+ log.debug "Found a variable #{val[0]}"; return Tag::Expr[Tag::Expr::Var[val[0]]]
351
364
  result
352
365
  end
353
366
  .,.,
354
367
 
355
- module_eval(<<'.,.,', 'parser.y', 31)
368
+ module_eval(<<'.,.,', 'parser.y', 38)
356
369
  def _reduce_23(val, _values, result)
357
- log.debug "Found a action mac #{val[0]}:#{val[1]}"; return Tag::Action[Tag::Macro[val[1]],val[0]]
370
+ log.debug "Found a action tag #{val[0]}:#{val[1]}"; return Tag::Action[val[1],val[0]]
358
371
  result
359
372
  end
360
373
  .,.,
361
374
 
362
- # reduce 24 omitted
375
+ module_eval(<<'.,.,', 'parser.y', 39)
376
+ def _reduce_24(val, _values, result)
377
+ log.debug "Found a action macro #{val[0]}:#{val[1]}"; return Tag::Action[Tag::Macro[val[1]],val[0]]
378
+ result
379
+ end
380
+ .,.,
363
381
 
364
382
  # reduce 25 omitted
365
383
 
366
- module_eval(<<'.,.,', 'parser.y', 36)
367
- def _reduce_26(val, _values, result)
384
+ # reduce 26 omitted
385
+
386
+ module_eval(<<'.,.,', 'parser.y', 44)
387
+ def _reduce_27(val, _values, result)
368
388
  log.debug "Found empty attribute: #{val[0]}"; return Tag::Attribute[val[0],'']
369
389
  result
370
390
  end
371
391
  .,.,
372
392
 
373
- module_eval(<<'.,.,', 'parser.y', 37)
374
- def _reduce_27(val, _values, result)
393
+ module_eval(<<'.,.,', 'parser.y', 45)
394
+ def _reduce_28(val, _values, result)
375
395
  log.debug "Found plain attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]]
376
396
  result
377
397
  end
378
398
  .,.,
379
399
 
380
- module_eval(<<'.,.,', 'parser.y', 38)
381
- def _reduce_28(val, _values, result)
400
+ module_eval(<<'.,.,', 'parser.y', 46)
401
+ def _reduce_29(val, _values, result)
382
402
  log.debug "Found string attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]]
383
403
  result
384
404
  end
385
405
  .,.,
386
406
 
387
- module_eval(<<'.,.,', 'parser.y', 39)
388
- def _reduce_29(val, _values, result)
407
+ module_eval(<<'.,.,', 'parser.y', 47)
408
+ def _reduce_30(val, _values, result)
389
409
  log.debug "Found macro attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]]
390
410
  result
391
411
  end
392
412
  .,.,
393
413
 
394
- module_eval(<<'.,.,', 'parser.y', 40)
395
- def _reduce_30(val, _values, result)
414
+ module_eval(<<'.,.,', 'parser.y', 48)
415
+ def _reduce_31(val, _values, result)
396
416
  log.debug "Found numeric attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]]
397
417
  result
398
418
  end
399
419
  .,.,
400
420
 
401
- module_eval(<<'.,.,', 'parser.y', 41)
402
- def _reduce_31(val, _values, result)
421
+ module_eval(<<'.,.,', 'parser.y', 49)
422
+ def _reduce_32(val, _values, result)
403
423
  log.debug "Found expression attribute: #{val[0]}"; return Tag::Attribute[val[0],val[1]]
404
424
  result
405
425
  end
406
426
  .,.,
407
427
 
408
- module_eval(<<'.,.,', 'parser.y', 43)
409
- def _reduce_32(val, _values, result)
428
+ module_eval(<<'.,.,', 'parser.y', 51)
429
+ def _reduce_33(val, _values, result)
410
430
  return " #{val[0]}"
411
431
  result
412
432
  end
413
433
  .,.,
414
434
 
415
- module_eval(<<'.,.,', 'parser.y', 44)
416
- def _reduce_33(val, _values, result)
435
+ module_eval(<<'.,.,', 'parser.y', 52)
436
+ def _reduce_34(val, _values, result)
417
437
  return ' '+val[0]+' '+val[1]
418
438
  result
419
439
  end
420
440
  .,.,
421
441
 
422
- module_eval(<<'.,.,', 'parser.y', 45)
423
- def _reduce_34(val, _values, result)
442
+ module_eval(<<'.,.,', 'parser.y', 53)
443
+ def _reduce_35(val, _values, result)
424
444
  return val[0] + '+' + val[2]
425
445
  result
426
446
  end
427
447
  .,.,
428
448
 
429
- module_eval(<<'.,.,', 'parser.y', 47)
430
- def _reduce_35(val, _values, result)
449
+ module_eval(<<'.,.,', 'parser.y', 55)
450
+ def _reduce_36(val, _values, result)
431
451
  log.debug "Found an attribute filter #{val[1]}"; return Tag::Filter[val[1]]
432
452
  result
433
453
  end
434
454
  .,.,
435
455
 
436
- module_eval(<<'.,.,', 'parser.y', 48)
437
- def _reduce_36(val, _values, result)
456
+ module_eval(<<'.,.,', 'parser.y', 56)
457
+ def _reduce_37(val, _values, result)
438
458
  log.debug "Found a macro filter #{val[1]}"; return Tag::Filter[Tag::Macro[val[1]]]
439
459
  result
440
460
  end
@@ -1,4 +1,11 @@
1
1
  class WMLAction::Parser
2
+
3
+ prechigh
4
+ nonassoc EUMIN
5
+ left '*' '/'
6
+ left '+' '-' '.'
7
+ preclow
8
+
2
9
  rule
3
10
  target : /* nothing */
4
11
  | wml_doc { log.debug 'Found a target' }
@@ -22,6 +29,7 @@ rule
22
29
  | expr EMINUS expr { log.debug "Found a #{val[0]} #{val[1]} #{val[2]} expression"; return val[0] << val[2] << Tag::Expr[Tag::Expr::Op[val[1]]] }
23
30
  | expr EMUL expr { log.debug "Found a #{val[0]} #{val[1]} #{val[2]} expression"; return val[0] << val[2] << Tag::Expr[Tag::Expr::Op[val[1]]] }
24
31
  | expr EDIV expr { log.debug "Found a #{val[0]} #{val[1]} #{val[2]} expression"; return val[0] << val[2] << Tag::Expr[Tag::Expr::Op[val[1]]] }
32
+ | expr EDOT expr { log.debug "Found a #{val[0]} #{val[1]} #{val[2]} expression"; return val[0] << val[2] << Tag::Expr[Tag::Expr::Op[val[1]]] }
25
33
  | EMINUS ENUMBER =EUMIN { return Tag:Expr[-val[1]] }
26
34
  | '(' expr ')' { return val[1] }
27
35
  | ESTR { log.debug "Found a string #{val[0]}"; return Tag::Expr[val[0]] }
@@ -29,7 +37,7 @@ rule
29
37
  | EVAR { log.debug "Found a variable #{val[0]}"; return Tag::Expr[Tag::Expr::Var[val[0]]] }
30
38
 
31
39
  action : aop tag { log.debug "Found a action tag #{val[0]}:#{val[1]}"; return Tag::Action[val[1],val[0]] }
32
- | aop MACRO { log.debug "Found a action mac #{val[0]}:#{val[1]}"; return Tag::Action[Tag::Macro[val[1]],val[0]] }
40
+ | aop MACRO { log.debug "Found a action macro #{val[0]}:#{val[1]}"; return Tag::Action[Tag::Macro[val[1]],val[0]] }
33
41
 
34
42
  aop : '+'
35
43
  | '-'
@@ -73,6 +73,7 @@ module WMLAction
73
73
  end
74
74
 
75
75
  def merge(other)
76
+ return self if other.nil?
76
77
  return self unless @name == other.name
77
78
  return self unless match?( other.filter )
78
79
  log.info "Merging [#{@name}] section with [#{other.name}] with filter: #{other.filter}"
@@ -1,3 +1,3 @@
1
1
  module WMLAction
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/spec/expr_spec.rb CHANGED
@@ -6,83 +6,101 @@ module WMLAction
6
6
  describe Tag::Expr do
7
7
 
8
8
  before(:all) do
9
- Expr=Tag::Expr unless WMLAction.const_defined? 'Expr'
10
- Var=Tag::Expr::Var unless WMLAction.const_defined? 'Var'
11
- Op=Tag::Expr::Op unless WMLAction.const_defined? 'Op'
9
+ Expr=Tag::Expr unless WMLAction.const_defined? 'Expr'
10
+ Var=Tag::Expr::Var unless WMLAction.const_defined? 'Var'
11
+ Op=Tag::Expr::Op unless WMLAction.const_defined? 'Op'
12
12
  end
13
13
 
14
14
  describe '#result' do
15
15
 
16
- it 'sums numbers' do
17
- e=Expr[1,2,Op['+']]
18
- expect(e.result).to eq 3
19
- end
16
+ it 'sums numbers' do
17
+ e=Expr[1,2,Op['+']]
18
+ expect(e.result).to eq 3
19
+ end
20
20
 
21
- it 'substract numbers' do
22
- e=Expr[2,1,Op['-']]
23
- expect(e.result).to eq 1
24
- end
21
+ it 'substract numbers' do
22
+ e=Expr[2,1,Op['-']]
23
+ expect(e.result).to eq 1
24
+ end
25
25
 
26
- it 'multiply numbers' do
27
- e=Expr[2,3,Op['*']]
28
- expect(e.result).to eq 6
29
- end
26
+ it 'multiply numbers' do
27
+ e=Expr[2,3,Op['*']]
28
+ expect(e.result).to eq 6
29
+ end
30
30
 
31
- it 'multiply numbers' do
32
- e=Expr[6,3,Op['/']]
33
- expect(e.result).to eq 2
34
- end
31
+ it 'multiply numbers' do
32
+ e=Expr[6,3,Op['/']]
33
+ expect(e.result).to eq 2
34
+ end
35
35
 
36
- it 'more than one operation' do
37
- e=Expr[2,3,Op['*'],3,Op['-']]
38
- expect(e.result).to eq 3
39
- end
36
+ it 'more than one operation' do
37
+ e=Expr[2,3,Op['*'],3,Op['-']]
38
+ expect(e.result).to eq 3
39
+ end
40
40
 
41
- it 'results in integers' do
42
- e=Expr[6,4,Op['/']]
43
- expect(e.result).to be_integer
44
- end
41
+ it 'results in integers' do
42
+ e=Expr[6,4,Op['/']]
43
+ expect(e.result).to be_integer
44
+ end
45
+
46
+ it 'substitute variables' do
47
+ e=Expr[Var[:a],Var[:b],Op['+']]
48
+ expect(e.result({a: 1, b: 3})).to eq 4
49
+ end
50
+
51
+ it 'returns empty string on empty expr' do
52
+ e=Expr[]
53
+ expect(e.result).to eq ''
54
+ end
55
+
56
+ context 'when operates with strings' do
45
57
 
46
58
  it 'concatenates strings' do
47
- e=Expr['Hello',' World!',Op['+']]
48
- expect(e.result).to eq 'Hello World!'
59
+ e=Expr['Hello',' World!',Op['+']]
60
+ expect(e.result).to eq 'Hello World!'
49
61
  end
50
62
 
51
- it 'substitute variables' do
52
- e=Expr[Var[:a],Var[:b],Op['+']]
53
- expect(e.result({a: 1, b: 3})).to eq 4
63
+ it 'keeps right quotes in string dot operation' do
64
+ e=Expr[%Q("Hello"),' World!',Op['.']]
65
+ expect(e.result).to eq %Q("Hello World!")
54
66
  end
55
67
 
56
- it 'returns empty string on empty expr' do
57
- e=Expr[]
58
- expect(e.result).to eq ''
68
+ it 'keeps left quotes in string dot operation' do
69
+ e=Expr['Hello ',%Q(_ "World!"),Op['.']]
70
+ expect(e.result).to eq %Q(_ "Hello World!")
59
71
  end
60
72
 
73
+ end
74
+
75
+ context 'when invalid expression' do
76
+
61
77
  it 'raises syntax error on error with binary op' do
62
- e=Expr[1,Op['+']]
63
- expect { e.result }.to raise_error
78
+ e=Expr[1,Op['+']]
79
+ expect { e.result }.to raise_error
64
80
  end
65
81
 
66
82
  it 'raises syntax error on error with lack of op' do
67
- e=Expr[1,2]
68
- expect { e.result }.to raise_error
83
+ e=Expr[1,2]
84
+ expect { e.result }.to raise_error
69
85
  end
70
86
 
87
+ end
88
+
71
89
  end
72
90
 
73
91
  describe '#dump' do
74
- it 'dumps' do
75
- e=Expr[Var['hp'],1,Op['+'],2,Op['*']]
76
- expect(e.dump).to eq 'hp 1 + 2 *'
77
- end
92
+ it 'dumps expr to string' do
93
+ e=Expr[Var['hp'],1,Op['+'],2,Op['*']]
94
+ expect(e.dump).to eq 'hp 1 + 2 *'
95
+ end
78
96
  end
79
97
 
80
98
  describe '#to_s' do
81
- it 'pretty prints for wml file output' do
82
- pending('Do not think I need this feature')
83
- e=Expr[Var['hp'],1,Op['+'],2,Op['*']]
84
- expect(e.to_s).to eq '(hp+1)*2'
85
- end
99
+ it 'pretty prints for wml file output' do
100
+ pending('Do not think I need this feature')
101
+ e=Expr[Var['hp'],1,Op['+'],2,Op['*']]
102
+ expect(e.to_s).to eq '(hp+1)*2'
103
+ end
86
104
  end
87
105
 
88
106
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wml_action
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pancho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-29 00:00:00.000000000 Z
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler