Skip to content

Commit

Permalink
Showing 12 changed files with 4,032 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/ruby/truffle/rubysl/README.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ was written by Brian Shirai, et al.

Commits for each library are:

* rubysl-date `16bc24123ca2e51fef293460e8f84c67fd1bb3ef`
* rubysl-strscan `efab0248119cbb10b2b0ce2561eae269e052cdfe`
* rubysl-stringio `4b2977296eceef83084146c73d9ddef8d7e8f1af`
* rubysl-complex `ccdb6e86aed5eaada64808f85d03d08d2834294a`
25 changes: 25 additions & 0 deletions lib/ruby/truffle/rubysl/rubysl-date/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2013, Brian Shirai
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the library nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions lib/ruby/truffle/rubysl/rubysl-date/lib/date.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "rubysl/date"
431 changes: 431 additions & 0 deletions lib/ruby/truffle/rubysl/rubysl-date/lib/date/delta.rb

Large diffs are not rendered by default.

301 changes: 301 additions & 0 deletions lib/ruby/truffle/rubysl/rubysl-date/lib/date/delta/parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
#
# DO NOT MODIFY!!!!
# This file is automatically generated by racc 1.4.5
# from racc grammer file "parser.ry".
#

require 'racc/parser'


class Date

class Delta

class Parser < Racc::Parser

module_eval <<'..end parser.ry modeval..id43bff5dec9', 'parser.ry', 42
def lookup(str)
t = str.downcase
k = UNITS4KEY[t]
return [:UNIT, k] if k
return [:AND, nil] if t == 'and'
return [:UNKNOWNWORD, nil]
end
def parse(str)
@q = []
until str.empty?
case str
when /\A\s+/
when /\AP(\d+y)?(\d+m)?(\d+d)?t?(\d+h)?(\d+m)?(\d+s)?(\d+w)?/i
y, m, d, h, min, s, w =
[$1, $2, $3, $4, $5, $6, $7].collect{|x| x.to_i}
y *= UNITS4KEY['years']
m *= UNITS4KEY['months']
d *= UNITS4KEY['days']
h *= UNITS4KEY['hours']
min *= UNITS4KEY['minutes']
s *= UNITS4KEY['seconds']
w *= UNITS4KEY['weeks']
@q.push [:DURATION, y + m + d + h + min + s + w]
when /\A\d+/
@q.push [:DIGITS, $&.to_i]
when /\A[a-z]+/i
@q.push lookup($&)
when /\A.|\n/
@q.push [$&, $&]
end
str = $'
end
@q.push [false, false]
do_parse
end
def next_token
@q.shift
end
..end parser.ry modeval..id43bff5dec9

##### racc 1.4.5 generates ###

racc_reduce_table = [
0, 0, :racc_error,
1, 16, :_reduce_none,
1, 17, :_reduce_none,
1, 17, :_reduce_none,
3, 17, :_reduce_4,
3, 17, :_reduce_5,
3, 17, :_reduce_6,
3, 17, :_reduce_7,
3, 17, :_reduce_8,
3, 17, :_reduce_9,
3, 17, :_reduce_10,
2, 17, :_reduce_11,
2, 17, :_reduce_12,
3, 17, :_reduce_13,
2, 18, :_reduce_14,
0, 20, :_reduce_15,
1, 20, :_reduce_none,
1, 19, :_reduce_none ]

racc_reduce_n = 18

racc_shift_n = 32

racc_action_table = [
13, 14, 15, 16, 17, 18, 19, 4, 27, 23,
8, 9, 1, 4, 25, 2, 8, 9, 1, 4,
24, 2, 8, 9, 1, 4, 21, 2, 8, 9,
1, 4, 11, 2, 8, 9, 1, 4, 26, 2,
8, 9, 1, 4, nil, 2, 8, 9, 1, 4,
nil, 2, 8, 9, 1, nil, nil, 2, 13, 14,
15, 16, 17, 18, 19, 13, 14, 15, 13, 14,
15, 13, 14, 15, 13, 14, 15 ]

