vernacular 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/vernacular.rb +41 -5
- data/lib/vernacular/source_file.rb +3 -6
- data/lib/vernacular/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be3b65d96dd405422c5d5723be0aea18e1aca5c8
|
4
|
+
data.tar.gz: 3f70cac82ad0ce35054d2b3289b4dc612b0da9a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a640f138ed4496de8f88f13a2c9e7820c6a92ce2ebbc7e5a1e153a17fbe302c841e934bd6cc2969b3c3a9a577b74aa5e3cfd1881fbe1a94c951f40a3e8f37132
|
7
|
+
data.tar.gz: 7f66305aabfacb753d8b79fc20d9a07647546063964aa330c02fa2653b56c008214f284588c70d58ba7d93b65b07409c94a7e358600b67de97025538d7cb0a02
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Vernacular
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/kddeisz/vernacular.svg?branch=master)](https://travis-ci.org/kddeisz/vernacular)
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/vernacular.svg)](https://rubygems.org/gems/vernacular)
|
4
5
|
|
5
6
|
Allows extending ruby's syntax and compilation process.
|
6
7
|
|
data/lib/vernacular.rb
CHANGED
@@ -16,16 +16,32 @@ end
|
|
16
16
|
|
17
17
|
# Allows extending ruby's syntax and compilation process
|
18
18
|
module Vernacular
|
19
|
+
PARSER_PATH = File.expand_path('vernacular/parser.rb', __dir__).freeze
|
20
|
+
|
19
21
|
# Module that gets included into `RubyVM::InstructionSequence` in order to
|
20
22
|
# hook into the require process.
|
21
23
|
module InstructionSequenceMixin
|
22
|
-
PARSER_PATH = File.expand_path('vernacular/parser.rb', __dir__).freeze
|
23
|
-
|
24
24
|
def load_iseq(filepath)
|
25
25
|
::Vernacular::SourceFile.load_iseq(filepath) if filepath != PARSER_PATH
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
# Module that gets included into `Bootsnap::CompileCache::ISeq` in order to
|
30
|
+
# hook into the bootsnap compilation process.
|
31
|
+
module BootsnapMixin
|
32
|
+
def input_to_storage(contents, filepath)
|
33
|
+
if filepath == PARSER_PATH
|
34
|
+
raise ::Bootsnap::CompileCache::Uncompilable, "can't compile parser"
|
35
|
+
end
|
36
|
+
|
37
|
+
contents = ::Vernacular.modify(contents)
|
38
|
+
iseq = RubyVM::InstructionSequence.compile(contents, filepath, filepath)
|
39
|
+
iseq.to_binary
|
40
|
+
rescue SyntaxError
|
41
|
+
raise ::Bootsnap::CompileCache::Uncompilable, 'syntax error'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
29
45
|
class << self
|
30
46
|
attr_reader :iseq_dir, :modifiers
|
31
47
|
|
@@ -45,9 +61,7 @@ module Vernacular
|
|
45
61
|
@iseq_dir = File.expand_path(File.join('../.iseq', hash), __dir__)
|
46
62
|
FileUtils.mkdir_p(iseq_dir) unless File.directory?(iseq_dir)
|
47
63
|
|
48
|
-
|
49
|
-
prepend ::Vernacular::InstructionSequenceMixin
|
50
|
-
end
|
64
|
+
install
|
51
65
|
end
|
52
66
|
|
53
67
|
# Use every available pre-configured modifier
|
@@ -56,9 +70,31 @@ module Vernacular
|
|
56
70
|
Modifiers.constants.map { |constant| Modifiers.const_get(constant).new }
|
57
71
|
end
|
58
72
|
|
73
|
+
def modify(source)
|
74
|
+
modifiers.each do |modifier|
|
75
|
+
source = modifier.modify(source)
|
76
|
+
end
|
77
|
+
source
|
78
|
+
end
|
79
|
+
|
59
80
|
def iseq_path_for(source_path)
|
60
81
|
source_path.gsub(/[^A-Za-z0-9\._-]/) { |c| '%02x' % c.ord }
|
61
82
|
.gsub('.rb', '.yarb')
|
62
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def install
|
88
|
+
@installed ||=
|
89
|
+
if defined?(Bootsnap)
|
90
|
+
class << Bootsnap::CompileCache::ISeq
|
91
|
+
prepend ::Vernacular::BootsnapMixin
|
92
|
+
end
|
93
|
+
else
|
94
|
+
class << RubyVM::InstructionSequence
|
95
|
+
prepend ::Vernacular::InstructionSequenceMixin
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
63
99
|
end
|
64
100
|
end
|
@@ -10,12 +10,9 @@ module Vernacular
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def dump
|
13
|
-
source = File.read(source_path)
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
iseq = RubyVM::InstructionSequence.compile(source)
|
13
|
+
source = Vernacular.modify(File.read(source_path))
|
14
|
+
iseq = RubyVM::InstructionSequence.compile(source, source_path,
|
15
|
+
source_path)
|
19
16
|
digest = ::Digest::MD5.file(source_path).digest
|
20
17
|
File.binwrite(iseq_path, iseq.to_binary("MD5:#{digest}"))
|
21
18
|
iseq
|
data/lib/vernacular/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vernacular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|