ruby-cldr 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Gemfile.lock +23 -0
- data/README.textile +9 -6
- data/VERSION +1 -1
- data/lib/cldr.rb +1 -1
- data/lib/cldr/data.rb +9 -29
- data/lib/cldr/download.rb +2 -2
- data/lib/cldr/export.rb +8 -2
- data/lib/cldr/export/code.rb +34 -0
- data/lib/cldr/export/code/numbers.rb +29 -0
- data/lib/cldr/export/data.rb +36 -0
- data/lib/cldr/export/data/base.rb +61 -0
- data/lib/cldr/export/data/calendars.rb +14 -0
- data/lib/cldr/export/data/calendars/gregorian.rb +142 -0
- data/lib/cldr/export/data/currencies.rb +28 -0
- data/lib/cldr/export/data/delimiters.rb +29 -0
- data/lib/cldr/export/data/languages.rb +19 -0
- data/lib/cldr/export/data/numbers.rb +67 -0
- data/lib/cldr/export/data/plurals.rb +41 -0
- data/lib/cldr/{data → export/data}/plurals/cldr_grammar.treetop +0 -0
- data/lib/cldr/export/data/plurals/grammar.rb +538 -0
- data/lib/cldr/export/data/plurals/rules.rb +119 -0
- data/lib/cldr/export/data/territories.rb +19 -0
- data/lib/cldr/export/data/timezones.rb +27 -0
- data/lib/cldr/export/data/units.rb +29 -0
- data/lib/cldr/export/ruby.rb +1 -1
- data/lib/cldr/export/yaml.rb +1 -1
- data/lib/cldr/format.rb +1 -97
- data/lib/cldr/format/currency.rb +1 -1
- data/lib/cldr/format/date.rb +1 -1
- data/lib/cldr/format/datetime.rb +14 -18
- data/lib/cldr/format/datetime/base.rb +1 -1
- data/lib/cldr/format/decimal.rb +1 -1
- data/lib/cldr/format/decimal/base.rb +1 -1
- data/lib/cldr/format/decimal/fraction.rb +1 -1
- data/lib/cldr/format/decimal/integer.rb +1 -1
- data/lib/cldr/format/decimal/number.rb +1 -1
- data/lib/cldr/format/percent.rb +1 -1
- data/lib/cldr/format/time.rb +1 -1
- data/lib/cldr/thor.rb +3 -3
- data/test/all.rb +1 -1
- data/test/export/code/numbers_test.rb +11 -0
- data/test/{data → export/data}/all.rb +1 -1
- data/test/{data → export/data}/calendars_test.rb +18 -18
- data/test/{data → export/data}/currencies_test.rb +6 -6
- data/test/{data → export/data}/delimiters_test.rb +6 -6
- data/test/{data → export/data}/languages_test.rb +6 -6
- data/test/{data → export/data}/numbers_test.rb +8 -8
- data/test/export/data/plurals_test.rb +141 -0
- data/test/{data → export/data}/territories_test.rb +6 -6
- data/test/{data → export/data}/timezones_test.rb +6 -6
- data/test/{data → export/data}/units_test.rb +6 -6
- data/test/export_test.rb +8 -8
- data/test/{formats → format}/all.rb +1 -1
- data/test/format/currency_test.rb +0 -0
- data/test/format/date_test.rb +265 -0
- data/test/format/datetime_test.rb +18 -0
- data/test/{formats → format}/decimal/fraction_test.rb +4 -4
- data/test/{formats → format}/decimal/integer_test.rb +17 -17
- data/test/{formats → format}/decimal/number_test.rb +19 -19
- data/test/{formats → format}/decimal_test.rb +5 -5
- data/test/format/percent_test.rb +0 -0
- data/test/format/time_test.rb +195 -0
- data/test/test_autotest.rb +36 -0
- data/test/test_helper.rb +16 -1
- metadata +124 -114
- data/lib/cldr/data/base.rb +0 -66
- data/lib/cldr/data/calendars.rb +0 -12
- data/lib/cldr/data/calendars/gregorian.rb +0 -124
- data/lib/cldr/data/currencies.rb +0 -26
- data/lib/cldr/data/delimiters.rb +0 -21
- data/lib/cldr/data/languages.rb +0 -17
- data/lib/cldr/data/numbers.rb +0 -60
- data/lib/cldr/data/plurals.rb +0 -39
- data/lib/cldr/data/plurals/grammar.rb +0 -536
- data/lib/cldr/data/plurals/rules.rb +0 -113
- data/lib/cldr/data/territories.rb +0 -17
- data/lib/cldr/data/timezones.rb +0 -25
- data/lib/cldr/data/units.rb +0 -25
- data/test/data/plurals_test.rb +0 -132
- data/test/formats/datetime/all.rb +0 -3
- data/test/formats/datetime/date_test.rb +0 -31
- data/test/formats/datetime/datetime_test.rb +0 -18
- data/test/formats/datetime/day_test.rb +0 -41
- data/test/formats/datetime/hour_test.rb +0 -79
- data/test/formats/datetime/minute_test.rb +0 -25
- data/test/formats/datetime/month_test.rb +0 -76
- data/test/formats/datetime/period_test.rb +0 -20
- data/test/formats/datetime/quarter_test.rb +0 -118
- data/test/formats/datetime/second_test.rb +0 -80
- data/test/formats/datetime/time_test.rb +0 -33
- data/test/formats/datetime/timezone_test.rb +0 -23
- data/test/formats/datetime/year_test.rb +0 -57
- data/test/formats/format_test.rb +0 -66
- data/test/formats/rails_compat/all.rb +0 -3
- data/test/formats/rails_compat/format_integer_test.rb +0 -56
- data/test/formats/rails_compat/format_number_test.rb +0 -134
data/lib/cldr/data/base.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'core_ext/string/underscore'
|
2
|
-
require 'core_ext/hash/deep_merge'
|
3
|
-
require 'nokogiri'
|
4
|
-
|
5
|
-
class Cldr
|
6
|
-
module Data
|
7
|
-
class Base < Hash
|
8
|
-
attr_reader :locale
|
9
|
-
|
10
|
-
def initialize(*args)
|
11
|
-
hash = args.last.is_a?(Hash) ? args.pop : {}
|
12
|
-
@locale = args.pop.to_sym unless args.empty?
|
13
|
-
end
|
14
|
-
|
15
|
-
def []=(keys, value)
|
16
|
-
return if value.nil? || value.respond_to?(:empty?) && value.empty?
|
17
|
-
|
18
|
-
keys = keys.to_s.split('.')
|
19
|
-
last_key = keys.pop.to_sym
|
20
|
-
|
21
|
-
target = keys.inject(self) { |target, key| target[key.to_sym] || target.store(key.to_sym, {}) }
|
22
|
-
target.store(last_key, value)
|
23
|
-
end
|
24
|
-
|
25
|
-
def update(hash)
|
26
|
-
hash.each { |key, value| self[key] = value }
|
27
|
-
end
|
28
|
-
|
29
|
-
protected
|
30
|
-
|
31
|
-
def plural?(node)
|
32
|
-
!!node.attribute('count')
|
33
|
-
end
|
34
|
-
|
35
|
-
def draft?(node)
|
36
|
-
draft = node.attribute('draft')
|
37
|
-
draft && draft.value == 'unconfirmed'
|
38
|
-
end
|
39
|
-
|
40
|
-
def name(node)
|
41
|
-
node.name.underscore
|
42
|
-
end
|
43
|
-
|
44
|
-
def count(node)
|
45
|
-
node.attribute('count').value
|
46
|
-
end
|
47
|
-
|
48
|
-
def select(*sources)
|
49
|
-
doc.xpath(xpath(sources))
|
50
|
-
end
|
51
|
-
|
52
|
-
def xpath(sources)
|
53
|
-
path = sources.map { |source| source.respond_to?(:path) ? source.path : source }.join('/')
|
54
|
-
path =~ /^\/?\/ldml/ ? path : "//ldml/#{path}"
|
55
|
-
end
|
56
|
-
|
57
|
-
def doc
|
58
|
-
@doc ||= Nokogiri::XML(File.read(path))
|
59
|
-
end
|
60
|
-
|
61
|
-
def path
|
62
|
-
@path ||= "#{Cldr::Data.dir}/main/#{locale.to_s.gsub('-', '_')}.xml"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/lib/cldr/data/calendars.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
class Cldr
|
2
|
-
module Data
|
3
|
-
class Calendars
|
4
|
-
class Gregorian < Base
|
5
|
-
def initialize(locale)
|
6
|
-
super
|
7
|
-
update(
|
8
|
-
:months => contexts('month'),
|
9
|
-
:days => contexts('day'),
|
10
|
-
:eras => contexts('era'),
|
11
|
-
:quarters => contexts('quarter'),
|
12
|
-
:periods => periods,
|
13
|
-
:fields => fields,
|
14
|
-
:'formats.date' => formats('date'),
|
15
|
-
:'formats.time' => formats('time'),
|
16
|
-
:'formats.datetime' => formats('dateTime')
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
def calendar
|
21
|
-
@calendar ||= select('dates/calendars/calendar[@type="gregorian"]').first
|
22
|
-
end
|
23
|
-
|
24
|
-
def contexts(kind)
|
25
|
-
select(calendar, "#{kind}s/#{kind}Context").inject({}) do |result, node|
|
26
|
-
context = node.attribute('type').value.to_sym
|
27
|
-
result[context] = widths(node, kind, context)
|
28
|
-
result
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def widths(node, kind, context)
|
33
|
-
select(node, "#{kind}Width").inject({}) do |result, node|
|
34
|
-
width = node.attribute('type').value.to_sym
|
35
|
-
result[width] = elements(node, kind, context, width)
|
36
|
-
result
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def elements(node, kind, context, width)
|
41
|
-
aliased = select(node, 'alias').first
|
42
|
-
if aliased
|
43
|
-
xpath_to_key(aliased.attribute('path').value, kind, context, width)
|
44
|
-
else
|
45
|
-
select(node, kind).inject({}) do |result, node|
|
46
|
-
key = node.attribute('type').value
|
47
|
-
key = key =~ /^\d*$/ ? key.to_i : key.to_sym
|
48
|
-
result[key] = node.content
|
49
|
-
result
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def xpath_to_key(xpath, kind, context, width)
|
55
|
-
kind = (xpath =~ %r(/([^\/]*)Width) && $1) || kind
|
56
|
-
context = (xpath =~ %r(Context\[@type='([^\/]*)'\]) && $1) || context
|
57
|
-
width = (xpath =~ %r(Width\[@type='([^\/]*)'\]) && $1) || width
|
58
|
-
:"calendars.gregorian.#{kind}s.#{context}.#{width}"
|
59
|
-
end
|
60
|
-
|
61
|
-
def xpath_width
|
62
|
-
end
|
63
|
-
|
64
|
-
def periods
|
65
|
-
am = select(calendar, "am").first
|
66
|
-
pm = select(calendar, "pm").first
|
67
|
-
|
68
|
-
result = {}
|
69
|
-
result[:am] = am.content if am
|
70
|
-
result[:pm] = pm.content if pm
|
71
|
-
result
|
72
|
-
end
|
73
|
-
|
74
|
-
def eras
|
75
|
-
base_path = calendar.path.gsub('/ldml/', '') + '/eras'
|
76
|
-
keys = select("#{base_path}/*").map { |node| node.name }
|
77
|
-
|
78
|
-
eras = keys.inject([]) do |result, name|
|
79
|
-
path = "#{base_path}/#{name}/*"
|
80
|
-
key = name.gsub('era', '').gsub(/s$/, '').downcase.to_sym
|
81
|
-
result << extract(path, :key => lambda { |node| node.attribute('type').value.to_i rescue 0 },
|
82
|
-
:value => lambda { |node| { key => node.content } })
|
83
|
-
end
|
84
|
-
eras.inject({}) { |result, data| result.deep_merge(data) }
|
85
|
-
end
|
86
|
-
|
87
|
-
def formats(type)
|
88
|
-
formats = select(calendar, "#{type}Formats/#{type}FormatLength").inject({}) do |result, node|
|
89
|
-
key = node.attribute('type').value.to_sym rescue :format
|
90
|
-
result[key] = pattern(node, type)
|
91
|
-
result
|
92
|
-
end
|
93
|
-
if default = default_format(type)
|
94
|
-
formats = default.merge(formats)
|
95
|
-
end
|
96
|
-
formats
|
97
|
-
end
|
98
|
-
|
99
|
-
def default_format(type)
|
100
|
-
if node = select(calendar, "#{type}Formats/default").first
|
101
|
-
key = node.attribute('choice').value.to_sym
|
102
|
-
{ :default => :"calendars.gregorian.formats.#{type.downcase}.#{key}" }
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def pattern(node, type)
|
107
|
-
select(node, "#{type}Format/pattern").inject({}) do |result, node|
|
108
|
-
result[:pattern] = node.content
|
109
|
-
result
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def fields
|
114
|
-
select(calendar, "fields/field").inject({}) do |result, node|
|
115
|
-
key = node.attribute('type').value.to_sym
|
116
|
-
name = node.xpath('displayName').first
|
117
|
-
result[key] = name.content if name
|
118
|
-
result
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
data/lib/cldr/data/currencies.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
class Cldr
|
2
|
-
module Data
|
3
|
-
class Currencies < Base
|
4
|
-
def initialize(locale)
|
5
|
-
super
|
6
|
-
self[:currencies] = currencies
|
7
|
-
end
|
8
|
-
|
9
|
-
def currencies
|
10
|
-
select('numbers/currencies/*').inject({}) do |result, node|
|
11
|
-
currency = self.currency(node)
|
12
|
-
result[node.attribute('type').value.to_sym] = currency unless currency.empty?
|
13
|
-
result
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def currency(node)
|
18
|
-
select(node, 'displayName').inject({}) do |result, node|
|
19
|
-
count = node.attribute('count') ? node.attribute('count').value.to_sym : :one
|
20
|
-
result[count] = node.content unless draft?(node)
|
21
|
-
result
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/cldr/data/delimiters.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class Cldr
|
2
|
-
module Data
|
3
|
-
class Delimiters < Base
|
4
|
-
def initialize(locale)
|
5
|
-
super
|
6
|
-
self[:'delimiters.quotes.default'] = quotes('quotation')
|
7
|
-
self[:'delimiters.quotes.alternate'] = quotes('alternateQuotation')
|
8
|
-
end
|
9
|
-
|
10
|
-
def quotes(type)
|
11
|
-
start = select("delimiters/#{type}Start").first
|
12
|
-
end_ = select("delimiters/#{type}End").first
|
13
|
-
|
14
|
-
result = {}
|
15
|
-
result[:start] = start.content if start
|
16
|
-
result[:end] = end_.content if end_
|
17
|
-
result
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/cldr/data/languages.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
class Cldr
|
2
|
-
module Data
|
3
|
-
class Languages < Base
|
4
|
-
def initialize(locale)
|
5
|
-
super
|
6
|
-
self[:languages] = languages
|
7
|
-
end
|
8
|
-
|
9
|
-
def languages
|
10
|
-
@languages ||= select('localeDisplayNames/languages/language').inject({}) do |result, node|
|
11
|
-
result[node.attribute('type').value.gsub('_', '-').to_sym] = node.content unless draft?(node)
|
12
|
-
result
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/cldr/data/numbers.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
class Cldr
|
2
|
-
module Data
|
3
|
-
class Numbers < Base
|
4
|
-
def initialize(locale)
|
5
|
-
super
|
6
|
-
self[:'numbers.symbols'] = symbols
|
7
|
-
self[:'numbers.formats'] = {
|
8
|
-
:decimal => {
|
9
|
-
:patterns => {
|
10
|
-
:default => format('decimal')
|
11
|
-
}
|
12
|
-
},
|
13
|
-
:scientific => {
|
14
|
-
:patterns => {
|
15
|
-
:default => format('scientific')
|
16
|
-
}
|
17
|
-
},
|
18
|
-
:percent => {
|
19
|
-
:patterns => {
|
20
|
-
:default => format('percent')
|
21
|
-
}
|
22
|
-
},
|
23
|
-
:currency => {
|
24
|
-
:patterns => {
|
25
|
-
:default => format('currency')
|
26
|
-
}
|
27
|
-
},
|
28
|
-
}
|
29
|
-
self[:'numbers.formats.currency.unit'] = unit
|
30
|
-
end
|
31
|
-
|
32
|
-
def currency
|
33
|
-
currency = format('currency')
|
34
|
-
currency.update(:unit => unit) unless unit.empty?
|
35
|
-
currency
|
36
|
-
end
|
37
|
-
|
38
|
-
def symbols
|
39
|
-
select('numbers/symbols/*').inject({}) do |result, node|
|
40
|
-
result[name(node).to_sym] = node.content unless draft?(node)
|
41
|
-
result
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def format(type)
|
46
|
-
select("numbers/#{type}Formats/#{type}FormatLength/#{type}Format/pattern").inject({}) do |result, node|
|
47
|
-
node.content unless draft?(node)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def unit
|
52
|
-
@unit ||= select("numbers/currencyFormats/unitPattern").inject({}) do |result, node|
|
53
|
-
count = node.attribute('count').value rescue 'one'
|
54
|
-
result[count] = node.content
|
55
|
-
result
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/cldr/data/plurals.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
class Cldr
|
4
|
-
module Data
|
5
|
-
class Plurals < String
|
6
|
-
autoload :Grammar, 'cldr/data/plurals/grammar'
|
7
|
-
autoload :Parser, 'cldr/data/plurals/grammar'
|
8
|
-
autoload :Rules, 'cldr/data/plurals/rules'
|
9
|
-
autoload :Rule, 'cldr/data/plurals/rules'
|
10
|
-
autoload :Proposition, 'cldr/data/plurals/rules'
|
11
|
-
autoload :Expression, 'cldr/data/plurals/rules'
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def rules
|
15
|
-
@@rules ||= Rules.parse(source)
|
16
|
-
end
|
17
|
-
|
18
|
-
def source
|
19
|
-
File.read("#{Cldr::Data.dir}/supplemental/plurals.xml")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
attr_reader :locale
|
24
|
-
|
25
|
-
def initialize(locale)
|
26
|
-
@locale = locale
|
27
|
-
super(rule ? ruby : "")
|
28
|
-
end
|
29
|
-
|
30
|
-
def ruby
|
31
|
-
"{ :#{locale} => { :i18n => {:plural => { :keys => #{rule.keys.inspect}, :rule => #{rule.to_ruby} } } } }"
|
32
|
-
end
|
33
|
-
|
34
|
-
def rule
|
35
|
-
@rule = Plurals.rules.rule(locale)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,536 +0,0 @@
|
|
1
|
-
# http://unicode.org/draft/reports/tr35/tr35.html#Language_Plural_Rules
|
2
|
-
#
|
3
|
-
# condition = and_condition ('or' and_condition)*
|
4
|
-
# and_condition = relation ('and' relation)*
|
5
|
-
# relation = is_relation | in_relation | within_relation | 'n' <EOL>
|
6
|
-
# is_relation = expr 'is' ('not')? value
|
7
|
-
# in_relation = expr ('not')? 'in' range
|
8
|
-
# within_relation = expr ('not')? 'within' range
|
9
|
-
# expr = 'n' ('mod' value)?
|
10
|
-
# value = digit+
|
11
|
-
# digit = 0|1|2|3|4|5|6|7|8|9
|
12
|
-
# range = value'..'value
|
13
|
-
|
14
|
-
class Cldr
|
15
|
-
module Data
|
16
|
-
class Plurals
|
17
|
-
module Grammar
|
18
|
-
include Treetop::Runtime
|
19
|
-
|
20
|
-
def root
|
21
|
-
@root || :or_condition
|
22
|
-
end
|
23
|
-
|
24
|
-
module OrCondition0
|
25
|
-
def and_condition
|
26
|
-
elements[1]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
module OrCondition1
|
31
|
-
def and_condition
|
32
|
-
elements[0]
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def _nt_or_condition
|
38
|
-
start_index = index
|
39
|
-
if node_cache[:or_condition].has_key?(index)
|
40
|
-
cached = node_cache[:or_condition][index]
|
41
|
-
@index = cached.interval.end if cached
|
42
|
-
return cached
|
43
|
-
end
|
44
|
-
|
45
|
-
i0, s0 = index, []
|
46
|
-
r1 = _nt_and_condition
|
47
|
-
s0 << r1
|
48
|
-
if r1
|
49
|
-
i3, s3 = index, []
|
50
|
-
if input.index(" or ", index) == index
|
51
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
52
|
-
@index += 4
|
53
|
-
else
|
54
|
-
terminal_parse_failure(" or ")
|
55
|
-
r4 = nil
|
56
|
-
end
|
57
|
-
s3 << r4
|
58
|
-
if r4
|
59
|
-
r5 = _nt_and_condition
|
60
|
-
s3 << r5
|
61
|
-
end
|
62
|
-
if s3.last
|
63
|
-
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
64
|
-
r3.extend(OrCondition0)
|
65
|
-
else
|
66
|
-
self.index = i3
|
67
|
-
r3 = nil
|
68
|
-
end
|
69
|
-
if r3
|
70
|
-
r2 = r3
|
71
|
-
else
|
72
|
-
r2 = instantiate_node(SyntaxNode,input, index...index)
|
73
|
-
end
|
74
|
-
s0 << r2
|
75
|
-
end
|
76
|
-
if s0.last
|
77
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
78
|
-
r0.extend(OrCondition1)
|
79
|
-
else
|
80
|
-
self.index = i0
|
81
|
-
r0 = nil
|
82
|
-
end
|
83
|
-
|
84
|
-
node_cache[:or_condition][start_index] = r0
|
85
|
-
|
86
|
-
return r0
|
87
|
-
end
|
88
|
-
|
89
|
-
module AndCondition0
|
90
|
-
def relation
|
91
|
-
elements[1]
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
module AndCondition1
|
96
|
-
def relation
|
97
|
-
elements[0]
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
def _nt_and_condition
|
103
|
-
start_index = index
|
104
|
-
if node_cache[:and_condition].has_key?(index)
|
105
|
-
cached = node_cache[:and_condition][index]
|
106
|
-
@index = cached.interval.end if cached
|
107
|
-
return cached
|
108
|
-
end
|
109
|
-
|
110
|
-
i0, s0 = index, []
|
111
|
-
r1 = _nt_relation
|
112
|
-
s0 << r1
|
113
|
-
if r1
|
114
|
-
i3, s3 = index, []
|
115
|
-
if input.index(" and ", index) == index
|
116
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
117
|
-
@index += 5
|
118
|
-
else
|
119
|
-
terminal_parse_failure(" and ")
|
120
|
-
r4 = nil
|
121
|
-
end
|
122
|
-
s3 << r4
|
123
|
-
if r4
|
124
|
-
r5 = _nt_relation
|
125
|
-
s3 << r5
|
126
|
-
end
|
127
|
-
if s3.last
|
128
|
-
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
129
|
-
r3.extend(AndCondition0)
|
130
|
-
else
|
131
|
-
self.index = i3
|
132
|
-
r3 = nil
|
133
|
-
end
|
134
|
-
if r3
|
135
|
-
r2 = r3
|
136
|
-
else
|
137
|
-
r2 = instantiate_node(SyntaxNode,input, index...index)
|
138
|
-
end
|
139
|
-
s0 << r2
|
140
|
-
end
|
141
|
-
if s0.last
|
142
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
143
|
-
r0.extend(AndCondition1)
|
144
|
-
else
|
145
|
-
self.index = i0
|
146
|
-
r0 = nil
|
147
|
-
end
|
148
|
-
|
149
|
-
node_cache[:and_condition][start_index] = r0
|
150
|
-
|
151
|
-
return r0
|
152
|
-
end
|
153
|
-
|
154
|
-
def _nt_relation
|
155
|
-
start_index = index
|
156
|
-
if node_cache[:relation].has_key?(index)
|
157
|
-
cached = node_cache[:relation][index]
|
158
|
-
@index = cached.interval.end if cached
|
159
|
-
return cached
|
160
|
-
end
|
161
|
-
|
162
|
-
i0 = index
|
163
|
-
r1 = _nt_is_relation
|
164
|
-
if r1
|
165
|
-
r0 = r1
|
166
|
-
else
|
167
|
-
r2 = _nt_in_relation
|
168
|
-
if r2
|
169
|
-
r0 = r2
|
170
|
-
else
|
171
|
-
r3 = _nt_within_relation
|
172
|
-
if r3
|
173
|
-
r0 = r3
|
174
|
-
else
|
175
|
-
if input.index("n", index) == index
|
176
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
177
|
-
@index += 1
|
178
|
-
else
|
179
|
-
terminal_parse_failure("n")
|
180
|
-
r4 = nil
|
181
|
-
end
|
182
|
-
if r4
|
183
|
-
r0 = r4
|
184
|
-
else
|
185
|
-
self.index = i0
|
186
|
-
r0 = nil
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
node_cache[:relation][start_index] = r0
|
193
|
-
|
194
|
-
return r0
|
195
|
-
end
|
196
|
-
|
197
|
-
module IsRelation0
|
198
|
-
def expr
|
199
|
-
elements[0]
|
200
|
-
end
|
201
|
-
|
202
|
-
def value
|
203
|
-
elements[3]
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
def _nt_is_relation
|
208
|
-
start_index = index
|
209
|
-
if node_cache[:is_relation].has_key?(index)
|
210
|
-
cached = node_cache[:is_relation][index]
|
211
|
-
@index = cached.interval.end if cached
|
212
|
-
return cached
|
213
|
-
end
|
214
|
-
|
215
|
-
i0, s0 = index, []
|
216
|
-
r1 = _nt_expr
|
217
|
-
s0 << r1
|
218
|
-
if r1
|
219
|
-
if input.index(" is ", index) == index
|
220
|
-
r2 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
221
|
-
@index += 4
|
222
|
-
else
|
223
|
-
terminal_parse_failure(" is ")
|
224
|
-
r2 = nil
|
225
|
-
end
|
226
|
-
s0 << r2
|
227
|
-
if r2
|
228
|
-
if input.index("not ", index) == index
|
229
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
230
|
-
@index += 4
|
231
|
-
else
|
232
|
-
terminal_parse_failure("not ")
|
233
|
-
r4 = nil
|
234
|
-
end
|
235
|
-
if r4
|
236
|
-
r3 = r4
|
237
|
-
else
|
238
|
-
r3 = instantiate_node(SyntaxNode,input, index...index)
|
239
|
-
end
|
240
|
-
s0 << r3
|
241
|
-
if r3
|
242
|
-
r5 = _nt_value
|
243
|
-
s0 << r5
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
if s0.last
|
248
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
249
|
-
r0.extend(IsRelation0)
|
250
|
-
else
|
251
|
-
self.index = i0
|
252
|
-
r0 = nil
|
253
|
-
end
|
254
|
-
|
255
|
-
node_cache[:is_relation][start_index] = r0
|
256
|
-
|
257
|
-
return r0
|
258
|
-
end
|
259
|
-
|
260
|
-
module InRelation0
|
261
|
-
def expr
|
262
|
-
elements[0]
|
263
|
-
end
|
264
|
-
|
265
|
-
def range
|
266
|
-
elements[3]
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
def _nt_in_relation
|
271
|
-
start_index = index
|
272
|
-
if node_cache[:in_relation].has_key?(index)
|
273
|
-
cached = node_cache[:in_relation][index]
|
274
|
-
@index = cached.interval.end if cached
|
275
|
-
return cached
|
276
|
-
end
|
277
|
-
|
278
|
-
i0, s0 = index, []
|
279
|
-
r1 = _nt_expr
|
280
|
-
s0 << r1
|
281
|
-
if r1
|
282
|
-
if input.index(" not", index) == index
|
283
|
-
r3 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
284
|
-
@index += 4
|
285
|
-
else
|
286
|
-
terminal_parse_failure(" not")
|
287
|
-
r3 = nil
|
288
|
-
end
|
289
|
-
if r3
|
290
|
-
r2 = r3
|
291
|
-
else
|
292
|
-
r2 = instantiate_node(SyntaxNode,input, index...index)
|
293
|
-
end
|
294
|
-
s0 << r2
|
295
|
-
if r2
|
296
|
-
if input.index(" in ", index) == index
|
297
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
298
|
-
@index += 4
|
299
|
-
else
|
300
|
-
terminal_parse_failure(" in ")
|
301
|
-
r4 = nil
|
302
|
-
end
|
303
|
-
s0 << r4
|
304
|
-
if r4
|
305
|
-
r5 = _nt_range
|
306
|
-
s0 << r5
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
310
|
-
if s0.last
|
311
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
312
|
-
r0.extend(InRelation0)
|
313
|
-
else
|
314
|
-
self.index = i0
|
315
|
-
r0 = nil
|
316
|
-
end
|
317
|
-
|
318
|
-
node_cache[:in_relation][start_index] = r0
|
319
|
-
|
320
|
-
return r0
|
321
|
-
end
|
322
|
-
|
323
|
-
module WithinRelation0
|
324
|
-
def expr
|
325
|
-
elements[0]
|
326
|
-
end
|
327
|
-
|
328
|
-
def range
|
329
|
-
elements[3]
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
def _nt_within_relation
|
334
|
-
start_index = index
|
335
|
-
if node_cache[:within_relation].has_key?(index)
|
336
|
-
cached = node_cache[:within_relation][index]
|
337
|
-
@index = cached.interval.end if cached
|
338
|
-
return cached
|
339
|
-
end
|
340
|
-
|
341
|
-
i0, s0 = index, []
|
342
|
-
r1 = _nt_expr
|
343
|
-
s0 << r1
|
344
|
-
if r1
|
345
|
-
if input.index(" not", index) == index
|
346
|
-
r3 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
347
|
-
@index += 4
|
348
|
-
else
|
349
|
-
terminal_parse_failure(" not")
|
350
|
-
r3 = nil
|
351
|
-
end
|
352
|
-
if r3
|
353
|
-
r2 = r3
|
354
|
-
else
|
355
|
-
r2 = instantiate_node(SyntaxNode,input, index...index)
|
356
|
-
end
|
357
|
-
s0 << r2
|
358
|
-
if r2
|
359
|
-
if input.index(" within ", index) == index
|
360
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index + 8))
|
361
|
-
@index += 8
|
362
|
-
else
|
363
|
-
terminal_parse_failure(" within ")
|
364
|
-
r4 = nil
|
365
|
-
end
|
366
|
-
s0 << r4
|
367
|
-
if r4
|
368
|
-
r5 = _nt_range
|
369
|
-
s0 << r5
|
370
|
-
end
|
371
|
-
end
|
372
|
-
end
|
373
|
-
if s0.last
|
374
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
375
|
-
r0.extend(WithinRelation0)
|
376
|
-
else
|
377
|
-
self.index = i0
|
378
|
-
r0 = nil
|
379
|
-
end
|
380
|
-
|
381
|
-
node_cache[:within_relation][start_index] = r0
|
382
|
-
|
383
|
-
return r0
|
384
|
-
end
|
385
|
-
|
386
|
-
module Expr0
|
387
|
-
def value
|
388
|
-
elements[1]
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
module Expr1
|
393
|
-
end
|
394
|
-
|
395
|
-
def _nt_expr
|
396
|
-
start_index = index
|
397
|
-
if node_cache[:expr].has_key?(index)
|
398
|
-
cached = node_cache[:expr][index]
|
399
|
-
@index = cached.interval.end if cached
|
400
|
-
return cached
|
401
|
-
end
|
402
|
-
|
403
|
-
i0, s0 = index, []
|
404
|
-
if input.index("n", index) == index
|
405
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
406
|
-
@index += 1
|
407
|
-
else
|
408
|
-
terminal_parse_failure("n")
|
409
|
-
r1 = nil
|
410
|
-
end
|
411
|
-
s0 << r1
|
412
|
-
if r1
|
413
|
-
i3, s3 = index, []
|
414
|
-
if input.index(" mod ", index) == index
|
415
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
416
|
-
@index += 5
|
417
|
-
else
|
418
|
-
terminal_parse_failure(" mod ")
|
419
|
-
r4 = nil
|
420
|
-
end
|
421
|
-
s3 << r4
|
422
|
-
if r4
|
423
|
-
r5 = _nt_value
|
424
|
-
s3 << r5
|
425
|
-
end
|
426
|
-
if s3.last
|
427
|
-
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
428
|
-
r3.extend(Expr0)
|
429
|
-
else
|
430
|
-
self.index = i3
|
431
|
-
r3 = nil
|
432
|
-
end
|
433
|
-
if r3
|
434
|
-
r2 = r3
|
435
|
-
else
|
436
|
-
r2 = instantiate_node(SyntaxNode,input, index...index)
|
437
|
-
end
|
438
|
-
s0 << r2
|
439
|
-
end
|
440
|
-
if s0.last
|
441
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
442
|
-
r0.extend(Expr1)
|
443
|
-
else
|
444
|
-
self.index = i0
|
445
|
-
r0 = nil
|
446
|
-
end
|
447
|
-
|
448
|
-
node_cache[:expr][start_index] = r0
|
449
|
-
|
450
|
-
return r0
|
451
|
-
end
|
452
|
-
|
453
|
-
module Range0
|
454
|
-
def value
|
455
|
-
elements[0]
|
456
|
-
end
|
457
|
-
|
458
|
-
def value
|
459
|
-
elements[2]
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
def _nt_range
|
464
|
-
start_index = index
|
465
|
-
if node_cache[:range].has_key?(index)
|
466
|
-
cached = node_cache[:range][index]
|
467
|
-
@index = cached.interval.end if cached
|
468
|
-
return cached
|
469
|
-
end
|
470
|
-
|
471
|
-
i0, s0 = index, []
|
472
|
-
r1 = _nt_value
|
473
|
-
s0 << r1
|
474
|
-
if r1
|
475
|
-
if input.index("..", index) == index
|
476
|
-
r2 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
477
|
-
@index += 2
|
478
|
-
else
|
479
|
-
terminal_parse_failure("..")
|
480
|
-
r2 = nil
|
481
|
-
end
|
482
|
-
s0 << r2
|
483
|
-
if r2
|
484
|
-
r3 = _nt_value
|
485
|
-
s0 << r3
|
486
|
-
end
|
487
|
-
end
|
488
|
-
if s0.last
|
489
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
490
|
-
r0.extend(Range0)
|
491
|
-
else
|
492
|
-
self.index = i0
|
493
|
-
r0 = nil
|
494
|
-
end
|
495
|
-
|
496
|
-
node_cache[:range][start_index] = r0
|
497
|
-
|
498
|
-
return r0
|
499
|
-
end
|
500
|
-
|
501
|
-
def _nt_value
|
502
|
-
start_index = index
|
503
|
-
if node_cache[:value].has_key?(index)
|
504
|
-
cached = node_cache[:value][index]
|
505
|
-
@index = cached.interval.end if cached
|
506
|
-
return cached
|
507
|
-
end
|
508
|
-
|
509
|
-
s0, i0 = [], index
|
510
|
-
loop do
|
511
|
-
if input.index(Regexp.new('[0-9]'), index) == index
|
512
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
513
|
-
@index += 1
|
514
|
-
else
|
515
|
-
r1 = nil
|
516
|
-
end
|
517
|
-
if r1
|
518
|
-
s0 << r1
|
519
|
-
else
|
520
|
-
break
|
521
|
-
end
|
522
|
-
end
|
523
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
524
|
-
|
525
|
-
node_cache[:value][start_index] = r0
|
526
|
-
|
527
|
-
return r0
|
528
|
-
end
|
529
|
-
end
|
530
|
-
end
|
531
|
-
|
532
|
-
class Parser < Treetop::Runtime::CompiledParser
|
533
|
-
include Grammar
|
534
|
-
end
|
535
|
-
end
|
536
|
-
end
|