racc_action_check = [
10, 10, 10, 10, 10, 10, 10, 17, 15, 10,
17, 17, 17, 18, 13, 17, 18, 18, 18, 4,
11, 18, 4, 4, 4, 1, 9, 4, 1, 1,
1, 8, 3, 1, 8, 8, 8, 19, 14, 8,
19, 19, 19, 0, nil, 19, 0, 0, 0, 16,
nil, 0, 16, 16, 16, nil, nil, 16, 5, 5,
5, 5, 5, 5, 5, 30, 30, 30, 28, 28,
28, 29, 29, 29, 31, 31, 31 ]

racc_action_pointer = [
37, 19, nil, 32, 13, 55, nil, nil, 25, 13,
-3, 20, nil, 4, 28, -2, 43, 1, 7, 31,
nil, nil, nil, nil, nil, nil, nil, nil, 65, 68,
62, 71 ]

racc_action_default = [
-18, -18, -17, -18, -18, -1, -2, -3, -18, -15,
-18, -18, -12, -18, -18, -18, -18, -18, -18, -18,
-11, -16, -14, -13, 32, -10, -8, -9, -4, -5,
-6, -7 ]

racc_goto_table = [
5, 10, 3, 22, 12, nil, nil, nil, 20, nil,
nil, nil, nil, nil, nil, nil, 28, 29, 30, 31 ]

racc_goto_check = [
2, 2, 1, 5, 2, nil, nil, nil, 2, nil,
nil, nil, nil, nil, nil, nil, 2, 2, 2, 2 ]

racc_goto_pointer = [
nil, 2, 0, nil, nil, -6 ]

racc_goto_default = [
nil, nil, nil, 6, 7, nil ]

racc_token_table = {
false => 0,
Object.new => 1,
:UNARY => 2,
"^" => 3,
"*" => 4,
"/" => 5,
"+" => 6,
"," => 7,
:AND => 8,
"-" => 9,
:DIGITS => 10,
"(" => 11,
")" => 12,
:UNIT => 13,
:DURATION => 14 }

racc_use_result_var = true

racc_nt_base = 15

Racc_arg = [
racc_action_table,
racc_action_check,
racc_action_default,
racc_action_pointer,
racc_goto_table,
racc_goto_check,
racc_goto_default,
racc_goto_pointer,
racc_nt_base,
racc_reduce_table,
racc_token_table,
racc_shift_n,
racc_reduce_n,
racc_use_result_var ]

Racc_token_to_s_table = [
'$end',
'error',
'UNARY',
'"^"',
'"*"',
'"/"',
'"+"',
'","',
'AND',
'"-"',
'DIGITS',
'"("',
'")"',
'UNIT',
'DURATION',
'$start',
'stmt',
'expr',
'time',
'iso',
'unit']

Racc_debug_parser = false

##### racc system variables end #####

# reduce 0 omitted

# reduce 1 omitted

# reduce 2 omitted

# reduce 3 omitted

module_eval <<'.,.,', 'parser.ry', 18
def _reduce_4( val, _values, result )
result += val[2]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 19
def _reduce_5( val, _values, result )
result += val[2]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 20
def _reduce_6( val, _values, result )
result += val[2]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 21
def _reduce_7( val, _values, result )
result -= val[2]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 22
def _reduce_8( val, _values, result )
result *= val[2]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 23
def _reduce_9( val, _values, result )
result /= val[2]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 24
def _reduce_10( val, _values, result )
result **= val[2]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 25
def _reduce_11( val, _values, result )
result = -val[1]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 26
def _reduce_12( val, _values, result )
result = +val[1]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 27
def _reduce_13( val, _values, result )
result = val[1]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 30
def _reduce_14( val, _values, result )
result = val[0] * val[1]
result
end
.,.,

module_eval <<'.,.,', 'parser.ry', 33
def _reduce_15( val, _values, result )
result = 1
result
end
.,.,

# reduce 16 omitted

