coderay_bash 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/coderay_bash.gemspec +1 -1
- data/lib/coderay/scanners/bash.rb +44 -32
- data/lib/coderay_bash.rb +0 -1
- metadata +3 -3
data/coderay_bash.gemspec
CHANGED
@@ -13,7 +13,7 @@ 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.1.
|
16
|
+
s.version = '0.1.2'
|
17
17
|
s.date = Time.now.strftime("%Y-%m-%d")
|
18
18
|
s.add_dependency('coderay', '< 1.0')
|
19
19
|
s.require_path = 'lib'
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# Scanner for Bash
|
2
2
|
# Author: Petr Kovar <pejuko@gmail.com>
|
3
|
-
module CodeRay
|
3
|
+
module CodeRay
|
4
|
+
module Scanners
|
4
5
|
class Bash < Scanner
|
5
6
|
|
6
7
|
register_for :bash
|
@@ -21,8 +22,6 @@ module CodeRay::Scanners
|
|
21
22
|
local logout printf read set shopt source type typeset ulimit unalias
|
22
23
|
)
|
23
24
|
|
24
|
-
RESERVED = RESERVED_WORDS + COMMANDS + BASH_COMMANDS
|
25
|
-
|
26
25
|
VARIABLES = %w(
|
27
26
|
CDPATH HOME IFS MAIL MAILPATH OPTARG OPTIND PATH PS1 PS2
|
28
27
|
)
|
@@ -41,7 +40,14 @@ module CodeRay::Scanners
|
|
41
40
|
RANDOM REPLAY SECONDS SHELL SHELLOPTS SHLVL TIMEFORMAT TMOUT TMPDIR UID
|
42
41
|
)
|
43
42
|
|
44
|
-
|
43
|
+
PRE_CONSTANTS = / \$\{? (?: \# | \? | \d | \* | @ | - | \$ | \! | _ ) \}? /ox
|
44
|
+
|
45
|
+
IDENT_KIND = WordList.new(:ident).
|
46
|
+
add(RESERVED_WORDS, :reserved).
|
47
|
+
add(COMMANDS, :method).
|
48
|
+
add(BASH_COMMANDS, :method).
|
49
|
+
add(VARIABLES, :pre_type).
|
50
|
+
add(BASH_VARIABLES, :pre_type)
|
45
51
|
|
46
52
|
def scan_tokens tokens, options
|
47
53
|
|
@@ -68,16 +74,16 @@ module CodeRay::Scanners
|
|
68
74
|
elsif match = scan(/(?:"|`)/)
|
69
75
|
state = :quote
|
70
76
|
quote = match
|
71
|
-
tokens << [match, :plain]
|
72
77
|
tokens << [:open, :string] if quote == '"'
|
73
78
|
tokens << [:open, :shell] if quote == '`'
|
79
|
+
tokens << [match, :delimiter]
|
74
80
|
next
|
75
81
|
elsif match = scan(/'[^']*'/)
|
76
82
|
kind = :string
|
77
83
|
elsif match = scan(/(?: \& | > | < | \| >> | << | >\& )/ox)
|
78
84
|
kind = :bin
|
79
|
-
elsif match = scan(/\d
|
80
|
-
#
|
85
|
+
elsif match = scan(/\d+[\.-](?:\d+[\.-]?)+/)
|
86
|
+
#versions, dates, and hyphen delimited numbers
|
81
87
|
kind = :float
|
82
88
|
elsif match = scan(/\d+\.\d+\s+/)
|
83
89
|
kind = :float
|
@@ -86,12 +92,12 @@ module CodeRay::Scanners
|
|
86
92
|
elsif match = scan(/ (?: \$\(\( | \)\) ) /x)
|
87
93
|
kind = :global_variable
|
88
94
|
elsif match = scan(/ \$\{ [^\}]+ \} /ox)
|
89
|
-
kind = :instance_variable
|
90
95
|
match =~ /\$\{(.*)\}/
|
91
|
-
kind =
|
96
|
+
kind = IDENT_KIND[$1]
|
97
|
+
kind = :instance_variable if kind == :ident
|
92
98
|
elsif match = scan(/ \$\( [^\)]+ \) /ox)
|
93
99
|
kind = :shell
|
94
|
-
elsif match = scan(
|
100
|
+
elsif match = scan(PRE_CONSTANTS)
|
95
101
|
kind = :pre_constant
|
96
102
|
elsif match = scan(/[^\s]*[A-Za-z_][A-Za-z_0-9]*\+?=/)
|
97
103
|
match =~ /(.*?)([A-Za-z_][A-Za-z_0-9]*)(\+?=)/
|
@@ -100,24 +106,23 @@ module CodeRay::Scanners
|
|
100
106
|
op = $3
|
101
107
|
kind = :plain
|
102
108
|
if str.to_s.strip.empty?
|
103
|
-
kind =
|
104
|
-
kind = :
|
105
|
-
#kind = :pre_constant if CONSTANTS.include?(pre)
|
109
|
+
kind = IDENT_KIND[pre]
|
110
|
+
kind = :instance_variable if kind == :ident
|
106
111
|
tokens << [pre, kind]
|
107
112
|
tokens << [op, :operator]
|
108
113
|
next
|
109
114
|
end
|
110
115
|
elsif match = scan(/[A-Za-z_]+\[[A-Za-z_\d]+\]/)
|
111
116
|
# array
|
112
|
-
kind =
|
113
|
-
kind = :
|
117
|
+
kind = IDENT_KIND(match)
|
118
|
+
kind = :instance_variable if kind == :ident
|
114
119
|
elsif match = scan(/ \$[A-Za-z_][A-Za-z_0-9]* /ox)
|
115
|
-
kind = :instance_variable
|
116
120
|
match =~ /\$(.*)/
|
117
|
-
kind =
|
121
|
+
kind = IDENT_KIND[$1]
|
122
|
+
kind = :instance_variable if kind == :ident
|
118
123
|
elsif match = scan(/read \S+/)
|
119
124
|
match =~ /read(\s+)(\S+)/
|
120
|
-
tokens << ['read', :
|
125
|
+
tokens << ['read', :method]
|
121
126
|
tokens << [$1, :space]
|
122
127
|
tokens << [$2, :instance_variable]
|
123
128
|
next
|
@@ -125,13 +130,11 @@ module CodeRay::Scanners
|
|
125
130
|
kind = :reserved
|
126
131
|
elsif match = scan(/ [A-Za-z_][A-Za-z_\d]*;? /x)
|
127
132
|
match =~ /([^;]+);?/
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
134
|
-
kind = :reserved
|
133
|
+
kind = IDENT_KIND[$1]
|
134
|
+
if match[/([^;]+);$/]
|
135
|
+
tokens << [$1, kind]
|
136
|
+
tokens << [';', :delimiter]
|
137
|
+
next
|
135
138
|
end
|
136
139
|
elsif match = scan(/(?: = | - | \+ | \{ | \} | \( | \) | && | \|\| | ;; | ! )/ox)
|
137
140
|
kind = :operator
|
@@ -141,20 +144,25 @@ module CodeRay::Scanners
|
|
141
144
|
kind = :plain
|
142
145
|
elsif match = scan(/.+/)
|
143
146
|
# this shouldn't be :reserved for highlighting bad matches
|
144
|
-
|
145
|
-
|
147
|
+
kind = :error
|
148
|
+
match = ">>>>>#{match}<<<<<"
|
146
149
|
end
|
147
150
|
elsif state == :quote
|
148
|
-
if (match = scan(
|
151
|
+
if (match = scan(/\\.?/))
|
149
152
|
kind = :content
|
150
153
|
elsif match = scan(/#{quote}/)
|
154
|
+
tokens << [match, :delimiter]
|
151
155
|
tokens << [:close, :string] if quote == '"'
|
152
156
|
tokens << [:close, :shell] if quote == "`"
|
153
157
|
quote = nil
|
154
158
|
state = :initial
|
155
|
-
|
156
|
-
|
157
|
-
|
159
|
+
next
|
160
|
+
#kind = :symbol
|
161
|
+
elsif match = scan(PRE_CONSTANTS)
|
162
|
+
kind = :pre_constant
|
163
|
+
elsif match = scan(/ \$\{?[A-Za-z_][A-Za-z_\d]*\}? /x)
|
164
|
+
kind = IDENT_KIND[match]
|
165
|
+
kind = :instance_variable if kind == :ident
|
158
166
|
elsif (quote == '`') and (match = scan(/\$"/))
|
159
167
|
kind = :content
|
160
168
|
elsif (quote == '"') and (match = scan(/\$`/))
|
@@ -163,7 +171,10 @@ module CodeRay::Scanners
|
|
163
171
|
kind = :content
|
164
172
|
else match = scan(/.+/)
|
165
173
|
# this shouldn't be
|
166
|
-
kind = :reserved
|
174
|
+
#kind = :reserved
|
175
|
+
#raise match
|
176
|
+
match = ">>>>>#{match}<<<<<"
|
177
|
+
kind = :error
|
167
178
|
end
|
168
179
|
end
|
169
180
|
|
@@ -176,3 +187,4 @@ module CodeRay::Scanners
|
|
176
187
|
|
177
188
|
end
|
178
189
|
end
|
190
|
+
end
|
data/lib/coderay_bash.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coderay_bash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Petr Kovar
|