yay 0.0.1

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.
@@ -0,0 +1,92 @@
1
+
2
+ class Yay
3
+ # manages colour rules. including variable substitutions
4
+ class RuleSet
5
+
6
+ def initialize
7
+ # the eventual ruleset
8
+ @rules = []
9
+
10
+ # variable = colour
11
+ @var_to_colours = {}
12
+
13
+ # variable = variable
14
+ @var_to_var = {}
15
+
16
+ # string = variable
17
+ @string_to_var = []
18
+ end
19
+
20
+ # merge with another ruleset
21
+ def merge rules
22
+ @rules = @rules | rules
23
+ end
24
+
25
+ def get_rules
26
+ # ensure we substitute all variables
27
+ substitute_variables if @string_to_var
28
+ @rules
29
+ end
30
+
31
+ # add a simple STRING = COLOUR match rule
32
+ def add_match strings, colours, is_line
33
+ strings.each { |string|
34
+ @rules.push [string, colours, is_line]
35
+ }
36
+ end
37
+
38
+ # add a VARIABLE = COLOUR match rule so we can substitute variables later
39
+ def add_substitution variable, colours, is_line
40
+ raise AlreadyAssignedError.new variable if @var_to_colours[variable] || @var_to_var[variable]
41
+ @var_to_colours[variable] = [colours, is_line]
42
+ end
43
+
44
+ # add a STRING = VARIABLE match rule. the variable will be substuted later
45
+ def add_assignment strings, variable
46
+ strings.each { |string|
47
+ @string_to_var.push [string, variable]
48
+ }
49
+ end
50
+
51
+ # add a VARIABLE = VARIABLE equivalence rule. x will be substituted later
52
+ def add_equivalence x, y
53
+ @var_to_var[x] = y
54
+ end
55
+
56
+ # try to find the value of a variable by making substitutions
57
+ def substitute_variable variable
58
+
59
+ path = []
60
+ result = nil
61
+ current = variable
62
+
63
+ while true
64
+ # detect circular references
65
+ raise CircularReferenceError.new(current, path) unless path.index(current).nil?
66
+
67
+ path.push current
68
+
69
+ # see if this variable has a value
70
+ result = @var_to_colours[current]
71
+ break if result
72
+
73
+ # see if this variable is a reference to another variable
74
+ current = @var_to_var[current]
75
+ break if current.nil?
76
+ end
77
+
78
+ raise UnresolvedSubstitutionError.new variable unless result
79
+ return result
80
+ end
81
+
82
+ def substitute_variables
83
+ @string_to_var.each { |ref|
84
+ string = ref[0]
85
+ variable = ref[1]
86
+ result = substitute_variable(variable)
87
+ add_match([string], result[0], result[1])
88
+ }
89
+ @string_to_var = []
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,19 @@
1
+ require 'open3'
2
+
3
+ class Yay
4
+
5
+ VERSION = "0.0.1"
6
+
7
+ def self.version
8
+ @rev ||= begin
9
+ begin
10
+ rev = Open3.popen3("git rev-parse HEAD") {|stdin, stdout, stderr| stdout.read }.strip
11
+ rescue Errno::ENOENT
12
+ rev = ""
13
+ end
14
+ rev.empty? ? nil : " (#{rev})"
15
+ end
16
+ "#{VERSION}#@rev"
17
+ end
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yay
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jon Davey
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-14 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: echo "i like apples" | yay apples are red
23
+ email: jond3k@gmail.com
24
+ executables:
25
+ - yay
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - LICENSE
32
+ - data/lexer_tests.rb
33
+ - data/grammar.y
34
+ - data/examples/regex.yay
35
+ - data/examples/errors.yay
36
+ - data/examples/variables.yay
37
+ - data/defaults/log4x.yay
38
+ - data/defaults/syslog.yay
39
+ - data/defaults/log.yay
40
+ - data/parser_tests.rb
41
+ - lib/yay/parser_gen.rb
42
+ - lib/yay/rule_set.rb
43
+ - lib/yay/version.rb
44
+ - lib/yay/lexer.rb
45
+ - lib/yay/loader.rb
46
+ - lib/yay/application.rb
47
+ - lib/yay/colour_wheel.rb
48
+ - lib/yay/colourizer.rb
49
+ - lib/yay/errors.rb
50
+ - lib/yay/installer.rb
51
+ - lib/yay/lexer_regex.rb
52
+ - lib/yay/parser.rb
53
+ - bin/yay
54
+ has_rdoc: true
55
+ homepage: https://github.com/jond3k/yay
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
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
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.7
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Makes your logs colourful!
88
+ test_files: []
89
+