edn_turbo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e737afa166083d5aaa0de28d796cc0600328efa7
4
+ data.tar.gz: ea373f461fa3ab36984fda13032c807eb44a26d4
5
+ SHA512:
6
+ metadata.gz: 06a184edd65e207c593e473078106c4727bfb7aea7e5df1373a37ab28c468ac9f19b04ddafaf9b5ae2b97196d29d25dbb957038d9fb22f24201eacd922567ba3
7
+ data.tar.gz: 0d8af5293af6611246bf36fbbe2b06c157ca2c248fc2f2f546d4077fea45761e2cb4ce0d63fa0c218d906a33a5ec2f75007b27cbfe5ac3422cb1073d7ef2b579
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ Makefile
2
+ *.so
3
+ *.bundle
4
+ tmp/*
5
+ .DS_Store
6
+ *.sublime-*
7
+ *.gem
8
+ *~
9
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in edn_ext.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ edn_ext
2
+ ============
3
+
4
+ Ruby C-extension for EDN file parser
5
+
6
+ Dependencies
7
+ ============
8
+
9
+ Minimum required versions shown of the following:
10
+ - ruby gems:
11
+ - [rake 10.3.2](http://rake.rubyforge.org)
12
+ - [rake-compiler 0.9.2](http://rake-compiler.rubyforge.org)
13
+ - [rice 1.7.0](http://rice.rubyforge.org)
14
+
15
+ Setup
16
+ =====
17
+
18
+ - Install gem dependencies:
19
+
20
+ ```
21
+ gem install rake rake-compiler rice
22
+ ```
23
+
24
+ Usage
25
+ =====
26
+ ```ruby
27
+ require 'edn_ext'
28
+
29
+ pp EDN_EXT.read("some_file.edn")
30
+ ```
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rake/testtask'
2
+ require 'rake/extensiontask'
3
+ require 'rake/clean'
4
+ require 'rbconfig'
5
+
6
+ NAME = 'edn_turbo'
7
+ LIB_DIR = "lib/#{NAME}"
8
+ EXT_BUNDLE = "#{LIB_DIR}/#{NAME}.#{RbConfig::CONFIG['DLEXT']}"
9
+
10
+
11
+ EXT_PATH = "ext/#{NAME}"
12
+ RAGEL_PARSER_SRC = "edn_parser.rl"
13
+ RAGEL_PARSER_SRC_PATH = "#{EXT_PATH}/#{RAGEL_PARSER_SRC}"
14
+ GEN_CC_PARSER_SRC = "edn_parser.cc"
15
+ GEN_CC_PARSER_SRC_PATH = "#{EXT_PATH}/#{GEN_CC_PARSER_SRC}"
16
+
17
+ Rake::ExtensionTask.new("#{NAME}") do |extension|
18
+ extension.lib_dir = LIB_DIR
19
+ extension.source_pattern = "*.{cc,h}"
20
+ end
21
+
22
+ task :chmod do
23
+ File.chmod(0775, EXT_BUNDLE)
24
+ end
25
+
26
+ task :ragel => GEN_CC_PARSER_SRC_PATH
27
+
28
+
29
+ file GEN_CC_PARSER_SRC_PATH => RAGEL_PARSER_SRC_PATH do
30
+ cd EXT_PATH do
31
+ sh "ragel -G2 -o #{GEN_CC_PARSER_SRC} #{RAGEL_PARSER_SRC}"
32
+ src = File.read(GEN_CC_PARSER_SRC).gsub(/[ \t]+$/, '')
33
+ File.open(GEN_CC_PARSER_SRC, "w") {|f| f.print src}
34
+ end
35
+ end
36
+
37
+ task :build => [:clean, :ragel, :compile, :chmod]
38
+
39
+ # add dependency to test task
40
+ task :test => EXT_BUNDLE
41
+
42
+ Rake::TestTask.new do |t|
43
+ t.libs << 'test'
44
+ t.test_files = FileList['test/test_output_diff.rb']
45
+ end
46
+
47
+ task :default => :compile
data/bin/edn-ruby-read ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'edn'
5
+
6
+ if ARGV.size == 0
7
+ $stderr.puts "no filename given"
8
+ exit 1
9
+ end
10
+
11
+ # file checks
12
+ filename = ARGV[0]
13
+ if !File.exist? filename
14
+ $stderr.puts "Error opening #{filename}"
15
+ abort
16
+ end
17
+
18
+ # read the file
19
+ doc_data = {}
20
+ begin
21
+ File.open(filename) do |file|
22
+ doc_data = EDN.read(file)
23
+ end
24
+ rescue Exception => e
25
+ $stderr.puts "Error reading file"
26
+ abort
27
+ end
data/bin/ppedn ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ $LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' )
5
+
6
+ require 'optparse'
7
+ require 'edn_turbo'
8
+ require 'pp'
9
+
10
+ options = {}
11
+ optparse = OptionParser.new do |opts|
12
+ opts.banner = "Usage: #{$0} [options] filename"
13
+
14
+ opts.on( '-v', '--version', 'Display version information and exit' ) do
15
+ $stderr.puts "EDN parsing C++-extension version #{EDNt::VERSION}"
16
+ exit
17
+ end
18
+
19
+ opts.on( '-h', '--help', 'Display this screen' ) do
20
+ $stderr.puts opts
21
+ exit
22
+ end
23
+ end
24
+ optparse.parse!
25
+
26
+ if ARGV.size == 0
27
+ $stderr.puts optparse
28
+ exit 1
29
+ end
30
+
31
+ filename = ARGV[0]
32
+ if !File.exist? filename
33
+ $stderr.puts "Path '#{filename}' not valid"
34
+ exit 1
35
+ end
36
+
37
+ # mimic edn-ruby usage
38
+ File.open(filename) do |file|
39
+ output = EDNT.read(file)
40
+ pp output if output != nil
41
+ end