yay 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/data/{defaults/log.yay → yay/default.yay} +0 -0
- data/data/{defaults → yay}/log4x.yay +1 -1
- data/data/{defaults → yay}/syslog.yay +0 -2
- data/lib/yay/application.rb +41 -3
- data/lib/yay/colourizer.rb +8 -0
- data/lib/yay/lexer_regex.rb +3 -3
- data/lib/yay/parser.rb +29 -2
- data/lib/yay/version.rb +1 -1
- metadata +9 -16
- data/data/defaults/174.txt.utf8 +0 -8903
- data/data/examples/errors.yay +0 -6
- data/data/examples/regex.yay +0 -24
- data/data/examples/variables.yay +0 -11
- data/data/grammar.y +0 -56
- data/data/lexer_tests.rb +0 -171
- data/data/parser_tests.rb +0 -153
File without changes
|
data/lib/yay/application.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
require 'yay/parser'
|
2
2
|
require 'yay/colourizer'
|
3
|
+
require 'yay/version'
|
3
4
|
|
4
5
|
class Yay
|
5
6
|
class Application
|
6
7
|
|
7
|
-
#
|
8
|
-
|
8
|
+
# arg that can be used if you don't want the application to do anything
|
9
|
+
DO_NOTHING_ARG = '--do-nothing'
|
10
|
+
|
11
|
+
# arg that can be used if you want to dump the rules instead of using them
|
12
|
+
DUMP_RULES_ARG = '--dump'
|
13
|
+
|
14
|
+
# arg that can be used to dump the version and exit
|
15
|
+
SHOW_VERSION_ARG = '--version'
|
9
16
|
|
10
17
|
def initialize(input, output, error, args)
|
11
18
|
raise ArgumentError, "input" unless input.kind_of? IO
|
@@ -24,7 +31,17 @@ class Yay
|
|
24
31
|
raise "already running" if @running
|
25
32
|
@running = true
|
26
33
|
|
27
|
-
|
34
|
+
preArg = @args[0]
|
35
|
+
@args.shift if preArg == DO_NOTHING_ARG ||
|
36
|
+
preArg == DUMP_RULES_ARG ||
|
37
|
+
preArg == SHOW_VERSION_ARG
|
38
|
+
|
39
|
+
if preArg == SHOW_VERSION_ARG
|
40
|
+
puts Yay::version
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
return if preArg == DO_NOTHING_ARG
|
28
45
|
|
29
46
|
begin
|
30
47
|
|
@@ -33,12 +50,33 @@ class Yay
|
|
33
50
|
@rules = @parser.get_rules
|
34
51
|
|
35
52
|
@colourizer = Yay::Colourizer.new @rules, @input, @output
|
53
|
+
|
54
|
+
if preArg == DUMP_RULES_ARG
|
55
|
+
dump_colours @colourizer.line_rules, @colourizer.part_rules
|
56
|
+
return
|
57
|
+
end
|
58
|
+
|
36
59
|
@colourizer.colourize_pipe
|
37
60
|
rescue Yay::Error => error
|
38
61
|
@error.puts error.printable_message
|
39
62
|
rescue Interrupt
|
40
63
|
end
|
41
64
|
end
|
65
|
+
|
66
|
+
def dump_colours line_rules, word_rules
|
67
|
+
|
68
|
+
puts "line rules:" if line_rules
|
69
|
+
|
70
|
+
line_rules.each { |rule|
|
71
|
+
puts "#{rule[0]} => #{rule[1].dump}"
|
72
|
+
}
|
73
|
+
|
74
|
+
puts "word rules:" if word_rules
|
75
|
+
|
76
|
+
word_rules.each { |rule|
|
77
|
+
puts "#{rule[0]} => #{rule[1].dump}"
|
78
|
+
}
|
79
|
+
end
|
42
80
|
|
43
81
|
end
|
44
82
|
end
|
data/lib/yay/colourizer.rb
CHANGED
data/lib/yay/lexer_regex.rb
CHANGED
@@ -3,8 +3,8 @@ require 'yay/colour_wheel'
|
|
3
3
|
class Yay
|
4
4
|
class Lexer
|
5
5
|
|
6
|
-
#
|
7
|
-
#
|
6
|
+
# the expressions to match to find tokens
|
7
|
+
# ensure the labels match up to tokens in grammar.y
|
8
8
|
BASE_PATTERNS = [
|
9
9
|
[:whitespace , /\s+/],
|
10
10
|
[:comment , /#.*$/],
|
@@ -12,7 +12,7 @@ class Yay
|
|
12
12
|
# strings
|
13
13
|
[:double_quoted , /"[^"\\]*(?:\\.[^"\\]*)*"/],
|
14
14
|
[:single_quoted , /'[^'\\]*(?:\\.[^'\\]*)*'/],
|
15
|
-
[:regex , /\/[^\/\\\r\n]*(
|
15
|
+
[:regex , /\/[^\/\\\r\n]*(?:\\.[^\/\\\r\n]*)*\/(?:[a-z]*\b)?/],
|
16
16
|
[:variable , /@\w+/],
|
17
17
|
|
18
18
|
# keywords
|
data/lib/yay/parser.rb
CHANGED
@@ -25,13 +25,40 @@ class Yay
|
|
25
25
|
|
26
26
|
def handle_string string
|
27
27
|
string = Regexp::escape(string)
|
28
|
-
Regexp.new(string, Regexp::IGNORECASE)
|
28
|
+
return Regexp.new(string, Regexp::IGNORECASE)
|
29
29
|
end
|
30
30
|
|
31
31
|
def handle_regex string
|
32
|
-
string
|
32
|
+
return string_to_regex string
|
33
33
|
end
|
34
34
|
|
35
|
+
# for lack of a better function, this will take the ending sequence from
|
36
|
+
# a regular expression and convert it in to a bytewise options variable
|
37
|
+
def extract_regexp_options args
|
38
|
+
return 0 if args.nil?
|
39
|
+
raise ArgumentError unless args.kind_of? String
|
40
|
+
options_map = {
|
41
|
+
'i' => Regexp::IGNORECASE,
|
42
|
+
'm' => Regexp::MULTILINE,
|
43
|
+
'x' => Regexp::EXTENDED,
|
44
|
+
}
|
45
|
+
options = 0
|
46
|
+
args.each { |char|
|
47
|
+
options |= options_map[char] || 0
|
48
|
+
}
|
49
|
+
return options
|
50
|
+
end
|
51
|
+
|
52
|
+
# for lack of a better function, this will take a string like "/abc/" and
|
53
|
+
# transform it in to a regex object
|
54
|
+
def string_to_regex string
|
55
|
+
matches = /\/([^\/\\\r\n]*(?:\\.[^\/\\\r\n]*)*)\/([a-z]\b)*/.match string
|
56
|
+
return nil if matches[1].nil?
|
57
|
+
content = Regexp::escape(matches[1])
|
58
|
+
options = extract_regexp_options matches[2]
|
59
|
+
return Regexp.new(content, options)
|
60
|
+
end
|
61
|
+
|
35
62
|
# given an array of colour strings, create an array with the VT100 colour
|
36
63
|
# sequences inside
|
37
64
|
def handle_colours colours
|
data/lib/yay/version.rb
CHANGED
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
-
|
13
|
+
- jon davey
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-15 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -29,16 +29,9 @@ extra_rdoc_files: []
|
|
29
29
|
|
30
30
|
files:
|
31
31
|
- LICENSE
|
32
|
-
- data/
|
33
|
-
- data/
|
34
|
-
- data/
|
35
|
-
- data/examples/variables.yay
|
36
|
-
- data/examples/regex.yay
|
37
|
-
- data/grammar.y
|
38
|
-
- data/defaults/log4x.yay
|
39
|
-
- data/defaults/174.txt.utf8
|
40
|
-
- data/defaults/syslog.yay
|
41
|
-
- data/defaults/log.yay
|
32
|
+
- data/yay/default.yay
|
33
|
+
- data/yay/log4x.yay
|
34
|
+
- data/yay/syslog.yay
|
42
35
|
- lib/yay/colourizer.rb
|
43
36
|
- lib/yay/application.rb
|
44
37
|
- lib/yay/version.rb
|
@@ -85,6 +78,6 @@ rubyforge_project:
|
|
85
78
|
rubygems_version: 1.3.7
|
86
79
|
signing_key:
|
87
80
|
specification_version: 3
|
88
|
-
summary:
|
81
|
+
summary: makes your logs colourful!
|
89
82
|
test_files: []
|
90
83
|
|