# reduce 17 omitted

def _reduce_none( val, _values, result )
result
end

end # class Parser

end # class Delta

end # class Date
84 changes: 84 additions & 0 deletions lib/ruby/truffle/rubysl/rubysl-date/lib/date/delta/parser.ry
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# parser.ry: Written by Tadayoshi Funaba 2006,2008,2009 -*- ruby -*-

class Date::Delta::Parser

prechigh
nonassoc UNARY
left '^'
left '*' '/'
left '+' ',' AND '-'
preclow

rule

stmt : expr
;

expr : time
| iso
| expr '+' expr {result += val[2]}
| expr ',' expr {result += val[2]}
| expr AND expr {result += val[2]}
| expr '-' expr {result -= val[2]}
| expr '*' DIGITS {result *= val[2]}
| expr '/' DIGITS {result /= val[2]}
| expr '^' DIGITS {result **= val[2]}
| '-' expr =UNARY {result = -val[1]}
| '+' expr =UNARY {result = +val[1]}
| '(' expr ')' {result = val[1]}
;

time : DIGITS unit {result = val[0] * val[1]}
;

unit : {result = 1} | UNIT
;

iso : DURATION
;

---- header ----
---- inner ----

def lookup(str)
t = str.downcase
k = UNITS4KEY[t]
return [:UNIT, k] if k
return [:AND, nil] if t == 'and'
return [:UNKNOWNWORD, nil]
end

def parse(str)
@q = []
until str.empty?
case str
when /\A\s+/
when /\AP(\d+y)?(\d+m)?(\d+d)?t?(\d+h)?(\d+m)?(\d+s)?(\d+w)?/i
y, m, d, h, min, s, w =
[$1, $2, $3, $4, $5, $6, $7].collect{|x| x.to_i}
y *= UNITS4KEY['years']
m *= UNITS4KEY['months']
d *= UNITS4KEY['days']
h *= UNITS4KEY['hours']
min *= UNITS4KEY['minutes']
s *= UNITS4KEY['seconds']
w *= UNITS4KEY['weeks']
@q.push [:DURATION, y + m + d + h + min + s + w]
when /\A\d+/
@q.push [:DIGITS, $&.to_i]
when /\A[a-z]+/i
@q.push lookup($&)
when /\A.|\n/
@q.push [$&, $&]
end
str = $'
end
@q.push [false, false]
do_parse
end

def next_token
@q.shift
end

---- footer ----
1,328 changes: 1,328 additions & 0 deletions lib/ruby/truffle/rubysl/rubysl-date/lib/date/format.rb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/ruby/truffle/rubysl/rubysl-date/lib/rubysl/date.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "rubysl/date/version"
require "rubysl/date/date"
1,852 changes: 1,852 additions & 0 deletions lib/ruby/truffle/rubysl/rubysl-date/lib/rubysl/date/date.rb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module RubySL
module Date
VERSION = "2.0.9"
end
end
1 change: 1 addition & 0 deletions spec/truffle/truffle.mspec
Original file line number Diff line number Diff line change
@@ -103,6 +103,7 @@ class MSpecScript
"spec/ruby/library/abbrev",
"spec/ruby/library/base64",
"spec/ruby/library/complex",
"spec/ruby/library/date",
"spec/ruby/library/erb",
"spec/ruby/library/getoptlong",
"spec/ruby/library/observer",
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ public void init() {
loadPath.slowPush(truffleContext.makeString(new File(home, "lib/ruby/truffle/mri").toString()));

// Libraries from RubySL
for (String lib : Arrays.asList("rubysl-strscan", "rubysl-stringio","rubysl-complex")) {
for (String lib : Arrays.asList("rubysl-strscan", "rubysl-stringio","rubysl-complex","rubysl-date")) {
loadPath.slowPush(truffleContext.makeString(new File(home, "lib/ruby/truffle/rubysl/" + lib + "/lib").toString()));
}

0 comments on commit 30fcc77

Please sign in to comment.