wml_action 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rubocop.yml +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +113 -0
- data/Rakefile +18 -0
- data/bin/wml_action +5 -0
- data/lib/wml_action/cli.rb +55 -0
- data/lib/wml_action/document.rb +22 -0
- data/lib/wml_action/lexer.rex +50 -0
- data/lib/wml_action/lexer.rex.rb +136 -0
- data/lib/wml_action/log.rb +19 -0
- data/lib/wml_action/parser.tab.rb +318 -0
- data/lib/wml_action/parser.y +52 -0
- data/lib/wml_action/tag.rb +144 -0
- data/lib/wml_action/version.rb +3 -0
- data/lib/wml_action.rb +9 -0
- data/spec/document_spec.rb +79 -0
- data/spec/fixtures/actions.cfg +14 -0
- data/spec/fixtures/as_from_file.cfg +15 -0
- data/spec/fixtures/attributes.cfg +7 -0
- data/spec/fixtures/filter.cfg +4 -0
- data/spec/fixtures/inners.cfg +11 -0
- data/spec/fixtures/macros.cfg +3 -0
- data/spec/fixtures/s_from_file.cfg +8 -0
- data/spec/fixtures/strings.cfg +9 -0
- data/spec/fixtures/tag.cfg +2 -0
- data/spec/tag_spec.rb +235 -0
- data/wml_action.gemspec +36 -0
- metadata +253 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NmFjMGE1ODU2Y2NkNTU3NDQyYTdjZDg5ZjUwYzExMWY2MjM4MTlkOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YjU4MjFiNjBiYjlmZWYzNTFkYmQ3NjAyNDE2ZTMyZDk5YzQxNGYwZQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MWJkMDEzZjY0YzBlY2JjMWU5YmM5OTgyNzJhMjFiYWY1NjdhMjEyZWYwN2Yx
|
10
|
+
MjBjMGM1OWRjZGYwMDM3MzA3MTQyOGEwOTU5ZDJmYjI4ODZjZGFkNTM1MTcz
|
11
|
+
YzEyNzA3NmEwYTA5YzIxZDBmNDgzYzI5Y2E0YWIwZGQwYWRjMGQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTlhMjJiYTU0Njk3MmIzYzMxNDZiM2E3ODI2MTFmODA2Y2QxNDQ1MjAwNDhl
|
14
|
+
MTcyMTRlMzllYzZiM2Y2NGVhN2Q5ZGIyNjExMDQzNWU4MjIxYTM4MTZhNTkz
|
15
|
+
N2IyOWQ2OGYyZTA4ZjE4NjJlYzU5YzY5ODdjNGMwNzAzZWQxNTU=
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require: rubocop-rspec
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Pancho
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# WMLAction
|
2
|
+
|
3
|
+
WMLAction is WML parser and modifier. WML modifications described as simple extension to WML. If you have many WML files and want to do some modifications to them all, then you can give it a try.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
### Changing/adding attributes:
|
8
|
+
File:
|
9
|
+
```
|
10
|
+
[unit]
|
11
|
+
hp=10
|
12
|
+
level=1
|
13
|
+
[/unit]
|
14
|
+
```
|
15
|
+
Modifications:
|
16
|
+
```
|
17
|
+
[unit]
|
18
|
+
hp=25
|
19
|
+
race="human"
|
20
|
+
{REGENERATES}
|
21
|
+
[unit]
|
22
|
+
```
|
23
|
+
Becomes:
|
24
|
+
```
|
25
|
+
[unit]
|
26
|
+
hp=25
|
27
|
+
level=1
|
28
|
+
race="human"
|
29
|
+
{REGENERATES}
|
30
|
+
[unit]
|
31
|
+
```
|
32
|
+
### Adding tags
|
33
|
+
File:
|
34
|
+
```
|
35
|
+
[unit]
|
36
|
+
[/unit]
|
37
|
+
```
|
38
|
+
Modifications:
|
39
|
+
```
|
40
|
+
[unit]
|
41
|
+
+ [attack]
|
42
|
+
damage=1
|
43
|
+
[/attack]
|
44
|
+
[/unit]
|
45
|
+
```
|
46
|
+
Becomes:
|
47
|
+
```
|
48
|
+
[unit]
|
49
|
+
[attack]
|
50
|
+
damage=1
|
51
|
+
[/attack]
|
52
|
+
[/unit]
|
53
|
+
```
|
54
|
+
|
55
|
+
### Operations on tags with filters
|
56
|
+
File:
|
57
|
+
```
|
58
|
+
[unit]
|
59
|
+
[attack]
|
60
|
+
range=ranged
|
61
|
+
[/attack]
|
62
|
+
[attack]
|
63
|
+
range=melee
|
64
|
+
[/attack]
|
65
|
+
[/unit]
|
66
|
+
```
|
67
|
+
Modifications:
|
68
|
+
```
|
69
|
+
[unit]
|
70
|
+
[attack]
|
71
|
+
/ range=melee
|
72
|
+
damage=10
|
73
|
+
[/attack]
|
74
|
+
[/unit]
|
75
|
+
```
|
76
|
+
Becomes:
|
77
|
+
```
|
78
|
+
[unit]
|
79
|
+
[attack]
|
80
|
+
range=ranged
|
81
|
+
[/attack]
|
82
|
+
[attack]
|
83
|
+
range=melee
|
84
|
+
damage=10
|
85
|
+
[/attack]
|
86
|
+
[/unit]
|
87
|
+
```
|
88
|
+
|
89
|
+
## Installation
|
90
|
+
|
91
|
+
Add this line to your application's Gemfile:
|
92
|
+
|
93
|
+
gem 'wml_action'
|
94
|
+
|
95
|
+
And then execute:
|
96
|
+
|
97
|
+
$ bundle
|
98
|
+
|
99
|
+
Or install it yourself as:
|
100
|
+
|
101
|
+
$ gem install wml_action
|
102
|
+
|
103
|
+
## Usage
|
104
|
+
|
105
|
+
$ wml_action modify wml_file actions_file
|
106
|
+
|
107
|
+
## Contributing
|
108
|
+
|
109
|
+
1. Fork it
|
110
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
111
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
112
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
113
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
Rake.application.rake_require "oedipus_lex"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
task lexer: "lib/wml_action/lexer.rex.rb"
|
9
|
+
|
10
|
+
task parser: [:lexer] do |t|
|
11
|
+
ruby "-S racc lib/wml_action/parser.y"
|
12
|
+
end
|
13
|
+
|
14
|
+
#task :test => [:parser, :lexer] do |t|
|
15
|
+
# sh "bundle exec ruby lib/parser.rb lib/sample.cfg"
|
16
|
+
#end
|
17
|
+
#
|
18
|
+
#task default: :test
|
data/bin/wml_action
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'wml_action'
|
3
|
+
|
4
|
+
module WMLAction
|
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
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "wml_action/tag"
|
2
|
+
require "wml_action/parser.tab"
|
3
|
+
|
4
|
+
module WMLAction
|
5
|
+
|
6
|
+
class Document
|
7
|
+
|
8
|
+
attr_reader :root
|
9
|
+
|
10
|
+
def initialize(root)
|
11
|
+
@root = root
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_file(filename)
|
15
|
+
root = Parser.new.parse_file(filename)
|
16
|
+
#TODO file exceptions
|
17
|
+
Document.new(root)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
require "racc/parser"
|
3
|
+
|
4
|
+
module WMLAction
|
5
|
+
|
6
|
+
class Parser < Racc::Parser
|
7
|
+
|
8
|
+
options
|
9
|
+
#debug
|
10
|
+
|
11
|
+
macro
|
12
|
+
OTAG /\[(\w+)\]/
|
13
|
+
CTAG /\[\/(\w+)\]/
|
14
|
+
ATTR /(\w+)=/
|
15
|
+
MACRO /\{.+\}/
|
16
|
+
ANUMBER /-?\d+/
|
17
|
+
ASTR /"[^"]*"/
|
18
|
+
APLAIN /.+/
|
19
|
+
SLASH /\//
|
20
|
+
COMMENT /\#.*$/
|
21
|
+
|
22
|
+
BLANK /[ \t]+/
|
23
|
+
|
24
|
+
rule
|
25
|
+
|
26
|
+
/#{COMMENT}/
|
27
|
+
/#{OTAG}/ { [:OTAG, match[1]] }
|
28
|
+
/#{CTAG}/ { [:CTAG, match[1]] }
|
29
|
+
/#{ATTR}/ { @state = :INATTR; [:ATTR, match[1]] }
|
30
|
+
/#{MACRO}/ { [:MACRO, text] }
|
31
|
+
/#{SLASH}/ { [:SLASH, text] }
|
32
|
+
/\-/ { [text,text] }
|
33
|
+
/\+/ { [text,text] }
|
34
|
+
|
35
|
+
:INATTR /\n/ { @state = nil }
|
36
|
+
:INATTR /#{BLANK}/
|
37
|
+
:INATTR /#{ANUMBER}\s+/ { @state = nil; [:ANUMBER, text.to_i] }
|
38
|
+
:INATTR /#{ASTR}/ { [:ASTR, text] }
|
39
|
+
:INATTR /#{MACRO}/ { [:AMACRO, text] }
|
40
|
+
:INATTR /_/ { [:UNDERSC, text] }
|
41
|
+
:INATTR /\+/ { [:APLUS, text] }
|
42
|
+
:INATTR /#{APLAIN}/ { [:APLAIN, text] }
|
43
|
+
|
44
|
+
/./
|
45
|
+
/\n/
|
46
|
+
|
47
|
+
inner
|
48
|
+
end
|
49
|
+
|
50
|
+
end #module
|
@@ -0,0 +1,136 @@
|
|
1
|
+
#--
|
2
|
+
# This file is automatically generated. Do not modify it.
|
3
|
+
# Generated by: oedipus_lex version 2.3.0.
|
4
|
+
# Source: lib/wml_action/lexer.rex
|
5
|
+
#++
|
6
|
+
|
7
|
+
|
8
|
+
require "racc/parser"
|
9
|
+
|
10
|
+
module WMLAction
|
11
|
+
|
12
|
+
class Parser < Racc::Parser
|
13
|
+
require 'strscan'
|
14
|
+
|
15
|
+
OTAG = /\[(\w+)\]/
|
16
|
+
CTAG = /\[\/(\w+)\]/
|
17
|
+
ATTR = /(\w+)=/
|
18
|
+
MACRO = /\{.+\}/
|
19
|
+
ANUMBER = /-?\d+/
|
20
|
+
ASTR = /"[^"]*"/
|
21
|
+
APLAIN = /.+/
|
22
|
+
SLASH = /\//
|
23
|
+
COMMENT = /\#.*$/
|
24
|
+
BLANK = /[ \t]+/
|
25
|
+
|
26
|
+
class ScanError < StandardError ; end
|
27
|
+
|
28
|
+
attr_accessor :lineno
|
29
|
+
attr_accessor :filename
|
30
|
+
attr_accessor :ss
|
31
|
+
attr_accessor :state
|
32
|
+
|
33
|
+
alias :match :ss
|
34
|
+
|
35
|
+
def matches
|
36
|
+
m = (1..9).map { |i| ss[i] }
|
37
|
+
m.pop until m[-1] or m.empty?
|
38
|
+
m
|
39
|
+
end
|
40
|
+
|
41
|
+
def action
|
42
|
+
yield
|
43
|
+
end
|
44
|
+
|
45
|
+
def scanner_class
|
46
|
+
StringScanner
|
47
|
+
end unless instance_methods(false).map(&:to_s).include?("scanner_class")
|
48
|
+
|
49
|
+
def parse str
|
50
|
+
self.ss = scanner_class.new str
|
51
|
+
self.lineno = 1
|
52
|
+
self.state ||= nil
|
53
|
+
|
54
|
+
do_parse
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_file path
|
58
|
+
self.filename = path
|
59
|
+
open path do |f|
|
60
|
+
parse f.read
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def next_token
|
65
|
+
|
66
|
+
token = nil
|
67
|
+
|
68
|
+
until ss.eos? or token do
|
69
|
+
token =
|
70
|
+
case state
|
71
|
+
when nil then
|
72
|
+
case
|
73
|
+
when text = ss.scan(/#{COMMENT}/) then
|
74
|
+
# do nothing
|
75
|
+
when text = ss.scan(/#{OTAG}/) then
|
76
|
+
action { [:OTAG, match[1]] }
|
77
|
+
when text = ss.scan(/#{CTAG}/) then
|
78
|
+
action { [:CTAG, match[1]] }
|
79
|
+
when text = ss.scan(/#{ATTR}/) then
|
80
|
+
action { @state = :INATTR; [:ATTR, match[1]] }
|
81
|
+
when text = ss.scan(/#{MACRO}/) then
|
82
|
+
action { [:MACRO, text] }
|
83
|
+
when text = ss.scan(/#{SLASH}/) then
|
84
|
+
action { [:SLASH, text] }
|
85
|
+
when text = ss.scan(/\-/) then
|
86
|
+
action { [text,text] }
|
87
|
+
when text = ss.scan(/\+/) then
|
88
|
+
action { [text,text] }
|
89
|
+
when text = ss.scan(/./) then
|
90
|
+
# do nothing
|
91
|
+
when text = ss.scan(/\n/) then
|
92
|
+
# do nothing
|
93
|
+
else
|
94
|
+
text = ss.string[ss.pos .. -1]
|
95
|
+
raise ScanError, "can not match (#{state.inspect}): '#{text}'"
|
96
|
+
end
|
97
|
+
when :INATTR then
|
98
|
+
case
|
99
|
+
when text = ss.scan(/\n/) then
|
100
|
+
action { @state = nil }
|
101
|
+
when text = ss.scan(/#{BLANK}/) then
|
102
|
+
# do nothing
|
103
|
+
when text = ss.scan(/#{ANUMBER}\s+/) then
|
104
|
+
action { @state = nil; [:ANUMBER, text.to_i] }
|
105
|
+
when text = ss.scan(/#{ASTR}/) then
|
106
|
+
action { [:ASTR, text] }
|
107
|
+
when text = ss.scan(/#{MACRO}/) then
|
108
|
+
action { [:AMACRO, text] }
|
109
|
+
when text = ss.scan(/_/) then
|
110
|
+
action { [:UNDERSC, text] }
|
111
|
+
when text = ss.scan(/\+/) then
|
112
|
+
action { [:APLUS, text] }
|
113
|
+
when text = ss.scan(/#{APLAIN}/) then
|
114
|
+
action { [:APLAIN, text] }
|
115
|
+
else
|
116
|
+
text = ss.string[ss.pos .. -1]
|
117
|
+
raise ScanError, "can not match (#{state.inspect}): '#{text}'"
|
118
|
+
end
|
119
|
+
else
|
120
|
+
raise ScanError, "undefined state: '#{state}'"
|
121
|
+
end # token = case state
|
122
|
+
|
123
|
+
next unless token # allow functions to trigger redo w/ nil
|
124
|
+
end # while
|
125
|
+
|
126
|
+
raise "bad lexical result: #{token.inspect}" unless
|
127
|
+
token.nil? || (Array === token && token.size >= 2)
|
128
|
+
|
129
|
+
# auto-switch state
|
130
|
+
self.state = token.last if token && token.first == :state
|
131
|
+
|
132
|
+
token
|
133
|
+
end # def next_token
|
134
|
+
end # class
|
135
|
+
|
136
|
+
end #module
|