coderay_bash 0.2.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/coderay_bash.gemspec +4 -4
- data/lib/coderay/scanners/bash.rb +82 -35
- data/lib/coderay/scanners/erb_bash.rb +2 -2
- metadata +14 -11
data/coderay_bash.gemspec
CHANGED
@@ -13,17 +13,17 @@ spec = Gem::Specification.new do |s|
|
|
13
13
|
s.email = "pejuko@gmail.com"
|
14
14
|
s.authors = ["Petr Kovar"]
|
15
15
|
s.name = 'coderay_bash'
|
16
|
-
s.version = '0
|
16
|
+
s.version = '1.0'
|
17
17
|
s.date = Time.now.strftime("%Y-%m-%d")
|
18
|
-
s.add_dependency('coderay', '
|
18
|
+
s.add_dependency('coderay', '>= 1.0')
|
19
19
|
s.require_path = 'lib'
|
20
20
|
s.files = ["README.md", "coderay_bash.gemspec", "Rakefile"]
|
21
21
|
s.files += Dir["lib/**/*.rb"]
|
22
22
|
s.post_install_message = <<EOF
|
23
|
-
This gem was tested with coderay 0
|
23
|
+
This gem was tested with coderay 1.0 and won't work with coderay 0.9.
|
24
24
|
EOF
|
25
25
|
s.description = <<EOF
|
26
|
-
Bash highlighting for coderay. This gem was tested with coderay 0
|
26
|
+
Bash highlighting for coderay. This gem was tested with coderay 1.0 and won't work with coderay < 1.0.
|
27
27
|
EOF
|
28
28
|
end
|
29
29
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# Scanner for Bash
|
2
2
|
# Author: Petr Kovar <pejuko@gmail.com>
|
3
|
-
|
4
|
-
module Scanners
|
3
|
+
|
4
|
+
module CodeRay module Scanners
|
5
|
+
|
5
6
|
class Bash < Scanner
|
6
7
|
|
7
8
|
register_for :bash
|
@@ -22,6 +23,14 @@ module Scanners
|
|
22
23
|
local logout printf read set shopt source type typeset ulimit unalias
|
23
24
|
)
|
24
25
|
|
26
|
+
PROGRAMS = %w(
|
27
|
+
awk bash bunzip2 bzcat bzip2 cat chgrp chmod chown cp cut date dd df dir dmesg du ed egrep
|
28
|
+
false fgrep findmnt fusermount gawk grep groups gunzip gzip hostname install keyctl kill less
|
29
|
+
ln loadkeys login ls lsblk lsinitcpio lsmod mbchk mkdir mkfifo mknod more mount mountpoint mv
|
30
|
+
netstat pidof ping ping6 ps pwd readlink red rm rmdir sed sh shred sleep stty su sudo sync tar
|
31
|
+
touch tput tr traceroute traceroute6 true umount uname uncompress vdir zcat
|
32
|
+
)
|
33
|
+
|
25
34
|
VARIABLES = %w(
|
26
35
|
CDPATH HOME IFS MAIL MAILPATH OPTARG OPTIND PATH PS1 PS2
|
27
36
|
)
|
@@ -46,8 +55,9 @@ module Scanners
|
|
46
55
|
add(RESERVED_WORDS, :reserved).
|
47
56
|
add(COMMANDS, :method).
|
48
57
|
add(BASH_COMMANDS, :method).
|
49
|
-
add(
|
50
|
-
add(
|
58
|
+
# add(PROGRAMS, :method).
|
59
|
+
add(VARIABLES, :predefined).
|
60
|
+
add(BASH_VARIABLES, :predefined)
|
51
61
|
|
52
62
|
attr_reader :state, :quote
|
53
63
|
|
@@ -55,35 +65,46 @@ module Scanners
|
|
55
65
|
super(*args)
|
56
66
|
@state = :initial
|
57
67
|
@quote = nil
|
68
|
+
@shell = false
|
58
69
|
end
|
59
70
|
|
60
|
-
def scan_tokens
|
71
|
+
def scan_tokens encoder, options
|
61
72
|
|
62
73
|
until eos?
|
63
74
|
kind = match = nil
|
64
75
|
|
65
76
|
if match = scan(/\n/)
|
66
|
-
|
77
|
+
encoder.text_token(match, :end_line)
|
67
78
|
next
|
68
79
|
end
|
69
80
|
|
70
81
|
if @state == :initial
|
71
82
|
if match = scan(/\A#!.*/)
|
72
83
|
kind = :directive
|
73
|
-
elsif match = scan(
|
84
|
+
elsif match = scan(/\s*#.*/)
|
74
85
|
kind = :comment
|
86
|
+
elsif match = scan(/.#/)
|
87
|
+
kind = :ident
|
75
88
|
elsif match = scan(/(?:\. |source ).*/)
|
76
89
|
kind = :reserved
|
77
90
|
elsif match = scan(/(?:\\.|,)/)
|
78
91
|
kind = :plain
|
79
92
|
elsif match = scan(/;/)
|
80
93
|
kind = :delimiter
|
81
|
-
elsif match = scan(/
|
94
|
+
elsif match = scan(/"/)
|
82
95
|
@state = :quote
|
83
96
|
@quote = match
|
84
|
-
|
85
|
-
|
86
|
-
|
97
|
+
encoder.begin_group :string
|
98
|
+
encoder.text_token(match, :delimiter)
|
99
|
+
next
|
100
|
+
elsif match = scan(/`/)
|
101
|
+
if @shell
|
102
|
+
encoder.end_group :shell
|
103
|
+
else
|
104
|
+
encoder.begin_group :shell
|
105
|
+
end
|
106
|
+
@shell = (not @shell)
|
107
|
+
encoder.text_token(match, :delimiter)
|
87
108
|
next
|
88
109
|
elsif match = scan(/'[^']*'/)
|
89
110
|
kind = :string
|
@@ -100,12 +121,19 @@ module Scanners
|
|
100
121
|
kind = :global_variable
|
101
122
|
elsif match = scan(/ \$\{ [^\}]+ \} /ox)
|
102
123
|
match =~ /\$\{(.*)\}/
|
103
|
-
|
124
|
+
var=$1
|
125
|
+
if var =~ /\[.*\]/
|
126
|
+
encoder.text_token("${", :instance_variable)
|
127
|
+
match_array(var, encoder)
|
128
|
+
encoder.text_token("}", :instance_variable)
|
129
|
+
next
|
130
|
+
end
|
131
|
+
kind = IDENT_KIND[var]
|
104
132
|
kind = :instance_variable if kind == :ident
|
105
133
|
elsif match = scan(/ \$\( [^\)]+ \) /ox)
|
106
134
|
kind = :shell
|
107
135
|
elsif match = scan(PRE_CONSTANTS)
|
108
|
-
kind = :
|
136
|
+
kind = :predefined_constant
|
109
137
|
elsif match = scan(/[^\s'"]*[A-Za-z_][A-Za-z_0-9]*\+?=/)
|
110
138
|
match =~ /(.*?)([A-Za-z_][A-Za-z_0-9]*)(\+?=)/
|
111
139
|
str = $1
|
@@ -115,23 +143,23 @@ module Scanners
|
|
115
143
|
if str.to_s.strip.empty?
|
116
144
|
kind = IDENT_KIND[pre]
|
117
145
|
kind = :instance_variable if kind == :ident
|
118
|
-
|
119
|
-
|
146
|
+
encoder.text_token(pre, kind)
|
147
|
+
encoder.text_token(op, :operator)
|
120
148
|
next
|
121
149
|
end
|
122
|
-
elsif match = scan(/[A-Za-z_]+\[[A-Za-z_
|
150
|
+
elsif match = scan(/[A-Za-z_]+\[[A-Za-z_\@\*\d]+\]/)
|
123
151
|
# array
|
124
|
-
|
125
|
-
|
152
|
+
match_array(match, encoder)
|
153
|
+
next
|
126
154
|
elsif match = scan(/ \$[A-Za-z_][A-Za-z_0-9]* /ox)
|
127
155
|
match =~ /\$(.*)/
|
128
156
|
kind = IDENT_KIND[$1]
|
129
157
|
kind = :instance_variable if kind == :ident
|
130
158
|
elsif match = scan(/read \S+/)
|
131
159
|
match =~ /read(\s+)(\S+)/
|
132
|
-
|
133
|
-
|
134
|
-
|
160
|
+
encoder.text_token('read', :method)
|
161
|
+
encoder.text_token($1, :space)
|
162
|
+
encoder.text_token($2, :instance_variable)
|
135
163
|
next
|
136
164
|
elsif match = scan(/[\!\:\[\]\{\}]/)
|
137
165
|
kind = :reserved
|
@@ -139,8 +167,8 @@ module Scanners
|
|
139
167
|
match =~ /([^;]+);?/
|
140
168
|
kind = IDENT_KIND[$1]
|
141
169
|
if match[/([^;]+);$/]
|
142
|
-
|
143
|
-
|
170
|
+
encoder.text_token($1, kind)
|
171
|
+
encoder.text_token(';', :delimiter)
|
144
172
|
next
|
145
173
|
end
|
146
174
|
elsif match = scan(/(?: = | - | \+ | \{ | \} | \( | \) | && | \|\| | ;; | ! )/ox)
|
@@ -157,23 +185,30 @@ module Scanners
|
|
157
185
|
if (match = scan(/\\.?/))
|
158
186
|
kind = :content
|
159
187
|
elsif match = scan(/#{@quote}/)
|
160
|
-
|
161
|
-
|
162
|
-
tokens << [:close, :shell] if @quote == "`"
|
188
|
+
encoder.text_token(match, :delimiter)
|
189
|
+
encoder.end_group :string
|
163
190
|
@quote = nil
|
164
191
|
@state = :initial
|
165
192
|
next
|
166
193
|
#kind = :symbol
|
167
194
|
elsif match = scan(PRE_CONSTANTS)
|
168
|
-
kind = :
|
169
|
-
elsif match = scan(/ \$\
|
195
|
+
kind = :predefined_constant
|
196
|
+
elsif match = scan(/ (?: \$\(\(.*?\)\) ) /x)
|
197
|
+
kind = :global_variable
|
198
|
+
elsif match = scan(/ \$ (?: (?: \{ [^\}]* \}) | (?: [A-Za-z_0-9]+ ) ) /x)
|
199
|
+
match =~ /(\$\{?)([^\}]*)(\}?)/
|
200
|
+
pre=$1
|
201
|
+
var=$2
|
202
|
+
post=$3
|
203
|
+
if var =~ /\[.*?\]/
|
204
|
+
encoder.text_token(pre,:instance_variable)
|
205
|
+
match_array(var, encoder)
|
206
|
+
encoder.text_token(post,:instance_variable)
|
207
|
+
next
|
208
|
+
end
|
170
209
|
kind = IDENT_KIND[match]
|
171
210
|
kind = :instance_variable if kind == :ident
|
172
|
-
elsif
|
173
|
-
kind = :content
|
174
|
-
elsif (@quote == '"') and (match = scan(/\$`/))
|
175
|
-
kind = :content
|
176
|
-
elsif match = scan(/[^#{@quote}\$\\]+/)
|
211
|
+
elsif match = scan(/[^#{@quote}\\]+/)
|
177
212
|
kind = :content
|
178
213
|
else match = scan(/.+/)
|
179
214
|
# this shouldn't be
|
@@ -184,12 +219,24 @@ module Scanners
|
|
184
219
|
end
|
185
220
|
|
186
221
|
match ||= matched
|
187
|
-
|
222
|
+
encoder.text_token(match, kind)
|
188
223
|
end
|
189
224
|
|
190
|
-
|
225
|
+
encoder
|
191
226
|
end
|
192
227
|
|
228
|
+
|
229
|
+
def match_array(match, encoder)
|
230
|
+
match =~ /([A-Za-z_]+)\[(.*?)\]/
|
231
|
+
var = $1
|
232
|
+
key = $2
|
233
|
+
kind = IDENT_KIND[var]
|
234
|
+
kind = :instance_variable if kind == :ident
|
235
|
+
encoder.text_token(var, kind)
|
236
|
+
encoder.text_token("[", :operator)
|
237
|
+
encoder.text_token(key, :key)
|
238
|
+
encoder.text_token("]", :operator)
|
239
|
+
end
|
193
240
|
|
194
241
|
def handle_error(match, options)
|
195
242
|
o = {:ignore_errors => true}.merge(options)
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coderay_bash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
|
-
- 0
|
7
|
-
- 2
|
8
7
|
- 1
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: "1.0"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Petr Kovar
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-10-04 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -23,8 +23,9 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
28
29
|
segments:
|
29
30
|
- 1
|
30
31
|
- 0
|
@@ -32,7 +33,7 @@ dependencies:
|
|
32
33
|
type: :runtime
|
33
34
|
version_requirements: *id001
|
34
35
|
description: |
|
35
|
-
Bash highlighting for coderay. This gem was tested with coderay 0
|
36
|
+
Bash highlighting for coderay. This gem was tested with coderay 1.0 and won't work with coderay < 1.0.
|
36
37
|
|
37
38
|
email: pejuko@gmail.com
|
38
39
|
executables: []
|
@@ -45,15 +46,15 @@ files:
|
|
45
46
|
- README.md
|
46
47
|
- coderay_bash.gemspec
|
47
48
|
- Rakefile
|
48
|
-
- lib/coderay/scanners/erb_bash.rb
|
49
|
-
- lib/coderay/scanners/bash.rb
|
50
49
|
- lib/coderay_bash.rb
|
50
|
+
- lib/coderay/scanners/bash.rb
|
51
|
+
- lib/coderay/scanners/erb_bash.rb
|
51
52
|
has_rdoc: true
|
52
53
|
homepage: http://github.com/pejuko/coderay_bash
|
53
54
|
licenses: []
|
54
55
|
|
55
56
|
post_install_message: |
|
56
|
-
This gem was tested with coderay 0
|
57
|
+
This gem was tested with coderay 1.0 and won't work with coderay 0.9.
|
57
58
|
|
58
59
|
rdoc_options: []
|
59
60
|
|
@@ -64,6 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
65
|
requirements:
|
65
66
|
- - ">="
|
66
67
|
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
67
69
|
segments:
|
68
70
|
- 0
|
69
71
|
version: "0"
|
@@ -72,13 +74,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
74
|
requirements:
|
73
75
|
- - ">="
|
74
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
75
78
|
segments:
|
76
79
|
- 0
|
77
80
|
version: "0"
|
78
81
|
requirements: []
|
79
82
|
|
80
83
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.6.0
|
82
85
|
signing_key:
|
83
86
|
specification_version: 3
|
84
87
|
summary: Simple bash scanner for highlighting with coderay.
|