yay 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -8,7 +8,7 @@ error is @serious
8
8
  fatal is @serious
9
9
 
10
10
  # some words that aren't logger levels but are still important
11
- exception is @serious
11
+ exception is @interesting
12
12
  "unhandled exception" is @serious
13
13
  important is @serious
14
14
 
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/yay
2
2
  # Highlights syslog messages
3
3
 
4
- insensitive
5
-
6
4
  debug is normal
7
5
  informational is gray
8
6
  notice and warning are yellow
@@ -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
- # args that can be used if you don't want the application to do anything
8
- DO_NOTHING_ARGS = ['--do-nothing']
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
- return if @args == DO_NOTHING_ARGS
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
@@ -7,6 +7,14 @@ class Yay
7
7
  @input = input
8
8
  @output = output
9
9
  end
10
+
11
+ def line_rules
12
+ @line_rules
13
+ end
14
+
15
+ def part_rules
16
+ @part_rules
17
+ end
10
18
 
11
19
  def colourize_rules rules
12
20
  @line_rules = []
@@ -3,8 +3,8 @@ require 'yay/colour_wheel'
3
3
  class Yay
4
4
  class Lexer
5
5
 
6
- # The expressions to match to find tokens
7
- # Ensure the labels match up to tokens in grammar.y
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]*(?:x.[^\/x\r\n]*)*\/[a-z]*/],
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
@@ -2,7 +2,7 @@ require 'open3'
2
2
 
3
3
  class Yay
4
4
 
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.3"
6
6
 
7
7
  def self.version
8
8
  @rev ||= begin
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
- - Jon Davey
13
+ - jon davey
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-14 00:00:00 +00:00
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/lexer_tests.rb
33
- - data/parser_tests.rb
34
- - data/examples/errors.yay
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: Makes your logs colourful!
81
+ summary: makes your logs colourful!
89
82
  test_files: []
90
83