trace_preprocessor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/trace_preprocessor/code_generator.rb +74 -0
- data/lib/trace_preprocessor/dsl.rb +56 -0
- data/lib/trace_preprocessor/lexeme.rb +10 -0
- data/lib/trace_preprocessor/preprocessor.rb +17 -0
- data/lib/trace_preprocessor/version.rb +3 -0
- data/lib/trace_preprocessor.rb +33 -0
- data/spec/dsl_spec.rb +62 -0
- data/trace_preprocessor.gemspec +23 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7ccca5ae4fcb661f3cd3ef939dcb86ebbef8979
|
4
|
+
data.tar.gz: ef3cf0c60f0212ef31be2af54d9881665cee3807
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60a004409355051161ec314ddadfcb1a4a09d96418439b328431a4affd0fb7f0b0c8ffea039dbb34376ce57f784cf252ef8eb390ff59925a8f88dd0800dd704a
|
7
|
+
data.tar.gz: b27ef4e4e1dcb15c30a1664d877418c48378552e691f172503fbf090b1f94631b0c2895ddc0cef51cac7b9f7704b39c6cacd69cbef450b28719a81ce50af8299
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sergey A
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# TracePreprocessor
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'trace_preprocessor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install trace_preprocessor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
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
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module TracePreprocessor
|
2
|
+
module CodeGenerator
|
3
|
+
|
4
|
+
def self.generate_lex dsl
|
5
|
+
template =
|
6
|
+
<<-LEX
|
7
|
+
%{
|
8
|
+
COMMON_CODE
|
9
|
+
|
10
|
+
CONVERTER_FUNCTIONS
|
11
|
+
%}
|
12
|
+
|
13
|
+
%option nounput
|
14
|
+
|
15
|
+
%%
|
16
|
+
|
17
|
+
REGEXPS
|
18
|
+
|
19
|
+
%%
|
20
|
+
LEX
|
21
|
+
|
22
|
+
template.gsub!("COMMON_CODE", dsl.code)
|
23
|
+
template.gsub!("CONVERTER_FUNCTIONS", converter_functions_c_code(dsl))
|
24
|
+
template.gsub!("REGEXPS", regexps(dsl))
|
25
|
+
|
26
|
+
template
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.converter_functions_c_code dsl
|
30
|
+
result = output_token_code dsl
|
31
|
+
|
32
|
+
dsl.lexemes.each do |name, lexeme|
|
33
|
+
if lexeme.converter[:c]
|
34
|
+
result += parse_lexeme_code(name, lexeme)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.regexps dsl
|
42
|
+
result = ""
|
43
|
+
|
44
|
+
dsl.lexemes.each do |name, lexeme|
|
45
|
+
if lexeme.regexp
|
46
|
+
result += "#{lexeme.regexp.source} parse_#{name}();\n"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
result
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.output_token_code dsl
|
54
|
+
<<-CODE
|
55
|
+
void output_token(const char* name, const char* source, long value, int value_kind) {
|
56
|
+
#{dsl.output_token_code}
|
57
|
+
}
|
58
|
+
CODE
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.parse_lexeme_code(name, lexeme)
|
62
|
+
<<-CODE
|
63
|
+
long converter_#{name}() {
|
64
|
+
#{lexeme.converter[:c]}
|
65
|
+
}
|
66
|
+
|
67
|
+
void parse_#{name}() {
|
68
|
+
output_token("#{name}", yytext, converter_#{name}(), #{lexeme.value_kind == :exact ? 1 : 0});
|
69
|
+
}
|
70
|
+
CODE
|
71
|
+
end
|
72
|
+
|
73
|
+
end # CodeGenerator
|
74
|
+
end # TracePreprocessor
|
@@ -0,0 +1,56 @@
|
|
1
|
+
%w(
|
2
|
+
lexeme
|
3
|
+
).each do |file|
|
4
|
+
require File.join(File.dirname(__FILE__), file)
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
module TracePreprocessor
|
10
|
+
class DSL
|
11
|
+
def initialize
|
12
|
+
@lexemes = {}
|
13
|
+
@code = ""
|
14
|
+
end
|
15
|
+
|
16
|
+
def init &block
|
17
|
+
instance_eval &block
|
18
|
+
end
|
19
|
+
|
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
|
25
|
+
|
26
|
+
converter = options[:converter]
|
27
|
+
converter_language = :c
|
28
|
+
converter_language = :ruby if converter.instance_of? Proc
|
29
|
+
lexeme.converter[converter_language] = converter
|
30
|
+
|
31
|
+
@lexemes[lexeme.name] = lexeme
|
32
|
+
|
33
|
+
lexeme
|
34
|
+
end
|
35
|
+
|
36
|
+
def common_code code
|
37
|
+
@code += code
|
38
|
+
end
|
39
|
+
|
40
|
+
def output_token code
|
41
|
+
@output_token_code = code
|
42
|
+
end
|
43
|
+
|
44
|
+
def workspace path
|
45
|
+
@workspace_path = File.expand_path path
|
46
|
+
|
47
|
+
if not File.exist? @workspace_path
|
48
|
+
FileUtils.mkdir_p @workspace_path
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
attr_accessor :lexemes
|
53
|
+
attr_accessor :code, :output_token_code
|
54
|
+
attr_accessor :workspace_path
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TracePreprocessor
|
2
|
+
class Preprocessor
|
3
|
+
attr_accessor :language
|
4
|
+
attr_accessor :preprocessor_file_name
|
5
|
+
|
6
|
+
def initialize language, preprocessor_file_name
|
7
|
+
@language = language
|
8
|
+
@preprocessor_file_name = preprocessor_file_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def run input_file_name, output_file_name
|
12
|
+
if @language == :c
|
13
|
+
`#{preprocessor_file_name} < #{input_file_name} > #{output_file_name}`
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
%w(
|
2
|
+
version
|
3
|
+
dsl
|
4
|
+
code_generator
|
5
|
+
preprocessor
|
6
|
+
).each do |file|
|
7
|
+
require File.join(File.dirname(__FILE__), 'trace_preprocessor', file)
|
8
|
+
end
|
9
|
+
|
10
|
+
include TracePreprocessor
|
11
|
+
|
12
|
+
module TracePreprocessor
|
13
|
+
|
14
|
+
def self.init &block
|
15
|
+
dsl = DSL.new
|
16
|
+
dsl.init &block
|
17
|
+
dsl
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.generate config, language
|
21
|
+
if language == :c
|
22
|
+
lex = CodeGenerator.generate_lex config
|
23
|
+
|
24
|
+
open(config.workspace_path + "/preprocessor.l", "w") { |fd| fd.write lex }
|
25
|
+
|
26
|
+
`cd #{config.workspace_path}; flex -o preprocessor.c preprocessor.l; gcc -o preprocessor -ll preprocessor.c`
|
27
|
+
|
28
|
+
Preprocessor.new(:c, config.workspace_path + "/preprocessor")
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/spec/dsl_spec.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'trace_preprocessor'
|
2
|
+
|
3
|
+
include TracePreprocessor
|
4
|
+
|
5
|
+
describe DSL do
|
6
|
+
it "smoke test for initialize DSL object" do
|
7
|
+
dsl = DSL.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "init with simple form of define_lexeme (default values)" do
|
11
|
+
dsl = DSL.new
|
12
|
+
|
13
|
+
lexeme = dsl.define_lexeme :id, :regexp => /[0-9]+/
|
14
|
+
lexeme.name.should eq :id
|
15
|
+
lexeme.value_kind.should eq :hash
|
16
|
+
end
|
17
|
+
|
18
|
+
it "converter in C" do
|
19
|
+
dsl = DSL.new
|
20
|
+
|
21
|
+
dsl.init do
|
22
|
+
define_lexeme :id,
|
23
|
+
:regexp => /[0-9]+/,
|
24
|
+
:converter => "return atol(str);",
|
25
|
+
:priority => 1,
|
26
|
+
:value_kind => :exact
|
27
|
+
end
|
28
|
+
|
29
|
+
dsl.lexemes.length.should eq 1
|
30
|
+
|
31
|
+
lexeme = dsl.lexemes[:id]
|
32
|
+
lexeme.regexp.should eq /[0-9]+/
|
33
|
+
lexeme.value_kind.should eq :exact
|
34
|
+
lexeme.converter.length.should eq 1
|
35
|
+
lexeme.converter[:c].should_not be_nil
|
36
|
+
lexeme.converter[:ruby].should be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "converter in Ruby" do
|
40
|
+
dsl = DSL.new
|
41
|
+
|
42
|
+
dsl.init do
|
43
|
+
define_lexeme :id,
|
44
|
+
:regexp => /[0-9]+/,
|
45
|
+
:converter => lambda { |str| str.to_i },
|
46
|
+
:value_kind => :hash
|
47
|
+
end
|
48
|
+
|
49
|
+
dsl.lexemes[:id].converter[:ruby].should_not be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "common code" do
|
53
|
+
dsl = DSL.new
|
54
|
+
|
55
|
+
dsl.init do
|
56
|
+
common_code <<-CODE
|
57
|
+
#include <stdio.h>
|
58
|
+
#include <stdlib.h>
|
59
|
+
CODE
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trace_preprocessor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "trace_preprocessor"
|
8
|
+
spec.version = TracePreprocessor::VERSION
|
9
|
+
spec.authors = ["Sergey"]
|
10
|
+
spec.email = ["mastedm@gmail.com"]
|
11
|
+
spec.description = %q{Log data preprocessor}
|
12
|
+
spec.summary = %q{Log data preprocessor}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trace_preprocessor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Log data preprocessor
|
42
|
+
email:
|
43
|
+
- mastedm@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/trace_preprocessor.rb
|
54
|
+
- lib/trace_preprocessor/code_generator.rb
|
55
|
+
- lib/trace_preprocessor/dsl.rb
|
56
|
+
- lib/trace_preprocessor/lexeme.rb
|
57
|
+
- lib/trace_preprocessor/preprocessor.rb
|
58
|
+
- lib/trace_preprocessor/version.rb
|
59
|
+
- spec/dsl_spec.rb
|
60
|
+
- trace_preprocessor.gemspec
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Log data preprocessor
|
85
|
+
test_files:
|
86
|
+
- spec/dsl_spec.rb
|