trace_preprocessor 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7ccca5ae4fcb661f3cd3ef939dcb86ebbef8979
4
- data.tar.gz: ef3cf0c60f0212ef31be2af54d9881665cee3807
3
+ metadata.gz: 547c48b671c56cb45f18b5c4bf9aae7c493a1da3
4
+ data.tar.gz: 62b8de7da7d11076967baf68cd4059ab9c0b9668
5
5
  SHA512:
6
- metadata.gz: 60a004409355051161ec314ddadfcb1a4a09d96418439b328431a4affd0fb7f0b0c8ffea039dbb34376ce57f784cf252ef8eb390ff59925a8f88dd0800dd704a
7
- data.tar.gz: b27ef4e4e1dcb15c30a1664d877418c48378552e691f172503fbf090b1f94631b0c2895ddc0cef51cac7b9f7704b39c6cacd69cbef450b28719a81ce50af8299
6
+ metadata.gz: 9f82fbcd4855ec30ec07340bbbcffeed621eb199c7fa0e171d5c3028e41b74ac19775a091e32c8830eb893189eafba492181cc051da4851ef83a1ff21b0fe098
7
+ data.tar.gz: ace8baf7e21c3c13c5e6f60b68349e97b5bfaf04ce1642111ff82877256d749f609e76b783e155e75c617c31899df90a973b91f256e3bdd8af2dad479be84623
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TracePreprocessor
2
2
 
3
- TODO: Write a gem description
3
+ Simple trace preprocess based on lexical analyzer
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,12 +18,27 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ #!/usr/bin/env ruby
22
+
23
+ require 'trace_preprocessor'
24
+
25
+ # Configuration
26
+ config = TracePreprocessor.init do
27
+ define_lexeme :id,
28
+ :regexp => /[0-9]+/,
29
+ :converter => "return atol(yytext);",
30
+ :value_kind => :exact,
31
+ :priority => 1
32
+
33
+ output_token "printf(\"{TOKEN;%s;%s;%ld;%d}\", name, source, value, value_kind);"
34
+
35
+ workspace "~/.trace_preprocessor"
36
+ end
37
+
38
+ # Generate preprocessor
39
+ preprocessor = TracePreprocessor.generate(config, :c)
40
+
41
+ # Preprocessor run
42
+ preprocessor.run("input.txt", "output.txt")
22
43
 
23
- ## Contributing
24
44
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
@@ -41,9 +41,12 @@ LEX
41
41
  def self.regexps dsl
42
42
  result = ""
43
43
 
44
- dsl.lexemes.each do |name, lexeme|
44
+ a = dsl.lexemes.values
45
+ a.sort! { |x, y| x.priority <=> y.priority }
46
+
47
+ a.each do |lexeme|
45
48
  if lexeme.regexp
46
- result += "#{lexeme.regexp.source} parse_#{name}();\n"
49
+ result += "#{lexeme.regexp.source} parse_#{lexeme.name}();\n"
47
50
  end
48
51
  end
49
52
 
@@ -18,10 +18,7 @@ module TracePreprocessor
18
18
  end
19
19
 
20
20
  def define_lexeme name, options
21
- lexeme = @lexemes[name] || Lexeme.new(name)
22
-
23
- lexeme.regexp = options[:regexp]
24
- lexeme.value_kind = options[:value_kind] || :hash
21
+ lexeme = @lexemes[name] || Lexeme.new(name, options)
25
22
 
26
23
  converter = options[:converter]
27
24
  converter_language = :c
@@ -1,8 +1,12 @@
1
1
  module TracePreprocessor
2
2
  class Lexeme
3
- def initialize name
3
+ def initialize name, options
4
4
  @name = name
5
5
  @converter = {}
6
+
7
+ @regexp = options[:regexp]
8
+ @priority = options[:priority]
9
+ @value_kind = options[:value_kind] || :hash
6
10
  end
7
11
 
8
12
  attr_accessor :name, :regexp, :converter, :value_kind, :priority
@@ -1,3 +1,3 @@
1
1
  module TracePreprocessor
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,50 @@
1
+ require 'trace_preprocessor'
2
+
3
+ include TracePreprocessor
4
+
5
+ describe Preprocessor do
6
+ it "priority test" do
7
+
8
+ config = TracePreprocessor.init do
9
+ output_token "printf(\"%ld\", value);"
10
+ workspace "~/.trace_preprocessor"
11
+
12
+ define_lexeme :id1,
13
+ :regexp => /[0-9]+/,
14
+ :converter => "return atol(yytext);",
15
+ :value_kind => :exact,
16
+ :priority => 2
17
+
18
+ define_lexeme :id2,
19
+ :regexp => /[0-9]+/,
20
+ :converter => "return -atol(yytext);",
21
+ :value_kind => :exact,
22
+ :priority => 1
23
+
24
+
25
+ define_lexeme :id3,
26
+ :regexp => /[0-9]+/,
27
+ :converter => "return atol(yytext);",
28
+ :value_kind => :exact,
29
+ :priority => 3
30
+
31
+ end
32
+
33
+ preprocessor = TracePreprocessor.generate(config, :c)
34
+
35
+ input = config.workspace_path + "/preprocessor_spec-in.txt"
36
+ output = config.workspace_path + "/preprocessor_spec-out.txt"
37
+
38
+ puts "input = #{input}"
39
+ puts "output = #{output}"
40
+
41
+ open(input, "w") { |fd| fd.write "123456" }
42
+
43
+ preprocessor.run(input, output)
44
+
45
+ result = open(output, "r") { |fd| fd.read }
46
+
47
+ result.should eq "-123456"
48
+
49
+ end
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trace_preprocessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-27 00:00:00.000000000 Z
11
+ date: 2013-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,6 +57,7 @@ files:
57
57
  - lib/trace_preprocessor/preprocessor.rb
58
58
  - lib/trace_preprocessor/version.rb
59
59
  - spec/dsl_spec.rb
60
+ - spec/preprocessor_spec.rb
60
61
  - trace_preprocessor.gemspec
61
62
  homepage: ''
62
63
  licenses:
@@ -84,3 +85,4 @@ specification_version: 4
84
85
  summary: Log data preprocessor
85
86
  test_files:
86
87
  - spec/dsl_spec.rb
88
+ - spec/preprocessor_spec.rb