valve-cfg-lint 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 kimoto
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ = valve-cfg-lint
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2011 kimoto. See LICENSE for details.
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "valve-cfg-lint"
8
+ gem.summary = %Q{TODO: one-line summary of your gem}
9
+ gem.description = %Q{TODO: longer description of your gem}
10
+ gem.email = "sub+peerler@gmail.com"
11
+ gem.homepage = "http://github.com/kimoto/valve-cfg-lint"
12
+ gem.authors = ["kimoto"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "valve-cfg-lint #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,25 @@
1
+ require 'valve-cfg-lint'
2
+ require 'open-uri'
3
+ require 'matchdata-highlight'
4
+
5
+ parser = ValveCfgParser.new
6
+ ARGF.each_with_index do |line, index|
7
+ begin
8
+ parser.parse(line)
9
+ puts line
10
+ rescue
11
+ puts line.match(parser.last_error[1]).highlight
12
+ STDERR.puts "format error at line #{index + 1} : #{parser.last_error}"
13
+ end
14
+ end
15
+
16
+ __END__
17
+ ValveCfgParser.new.parse('bind "w" "say hello world!!")
18
+ => no problem
19
+
20
+ ValveCfgParser.new.parse('"hoge" "piyo"')
21
+ => no problem
22
+
23
+ ValveCfgParser.new.parse('"bad command format" "piyo"')
24
+ => throw exception
25
+
@@ -0,0 +1,2 @@
1
+ require_relative 'valve-cfg-parser'
2
+
@@ -0,0 +1,133 @@
1
+ require_relative 'valve-cfg.tab'
2
+
3
+ class ValveCfgParser
4
+ attr_accessor :last_error
5
+
6
+ def parse(str)
7
+ @q = []
8
+ until str.empty?
9
+ case str
10
+ when /\A(\r\n|\n)/
11
+ @q.push [:LINE_FEED, $&]
12
+ when /\A\s+/
13
+ when /\A[\d\.]+/
14
+ @q.push [:NUMBER, $&]
15
+ when /\A\/\/.*$/
16
+ @q.push [:COMMENT_STRING, $&]
17
+ # when /\A"([^\\"]|\\")*"/
18
+ when /\A"[^\s]+"/
19
+ @q.push [:QUOTED_COMMAND, $&]
20
+ when /\A".*"/
21
+ @q.push [:QUOTED_STRING, $&]
22
+ # when /\A'([^\\']|\\')*'/
23
+ # @q.push [:QUOTED_STRING, $&]
24
+ when /\A[a-zA-Z\-\+\\]\w*/
25
+ @q.push [:IDENT, $&]
26
+ when /\A;/
27
+ @q.push [:DELIMITER, $&]
28
+ when /\A./o
29
+ s = $&
30
+ @q.push [s, s]
31
+ end
32
+ str = $'
33
+ end
34
+ @q.push [false, '$end']
35
+ # p @q
36
+ do_parse
37
+ end
38
+
39
+ def next_token
40
+ @q.shift
41
+ end
42
+
43
+ def on_error(token, token_value, stack)
44
+ @last_error = [token, token_value, stack]
45
+ raise "ERROR: token:#{token}, value:#{token_value}, stack:#{stack}"
46
+ end
47
+ end
48
+
49
+ __END__
50
+ p AutoExecp.new.parse('snd_restart')
51
+ p AutoExecp.new.parse("snd_restart")
52
+ p AutoExecp.new.parse('snd_restart "hoge"')
53
+ p AutoExecp.new.parse('"snd_restart" "hoge"')
54
+ p AutoExecp.new.parse('"snd_restart" hoge')
55
+ p AutoExecp.new.parse('bind "hoge \"fuga piyo"')
56
+
57
+ p AutoExecp.new.parse('aaaa')
58
+ p AutoExecp.new.parse('aaaa; hoge')
59
+ p AutoExecp.new.parse(';d')
60
+ p AutoExecp.new.parse('d;')
61
+ p AutoExecp.new.parse(';e;')
62
+ p AutoExecp.new.parse(';')
63
+ p AutoExecp.new.parse(';;;;;;;;')
64
+
65
+ p AutoExecp.new.parse('// test')
66
+ p AutoExecp.new.parse('hoge; hoge // test')
67
+ p AutoExecp.new.parse('hoge hoge // test')
68
+ p AutoExecp.new.parse('hoge "hoge" // test')
69
+ p AutoExecp.new.parse('hoge "h\"oge" // test')
70
+ p AutoExecp.new.parse('// test // unko // test')
71
+ p AutoExecp.new.parse('hoge; hoge "test"; chinko "\"aiueo"')
72
+ p AutoExecp.new.parse(';;;;;;;;;;;;;;;; // test ;;;;;;;')
73
+
74
+ p AutoExecp.new.parse('bind w move')
75
+ p AutoExecp.new.parse('bind "w" "move"')
76
+
77
+ p AutoExecp.new.parse(' ')
78
+ p AutoExecp.new.parse('')
79
+
80
+ p AutoExecp.new.parse('volume 0.4')
81
+ p AutoExecp.new.parse('fps_max 300')
82
+ p AutoExecp.new.parse('-moveleft')
83
+ p AutoExecp.new.parse('+moveleft')
84
+ p AutoExecp.new.parse('+moveleft; -moveleft')
85
+ p AutoExecp.new.parse('alias cheat_enable "sv_cheats 1; god 1; bind MOUSE4 noclip"')
86
+ p AutoExecp.new.parse('unbind "`"')
87
+ p AutoExecp.new.parse('bind "F5" "exec autoexec; say reload autoexec.cfg;"')
88
+ p AutoExecp.new.parse('kz_spec_helper_self 1')
89
+ #p AutoExecp.new.parse('0.4 aiueo')
90
+
91
+ p AutoExecp.new.parse("kz_spec_helper_self 1\n\n\ntest")
92
+
93
+ p AutoExecp.new.parse(<<EOT
94
+ kz_spec_helper_self 1
95
+ sensitivity 10
96
+ cl_randomtips_interval "60"
97
+ cl_randomtips "0"
98
+ kz_shop_auto_show "0"
99
+ cl_showfps "1"
100
+ cl_showpos "1"
101
+ sv_lan "1"
102
+ EOT
103
+ )
104
+
105
+ p AutoExecp.new.parse(<<EOT
106
+ hoge // test
107
+ hoge
108
+ EOT
109
+ )
110
+
111
+ p AutoExecp.new.parse(<<EOT
112
+ alias "quickdemo01" "alias quickdemo quickdemo02; stop; echo quickdemo01; record quickdemo01"
113
+ EOT
114
+ )
115
+
116
+ p AutoExecp.new.parse("rrdecal_purge //remove all spray")
117
+
118
+ p AutoExecp.new.parse(<<EOT
119
+ a
120
+ b
121
+
122
+ // test
123
+ rrdecal_purge //remove all spray
124
+ aaaaaaaaa " test """"""""" "
125
+
126
+ bind "\\" tank
127
+ bind \\ tank
128
+ EOT
129
+ )
130
+
131
+ puts text = 'bind "\" tank'
132
+ puts AutoExecp.new.parse(text)
133
+
@@ -0,0 +1,192 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.7
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+ class ValveCfgParser < Racc::Parser
9
+ ##### State transition tables begin ###
10
+
11
+ racc_action_table = [
12
+ 13, 10, 8, 9, 11, 12, 10, 11, 12, 8,
13
+ 9, 11, 12, 10, 11, 12, 8, 9, 11, 12,
14
+ 10, 11, 12, 8, 9, 11, 12, 10, 11, 12,
15
+ 8, 9, 23, nil, 10, 11, 12, 20, nil, 21,
16
+ 22, 20, nil, 21, 22 ]
17
+
18
+ racc_action_check = [
19
+ 1, 5, 1, 1, 24, 24, 1, 1, 1, 15,
20
+ 15, 2, 2, 15, 15, 15, 0, 0, 14, 14,
21
+ 0, 0, 0, 3, 3, 16, 16, 3, 3, 3,
22
+ 25, 25, 13, nil, 25, 25, 25, 7, nil, 7,
23
+ 7, 19, nil, 19, 19 ]
24
+
25
+ racc_action_pointer = [
26
+ 14, 0, 4, 21, nil, -5, nil, 35, nil, nil,
27
+ nil, nil, nil, 32, 11, 7, 18, nil, nil, 39,
28
+ nil, nil, nil, nil, -3, 28, nil ]
29
+
30
+ racc_action_default = [
31
+ -9, -25, -1, -7, -8, -12, -11, -14, -17, -18,
32
+ -22, -23, -24, -25, -2, -4, -5, -10, -13, -16,
33
+ -19, -20, -21, 27, -3, -4, -15 ]
34
+
35
+ racc_goto_table = [
36
+ 15, 19, 2, 14, 17, 16, 18, 1, nil, nil,
37
+ nil, nil, 15, 26, 25, nil, nil, nil, nil, nil,
38
+ nil, nil, 15 ]
39
+
40
+ racc_goto_check = [
41
+ 3, 9, 2, 2, 6, 2, 8, 1, nil, nil,
42
+ nil, nil, 3, 9, 3, nil, nil, nil, nil, nil,
43
+ nil, nil, 3 ]
44
+
45
+ racc_goto_pointer = [
46
+ nil, 7, 2, -2, nil, nil, -1, nil, -1, -6 ]
47
+
48
+ racc_goto_default = [
49
+ nil, nil, 24, 3, 4, 5, 6, 7, nil, nil ]
50
+
51
+ racc_reduce_table = [
52
+ 0, 0, :racc_error,
53
+ 1, 10, :_reduce_none,
54
+ 2, 10, :_reduce_none,
55
+ 3, 11, :_reduce_none,
56
+ 2, 11, :_reduce_none,
57
+ 2, 11, :_reduce_none,
58
+ 3, 11, :_reduce_none,
59
+ 1, 11, :_reduce_none,
60
+ 1, 11, :_reduce_none,
61
+ 0, 11, :_reduce_none,
62
+ 2, 13, :_reduce_none,
63
+ 1, 13, :_reduce_none,
64
+ 1, 13, :_reduce_none,
65
+ 2, 14, :_reduce_none,
66
+ 1, 14, :_reduce_none,
67
+ 2, 17, :_reduce_none,
68
+ 1, 17, :_reduce_none,
69
+ 1, 16, :_reduce_none,
70
+ 1, 16, :_reduce_none,
71
+ 1, 18, :_reduce_none,
72
+ 1, 18, :_reduce_none,
73
+ 1, 18, :_reduce_none,
74
+ 1, 15, :_reduce_none,
75
+ 1, 12, :_reduce_none,
76
+ 1, 12, :_reduce_none ]
77
+
78
+ racc_reduce_n = 25
79
+
80
+ racc_shift_n = 27
81
+
82
+ racc_token_table = {
83
+ false => 0,
84
+ :error => 1,
85
+ :IDENT => 2,
86
+ :QUOTED_COMMAND => 3,
87
+ :QUOTED_STRING => 4,
88
+ :NUMBER => 5,
89
+ :COMMENT_STRING => 6,
90
+ :DELIMITER => 7,
91
+ :LINE_FEED => 8 }
92
+
93
+ racc_nt_base = 9
94
+
95
+ racc_use_result_var = true
96
+
97
+ Racc_arg = [
98
+ racc_action_table,
99
+ racc_action_check,
100
+ racc_action_default,
101
+ racc_action_pointer,
102
+ racc_goto_table,
103
+ racc_goto_check,
104
+ racc_goto_default,
105
+ racc_goto_pointer,
106
+ racc_nt_base,
107
+ racc_reduce_table,
108
+ racc_token_table,
109
+ racc_shift_n,
110
+ racc_reduce_n,
111
+ racc_use_result_var ]
112
+
113
+ Racc_token_to_s_table = [
114
+ "$end",
115
+ "error",
116
+ "IDENT",
117
+ "QUOTED_COMMAND",
118
+ "QUOTED_STRING",
119
+ "NUMBER",
120
+ "COMMENT_STRING",
121
+ "DELIMITER",
122
+ "LINE_FEED",
123
+ "$start",
124
+ "target",
125
+ "exp",
126
+ "delim",
127
+ "param",
128
+ "cmd",
129
+ "comment",
130
+ "command",
131
+ "argument_list",
132
+ "argument" ]
133
+
134
+ Racc_debug_parser = false
135
+
136
+ ##### State transition tables end #####
137
+
138
+ # reduce 0 omitted
139
+
140
+ # reduce 1 omitted
141
+
142
+ # reduce 2 omitted
143
+
144
+ # reduce 3 omitted
145
+
146
+ # reduce 4 omitted
147
+
148
+ # reduce 5 omitted
149
+
150
+ # reduce 6 omitted
151
+
152
+ # reduce 7 omitted
153
+
154
+ # reduce 8 omitted
155
+
156
+ # reduce 9 omitted
157
+
158
+ # reduce 10 omitted
159
+
160
+ # reduce 11 omitted
161
+
162
+ # reduce 12 omitted
163
+
164
+ # reduce 13 omitted
165
+
166
+ # reduce 14 omitted
167
+
168
+ # reduce 15 omitted
169
+
170
+ # reduce 16 omitted
171
+
172
+ # reduce 17 omitted
173
+
174
+ # reduce 18 omitted
175
+
176
+ # reduce 19 omitted
177
+
178
+ # reduce 20 omitted
179
+
180
+ # reduce 21 omitted
181
+
182
+ # reduce 22 omitted
183
+
184
+ # reduce 23 omitted
185
+
186
+ # reduce 24 omitted
187
+
188
+ def _reduce_none(val, _values, result)
189
+ val[0]
190
+ end
191
+
192
+ end # class ValveCfgParser
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'valve-cfg-lint'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ValveCfgLintTest < Test::Unit::TestCase
4
+ should true do
5
+ true
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: valve-cfg-lint
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - kimoto
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-11-28 00:00:00 +09:00
18
+ default_executable: valve-cfg-lint
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: "valve cfg file format validator - example: autoexec.cfg, userconfig.cfg"
34
+ email: sub+peerler@gmail.com
35
+ executables:
36
+ - valve-cfg-lint
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - LICENSE
41
+ - README.rdoc
42
+ files:
43
+ - .document
44
+ - .gitignore
45
+ - LICENSE
46
+ - README.rdoc
47
+ - Rakefile
48
+ - VERSION
49
+ - lib/valve-cfg-lint.rb
50
+ - lib/valve-cfg-parser.rb
51
+ - lib/valve-cfg.tab.rb
52
+ - test/test_helper.rb
53
+ - test/valve-cfg-lint_test.rb
54
+ - bin/valve-cfg-lint
55
+ has_rdoc: true
56
+ homepage: http://github.com/kimoto/valve-cfg-lint
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.7
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: valve cfg file format validator
87
+ test_files:
88
+ - test/test_helper.rb
89
+ - test/valve-cfg-lint_test.rb