storable 0.8.6 → 0.9.pre.RC2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/{README.rdoc → README.md} +38 -37
- data/Rakefile +12 -65
- data/lib/core_ext.rb +273 -0
- data/lib/proc_source.rb +176 -67
- data/lib/storable.rb +57 -33
- data/storable.gemspec +22 -38
- metadata +36 -59
- data/CHANGES.txt +0 -156
- data/LICENSE.txt +0 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1fe040169d9300d29f3a00c5e46e74580a6f5a124b6dabda16ad3a8132d5a6eb
|
4
|
+
data.tar.gz: 24de9dc3bf471ef05c6aad494482925131f0b00d3a4f3dff5f478eec4b655dee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fdaa8dc26da7cf8163dcb1d5d6249a894816445fdf0309bff690e0fc70cc13b637bf3d9ae0557d5eec2a6cabe32986b318a683b3529b0fdee466b733e1c11afb
|
7
|
+
data.tar.gz: 363d57e409178dac08aac9809768d6a1cfb7e4bccf2056be267da51718cc505219eb5a182a41cb3b87be2d5b4d569506dbbe473ee082e4ce8c3162f9cd9ccda7
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,76 +1,76 @@
|
|
1
|
-
|
1
|
+
# Storable - v0.9-RC2
|
2
2
|
|
3
|
-
Marshal Ruby classes
|
3
|
+
Marshal Ruby classes in to and out of multiple formats (yaml, json, csv, tsv).
|
4
|
+
|
5
|
+
## Example
|
4
6
|
|
5
|
-
== Example
|
6
|
-
|
7
7
|
require 'storable'
|
8
|
-
|
8
|
+
|
9
9
|
class Machine < Storable
|
10
10
|
field :environment # Define field names for Machine. The
|
11
11
|
field :role # default type is String, but you can
|
12
12
|
field :position => Integer # specify a type using a hash syntax.
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
mac1 = Machine.new # Instances of Machine have accessors
|
16
|
-
mac1.environment = "stage" # just like regular attributes.
|
16
|
+
mac1.environment = "stage" # just like regular attributes.
|
17
17
|
mac1.role = "app"
|
18
18
|
mac1.position = 1
|
19
|
-
|
20
|
-
puts "# YAML", mac1.to_yaml # Note: the field order is maintained
|
19
|
+
|
20
|
+
puts "# YAML", mac1.to_yaml # Note: the field order is maintained
|
21
21
|
puts "# CSV", mac1.to_csv # => stage,app,1
|
22
22
|
puts "# JSON", mac1.to_json # Note: field order not maintained.
|
23
|
-
|
23
|
+
|
24
24
|
mac2 = Machine.from_yaml(mac1.to_yaml)
|
25
25
|
puts mac2.environment # => "stage"
|
26
26
|
puts mac2.position.class # => Fixnum
|
27
27
|
|
28
28
|
|
29
|
-
|
29
|
+
## Sensitive Fields
|
30
30
|
|
31
31
|
require 'storable'
|
32
|
-
|
32
|
+
|
33
33
|
class Calc < Storable
|
34
34
|
field :three
|
35
35
|
field :two
|
36
36
|
field :one
|
37
37
|
sensitive_fields :three
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
calc = Calc.new 3, 2, 1
|
41
41
|
calc.to_a # => [3, 2, 1]
|
42
42
|
calc.sensitive!
|
43
43
|
calc.to_a # => [2, 1]
|
44
|
-
|
45
|
-
|
46
|
-
== Storing Procs
|
47
44
|
|
48
|
-
|
49
|
-
|
45
|
+
|
46
|
+
## Storing Procs
|
47
|
+
|
48
|
+
Storable can also marshal Proc objects to and from their actual source code.
|
49
|
+
|
50
50
|
require 'storable'
|
51
|
-
|
51
|
+
|
52
52
|
class Maths < Storable
|
53
53
|
field :x => Float
|
54
54
|
field :y => Float
|
55
55
|
field :calculate => Proc
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
m1 = Maths.new 2.0, 3.0
|
59
59
|
m1.calculate = Proc.new { @x * @y }
|
60
|
-
|
60
|
+
|
61
61
|
m1.calculate.source # => "{ @x * @y }"
|
62
62
|
m1.call :calculate # => 6.0
|
63
|
-
|
63
|
+
|
64
64
|
dump = m1.to_json
|
65
|
-
|
65
|
+
|
66
66
|
m2 = Maths.from_json dump
|
67
67
|
m2.call :calculate # => 6.0
|
68
|
-
|
69
|
-
|
70
|
-
Anything is possible when you keep your mind open and you use Ruby.
|
71
68
|
|
72
69
|
|
73
|
-
|
70
|
+
Anything is possible when you keep your mind open and you use Ruby.
|
71
|
+
|
72
|
+
|
73
|
+
## Installation
|
74
74
|
|
75
75
|
Via Rubygems, one of:
|
76
76
|
|
@@ -80,29 +80,30 @@ Via Rubygems, one of:
|
|
80
80
|
or via download:
|
81
81
|
* storable-latest.tar.gz[http://github.com/delano/storable/tarball/latest]
|
82
82
|
* storable-latest.zip[http://github.com/delano/storable/zipball/latest]
|
83
|
-
|
84
83
|
|
85
|
-
== Prerequisites
|
86
84
|
|
87
|
-
|
85
|
+
## Prerequisites
|
86
|
+
|
87
|
+
* Ruby <=2.7, >=1.9, possibly JRuby
|
88
88
|
|
89
89
|
|
90
|
-
|
90
|
+
## Credits
|
91
91
|
|
92
92
|
* Delano Mandelbaum (delano@solutious.com)
|
93
93
|
* lib/proc_source.rb is based on http://github.com/imedo/background
|
94
94
|
* OrderedHash implementation by Jan Molic
|
95
95
|
|
96
96
|
|
97
|
-
|
97
|
+
## Thanks
|
98
98
|
|
99
|
-
* Pierre Riteau (priteau[
|
99
|
+
* Pierre Riteau (priteau[https://github.com/priteau]) for bug fixes.
|
100
|
+
* notro[https://github.com/priteau] for proc_source improvements.
|
100
101
|
|
101
102
|
|
102
|
-
|
103
|
+
## More Info
|
103
104
|
|
104
|
-
*
|
105
|
+
* GitHub[http://github.com/delano/storable]
|
105
106
|
|
106
|
-
|
107
|
+
## License
|
107
108
|
|
108
|
-
See: LICENSE.txt
|
109
|
+
See: LICENSE.txt
|
data/Rakefile
CHANGED
@@ -1,22 +1,17 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake/clean'
|
3
|
-
require '
|
3
|
+
require 'rubygems/package_task'
|
4
4
|
require 'fileutils'
|
5
|
+
require 'rdoc/task'
|
5
6
|
include FileUtils
|
6
7
|
|
7
|
-
begin
|
8
|
-
require 'hanna/rdoctask'
|
9
|
-
rescue LoadError
|
10
|
-
require 'rake/rdoctask'
|
11
|
-
end
|
12
|
-
|
13
8
|
task :default => :package
|
14
|
-
|
9
|
+
|
10
|
+
|
15
11
|
# CONFIG =============================================================
|
16
12
|
|
17
13
|
# Change the following according to your needs
|
18
|
-
README = "README.
|
19
|
-
CHANGES = "CHANGES.txt"
|
14
|
+
README = "README.md"
|
20
15
|
LICENSE = "LICENSE.txt"
|
21
16
|
|
22
17
|
# Files and directories to be deleted when you run "rake clean"
|
@@ -28,20 +23,22 @@ load "#{name}.gemspec"
|
|
28
23
|
version = @spec.version
|
29
24
|
|
30
25
|
# That's it! The following defaults should allow you to get started
|
31
|
-
# on other things.
|
26
|
+
# on other things.
|
32
27
|
|
33
28
|
|
34
29
|
# TESTS/SPECS =========================================================
|
35
30
|
|
36
|
-
|
31
|
+
task :test do
|
32
|
+
sh "try"
|
33
|
+
end
|
37
34
|
|
38
35
|
# INSTALL =============================================================
|
39
36
|
|
40
|
-
|
37
|
+
Gem::PackageTask.new(@spec) do |p|
|
41
38
|
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
|
42
39
|
end
|
43
40
|
|
44
|
-
task :build => [ :package ]
|
41
|
+
task :build => [ :test, :package ]
|
45
42
|
task :release => [ :rdoc, :package ]
|
46
43
|
task :install => [ :rdoc, :package ] do
|
47
44
|
sh %{sudo gem install pkg/#{name}-#{version}.gem}
|
@@ -51,65 +48,15 @@ task :uninstall => [ :clean ] do
|
|
51
48
|
end
|
52
49
|
|
53
50
|
|
54
|
-
# RUBYFORGE RELEASE / PUBLISH TASKS ==================================
|
55
|
-
|
56
|
-
if @spec.rubyforge_project
|
57
|
-
desc 'Publish website to rubyforge'
|
58
|
-
task 'publish:rdoc' => 'doc/index.html' do
|
59
|
-
sh "scp -rp doc/* rubyforge.org:/var/www/gforge-projects/#{name}/"
|
60
|
-
end
|
61
|
-
|
62
|
-
desc 'Public release to rubyforge'
|
63
|
-
task 'publish:gem' => [:package] do |t|
|
64
|
-
sh <<-end
|
65
|
-
rubyforge add_release -o Any -a #{CHANGES} -f -n #{README} #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.gem &&
|
66
|
-
rubyforge add_file -o Any -a #{CHANGES} -f -n #{README} #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.tgz
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
51
|
# RUBY DOCS TASK ==================================
|
74
|
-
begin
|
75
|
-
require 'hanna/rdoctask'
|
76
|
-
rescue LoadError
|
77
|
-
require 'rake/rdoctask'
|
78
|
-
end
|
79
52
|
|
80
|
-
|
53
|
+
RDoc::Task.new do |t|
|
81
54
|
t.rdoc_dir = 'doc'
|
82
55
|
t.title = @spec.summary
|
83
56
|
t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
84
57
|
t.options << '--charset' << 'utf-8'
|
85
58
|
t.rdoc_files.include(LICENSE)
|
86
59
|
t.rdoc_files.include(README)
|
87
|
-
t.rdoc_files.include(CHANGES)
|
88
60
|
#t.rdoc_files.include('bin/*')
|
89
61
|
t.rdoc_files.include('lib/**/*.rb')
|
90
62
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
#Hoe.new('rspec', Spec::VERSION::STRING) do |p|
|
96
|
-
# p.summary = Spec::VERSION::SUMMARY
|
97
|
-
# p.description = "Behaviour Driven Development for Ruby."
|
98
|
-
# p.rubyforge_name = 'rspec'
|
99
|
-
# p.developer('RSpec Development Team', 'rspec-devel@rubyforge.org')
|
100
|
-
# p.extra_dev_deps = [["cucumber",">= 0.1.13"]]
|
101
|
-
# p.remote_rdoc_dir = "rspec/#{Spec::VERSION::STRING}"
|
102
|
-
# p.rspec_options = ['--options', 'spec/spec.opts']
|
103
|
-
# p.history_file = 'History.rdoc'
|
104
|
-
# p.readme_file = 'README.rdoc'
|
105
|
-
# p.post_install_message = <<-POST_INSTALL_MESSAGE
|
106
|
-
##{'*'*50}
|
107
|
-
#
|
108
|
-
# Thank you for installing rspec-#{Spec::VERSION::STRING}
|
109
|
-
#
|
110
|
-
# Please be sure to read History.rdoc and Upgrade.rdoc
|
111
|
-
# for useful information about this release.
|
112
|
-
#
|
113
|
-
#{'*'*50}
|
114
|
-
#POST_INSTALL_MESSAGE
|
115
|
-
#end
|
data/lib/core_ext.rb
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# RubyToken was removed in >= 2.7
|
4
|
+
# Direct copy from Ruby 2.6.6 source
|
5
|
+
#
|
6
|
+
|
7
|
+
# frozen_string_literal: false
|
8
|
+
#
|
9
|
+
# irb/ruby-token.rb - ruby tokens
|
10
|
+
# $Release Version: 0.9.6$
|
11
|
+
# $Revision$
|
12
|
+
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
13
|
+
#
|
14
|
+
# --
|
15
|
+
#
|
16
|
+
#
|
17
|
+
#
|
18
|
+
# :stopdoc:
|
19
|
+
module RubyToken
|
20
|
+
EXPR_BEG = :EXPR_BEG
|
21
|
+
EXPR_MID = :EXPR_MID
|
22
|
+
EXPR_END = :EXPR_END
|
23
|
+
EXPR_ARG = :EXPR_ARG
|
24
|
+
EXPR_FNAME = :EXPR_FNAME
|
25
|
+
EXPR_DOT = :EXPR_DOT
|
26
|
+
EXPR_CLASS = :EXPR_CLASS
|
27
|
+
|
28
|
+
class Token
|
29
|
+
def initialize(seek, line_no, char_no)
|
30
|
+
@seek = seek
|
31
|
+
@line_no = line_no
|
32
|
+
@char_no = char_no
|
33
|
+
end
|
34
|
+
attr_reader :seek, :line_no, :char_no
|
35
|
+
end
|
36
|
+
|
37
|
+
class TkNode < Token
|
38
|
+
def initialize(seek, line_no, char_no)
|
39
|
+
super
|
40
|
+
end
|
41
|
+
attr_reader :node
|
42
|
+
end
|
43
|
+
|
44
|
+
class TkId < Token
|
45
|
+
def initialize(seek, line_no, char_no, name)
|
46
|
+
super(seek, line_no, char_no)
|
47
|
+
@name = name
|
48
|
+
end
|
49
|
+
attr_reader :name
|
50
|
+
end
|
51
|
+
|
52
|
+
class TkVal < Token
|
53
|
+
def initialize(seek, line_no, char_no, value = nil)
|
54
|
+
super(seek, line_no, char_no)
|
55
|
+
@value = value
|
56
|
+
end
|
57
|
+
attr_reader :value
|
58
|
+
end
|
59
|
+
|
60
|
+
class TkOp < Token
|
61
|
+
attr_accessor :name
|
62
|
+
end
|
63
|
+
|
64
|
+
class TkOPASGN < TkOp
|
65
|
+
def initialize(seek, line_no, char_no, op)
|
66
|
+
super(seek, line_no, char_no)
|
67
|
+
op = TkReading2Token[op][0] unless op.kind_of?(Symbol)
|
68
|
+
@op = op
|
69
|
+
end
|
70
|
+
attr_reader :op
|
71
|
+
end
|
72
|
+
|
73
|
+
class TkUnknownChar < Token
|
74
|
+
def initialize(seek, line_no, char_no, id)
|
75
|
+
super(seek, line_no, char_no)
|
76
|
+
@name = name
|
77
|
+
end
|
78
|
+
attr_reader :name
|
79
|
+
end
|
80
|
+
|
81
|
+
class TkError < Token
|
82
|
+
end
|
83
|
+
|
84
|
+
def Token(token, value = nil)
|
85
|
+
case token
|
86
|
+
when String
|
87
|
+
if (tk = TkReading2Token[token]).nil?
|
88
|
+
IRB.fail TkReading2TokenNoKey, token
|
89
|
+
end
|
90
|
+
tk = Token(tk[0], value)
|
91
|
+
if tk.kind_of?(TkOp)
|
92
|
+
tk.name = token
|
93
|
+
end
|
94
|
+
return tk
|
95
|
+
when Symbol
|
96
|
+
if (tk = TkSymbol2Token[token]).nil?
|
97
|
+
IRB.fail TkSymbol2TokenNoKey, token
|
98
|
+
end
|
99
|
+
return Token(tk[0], value)
|
100
|
+
else
|
101
|
+
if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
|
102
|
+
token.new(@prev_seek, @prev_line_no, @prev_char_no)
|
103
|
+
else
|
104
|
+
token.new(@prev_seek, @prev_line_no, @prev_char_no, value)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
TokenDefinitions = [
|
110
|
+
[:TkCLASS, TkId, "class", EXPR_CLASS],
|
111
|
+
[:TkMODULE, TkId, "module", EXPR_BEG],
|
112
|
+
[:TkDEF, TkId, "def", EXPR_FNAME],
|
113
|
+
[:TkUNDEF, TkId, "undef", EXPR_FNAME],
|
114
|
+
[:TkBEGIN, TkId, "begin", EXPR_BEG],
|
115
|
+
[:TkRESCUE, TkId, "rescue", EXPR_MID],
|
116
|
+
[:TkENSURE, TkId, "ensure", EXPR_BEG],
|
117
|
+
[:TkEND, TkId, "end", EXPR_END],
|
118
|
+
[:TkIF, TkId, "if", EXPR_BEG, :TkIF_MOD],
|
119
|
+
[:TkUNLESS, TkId, "unless", EXPR_BEG, :TkUNLESS_MOD],
|
120
|
+
[:TkTHEN, TkId, "then", EXPR_BEG],
|
121
|
+
[:TkELSIF, TkId, "elsif", EXPR_BEG],
|
122
|
+
[:TkELSE, TkId, "else", EXPR_BEG],
|
123
|
+
[:TkCASE, TkId, "case", EXPR_BEG],
|
124
|
+
[:TkWHEN, TkId, "when", EXPR_BEG],
|
125
|
+
[:TkWHILE, TkId, "while", EXPR_BEG, :TkWHILE_MOD],
|
126
|
+
[:TkUNTIL, TkId, "until", EXPR_BEG, :TkUNTIL_MOD],
|
127
|
+
[:TkFOR, TkId, "for", EXPR_BEG],
|
128
|
+
[:TkBREAK, TkId, "break", EXPR_END],
|
129
|
+
[:TkNEXT, TkId, "next", EXPR_END],
|
130
|
+
[:TkREDO, TkId, "redo", EXPR_END],
|
131
|
+
[:TkRETRY, TkId, "retry", EXPR_END],
|
132
|
+
[:TkIN, TkId, "in", EXPR_BEG],
|
133
|
+
[:TkDO, TkId, "do", EXPR_BEG],
|
134
|
+
[:TkRETURN, TkId, "return", EXPR_MID],
|
135
|
+
[:TkYIELD, TkId, "yield", EXPR_END],
|
136
|
+
[:TkSUPER, TkId, "super", EXPR_END],
|
137
|
+
[:TkSELF, TkId, "self", EXPR_END],
|
138
|
+
[:TkNIL, TkId, "nil", EXPR_END],
|
139
|
+
[:TkTRUE, TkId, "true", EXPR_END],
|
140
|
+
[:TkFALSE, TkId, "false", EXPR_END],
|
141
|
+
[:TkAND, TkId, "and", EXPR_BEG],
|
142
|
+
[:TkOR, TkId, "or", EXPR_BEG],
|
143
|
+
[:TkNOT, TkId, "not", EXPR_BEG],
|
144
|
+
[:TkIF_MOD, TkId],
|
145
|
+
[:TkUNLESS_MOD, TkId],
|
146
|
+
[:TkWHILE_MOD, TkId],
|
147
|
+
[:TkUNTIL_MOD, TkId],
|
148
|
+
[:TkALIAS, TkId, "alias", EXPR_FNAME],
|
149
|
+
[:TkDEFINED, TkId, "defined?", EXPR_END],
|
150
|
+
[:TklBEGIN, TkId, "BEGIN", EXPR_END],
|
151
|
+
[:TklEND, TkId, "END", EXPR_END],
|
152
|
+
[:Tk__LINE__, TkId, "__LINE__", EXPR_END],
|
153
|
+
[:Tk__FILE__, TkId, "__FILE__", EXPR_END],
|
154
|
+
|
155
|
+
[:TkIDENTIFIER, TkId],
|
156
|
+
[:TkFID, TkId],
|
157
|
+
[:TkGVAR, TkId],
|
158
|
+
[:TkCVAR, TkId],
|
159
|
+
[:TkIVAR, TkId],
|
160
|
+
[:TkCONSTANT, TkId],
|
161
|
+
|
162
|
+
[:TkINTEGER, TkVal],
|
163
|
+
[:TkFLOAT, TkVal],
|
164
|
+
[:TkSTRING, TkVal],
|
165
|
+
[:TkXSTRING, TkVal],
|
166
|
+
[:TkREGEXP, TkVal],
|
167
|
+
[:TkSYMBOL, TkVal],
|
168
|
+
|
169
|
+
[:TkDSTRING, TkNode],
|
170
|
+
[:TkDXSTRING, TkNode],
|
171
|
+
[:TkDREGEXP, TkNode],
|
172
|
+
[:TkNTH_REF, TkNode],
|
173
|
+
[:TkBACK_REF, TkNode],
|
174
|
+
|
175
|
+
[:TkUPLUS, TkOp, "+@"],
|
176
|
+
[:TkUMINUS, TkOp, "-@"],
|
177
|
+
[:TkPOW, TkOp, "**"],
|
178
|
+
[:TkCMP, TkOp, "<=>"],
|
179
|
+
[:TkEQ, TkOp, "=="],
|
180
|
+
[:TkEQQ, TkOp, "==="],
|
181
|
+
[:TkNEQ, TkOp, "!="],
|
182
|
+
[:TkGEQ, TkOp, ">="],
|
183
|
+
[:TkLEQ, TkOp, "<="],
|
184
|
+
[:TkANDOP, TkOp, "&&"],
|
185
|
+
[:TkOROP, TkOp, "||"],
|
186
|
+
[:TkMATCH, TkOp, "=~"],
|
187
|
+
[:TkNMATCH, TkOp, "!~"],
|
188
|
+
[:TkDOT2, TkOp, ".."],
|
189
|
+
[:TkDOT3, TkOp, "..."],
|
190
|
+
[:TkAREF, TkOp, "[]"],
|
191
|
+
[:TkASET, TkOp, "[]="],
|
192
|
+
[:TkLSHFT, TkOp, "<<"],
|
193
|
+
[:TkRSHFT, TkOp, ">>"],
|
194
|
+
[:TkCOLON2, TkOp],
|
195
|
+
[:TkCOLON3, TkOp],
|
196
|
+
[:TkASSOC, TkOp, "=>"],
|
197
|
+
[:TkQUESTION, TkOp, "?"], #?
|
198
|
+
[:TkCOLON, TkOp, ":"], #:
|
199
|
+
|
200
|
+
[:TkfLPAREN], # func( #
|
201
|
+
[:TkfLBRACK], # func[ #
|
202
|
+
[:TkfLBRACE], # func{ #
|
203
|
+
[:TkSTAR], # *arg
|
204
|
+
[:TkAMPER], # &arg #
|
205
|
+
[:TkSYMBEG], # :SYMBOL
|
206
|
+
|
207
|
+
[:TkGT, TkOp, ">"],
|
208
|
+
[:TkLT, TkOp, "<"],
|
209
|
+
[:TkPLUS, TkOp, "+"],
|
210
|
+
[:TkMINUS, TkOp, "-"],
|
211
|
+
[:TkMULT, TkOp, "*"],
|
212
|
+
[:TkDIV, TkOp, "/"],
|
213
|
+
[:TkMOD, TkOp, "%"],
|
214
|
+
[:TkBITOR, TkOp, "|"],
|
215
|
+
[:TkBITXOR, TkOp, "^"],
|
216
|
+
[:TkBITAND, TkOp, "&"],
|
217
|
+
[:TkBITNOT, TkOp, "~"],
|
218
|
+
[:TkNOTOP, TkOp, "!"],
|
219
|
+
|
220
|
+
[:TkBACKQUOTE, TkOp, "`"],
|
221
|
+
|
222
|
+
[:TkASSIGN, Token, "="],
|
223
|
+
[:TkDOT, Token, "."],
|
224
|
+
[:TkLPAREN, Token, "("], #(exp)
|
225
|
+
[:TkLBRACK, Token, "["], #[arry]
|
226
|
+
[:TkLBRACE, Token, "{"], #{hash}
|
227
|
+
[:TkRPAREN, Token, ")"],
|
228
|
+
[:TkRBRACK, Token, "]"],
|
229
|
+
[:TkRBRACE, Token, "}"],
|
230
|
+
[:TkCOMMA, Token, ","],
|
231
|
+
[:TkSEMICOLON, Token, ";"],
|
232
|
+
|
233
|
+
[:TkCOMMENT],
|
234
|
+
[:TkRD_COMMENT],
|
235
|
+
[:TkSPACE],
|
236
|
+
[:TkNL],
|
237
|
+
[:TkEND_OF_SCRIPT],
|
238
|
+
|
239
|
+
[:TkBACKSLASH, TkUnknownChar, "\\"],
|
240
|
+
[:TkAT, TkUnknownChar, "@"],
|
241
|
+
[:TkDOLLAR, TkUnknownChar, "$"],
|
242
|
+
]
|
243
|
+
|
244
|
+
# {reading => token_class}
|
245
|
+
# {reading => [token_class, *opt]}
|
246
|
+
TkReading2Token = {}
|
247
|
+
TkSymbol2Token = {}
|
248
|
+
|
249
|
+
def RubyToken.def_token(token_n, super_token = Token, reading = nil, *opts)
|
250
|
+
token_n = token_n.id2name if token_n.kind_of?(Symbol)
|
251
|
+
if RubyToken.const_defined?(token_n)
|
252
|
+
IRB.fail AlreadyDefinedToken, token_n
|
253
|
+
end
|
254
|
+
token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}")
|
255
|
+
|
256
|
+
if reading
|
257
|
+
if TkReading2Token[reading]
|
258
|
+
IRB.fail TkReading2TokenDuplicateError, token_n, reading
|
259
|
+
end
|
260
|
+
if opts.empty?
|
261
|
+
TkReading2Token[reading] = [token_c]
|
262
|
+
else
|
263
|
+
TkReading2Token[reading] = [token_c].concat(opts)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
TkSymbol2Token[token_n.intern] = token_c
|
267
|
+
end
|
268
|
+
|
269
|
+
for defs in TokenDefinitions
|
270
|
+
def_token(*defs)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
# :startdoc:
|