rdf-turtle 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/History +7 -0
- data/{README.markdown → README.md} +11 -26
- data/VERSION +1 -1
- data/lib/rdf/turtle.rb +1 -2
- data/lib/rdf/turtle/meta.rb +1027 -1175
- data/lib/rdf/turtle/reader.rb +92 -79
- data/lib/rdf/turtle/terminals.rb +31 -31
- data/lib/rdf/turtle/writer.rb +2 -2
- metadata +127 -161
- data/lib/ebnf.rb +0 -638
- data/lib/rdf/ll1/lexer.rb +0 -475
- data/lib/rdf/ll1/parser.rb +0 -541
- data/lib/rdf/ll1/scanner.rb +0 -101
data/lib/rdf/ll1/scanner.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'strscan' unless defined?(StringScanner)
|
2
|
-
|
3
|
-
module RDF::LL1
|
4
|
-
##
|
5
|
-
# Overload StringScanner with file operations
|
6
|
-
#
|
7
|
-
# * Reloads scanner as required until EOF.
|
8
|
-
# * Loads to a high-water and reloads when remaining size reaches a low-water.
|
9
|
-
#
|
10
|
-
# FIXME: Only implements the subset required by the Lexer for now.
|
11
|
-
class Scanner < StringScanner
|
12
|
-
HIGH_WATER = 10240
|
13
|
-
LOW_WATER = 2048 # Hopefully large enough to deal with long multi-line comments
|
14
|
-
|
15
|
-
##
|
16
|
-
# @!attribute [r] input
|
17
|
-
# @return [IO, StringIO]
|
18
|
-
attr_reader :input
|
19
|
-
|
20
|
-
##
|
21
|
-
# Create a scanner, from an IO or String
|
22
|
-
#
|
23
|
-
# @param [String, IO, #read] input
|
24
|
-
# @param [Hash{Symbol => Object}] options
|
25
|
-
# @option options[Integer] :high_water (HIGH_WATER)
|
26
|
-
# @option options[Integer] :low_water (LOW_WATER)
|
27
|
-
# @yield [string]
|
28
|
-
# @yieldparam [String] string data read from input file
|
29
|
-
# @yieldreturn [String] replacement read data, useful for decoding escapes.
|
30
|
-
# @return [Scanner]
|
31
|
-
def initialize(input, options = {}, &block)
|
32
|
-
@block = block
|
33
|
-
@options = options.merge(:high_water => HIGH_WATER, :low_water => LOW_WATER)
|
34
|
-
|
35
|
-
if input.respond_to?(:read)
|
36
|
-
@input = input
|
37
|
-
super("")
|
38
|
-
feed_me
|
39
|
-
else
|
40
|
-
super(input.to_s)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
##
|
45
|
-
# Returns the "rest" of the line, or the next line if at EOL (i.e. everything after the scan pointer).
|
46
|
-
# If there is no more data (eos? = true), it returns "".
|
47
|
-
#
|
48
|
-
# @return [String]
|
49
|
-
def rest
|
50
|
-
feed_me
|
51
|
-
super
|
52
|
-
end
|
53
|
-
|
54
|
-
##
|
55
|
-
# Attempts to skip over the given `pattern` beginning with the scan pointer.
|
56
|
-
# If it matches, the scan pointer is advanced to the end of the match,
|
57
|
-
# and the length of the match is returned. Otherwise, `nil` is returned.
|
58
|
-
#
|
59
|
-
# similar to `scan`, but without returning the matched string.
|
60
|
-
# @param [Regexp] pattern
|
61
|
-
def skip(pattern)
|
62
|
-
feed_me
|
63
|
-
super
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
# Tries to match with `pattern` at the current position.
|
68
|
-
#
|
69
|
-
# If there is a match, the scanner advances the "scan pointer" and returns the matched string.
|
70
|
-
# Otherwise, the scanner returns nil.
|
71
|
-
#
|
72
|
-
# If the scanner begins with the multi-line start expression
|
73
|
-
# @example
|
74
|
-
# s = StringScanner.new('test string')
|
75
|
-
# p s.scan(/\w+/) # -> "test"
|
76
|
-
# p s.scan(/\w+/) # -> nil
|
77
|
-
# p s.scan(/\s+/) # -> " "
|
78
|
-
# p s.scan(/\w+/) # -> "string"
|
79
|
-
# p s.scan(/./) # -> nil
|
80
|
-
#
|
81
|
-
# @param [Regexp] pattern
|
82
|
-
# @return [String]
|
83
|
-
def scan(pattern)
|
84
|
-
feed_me
|
85
|
-
super
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
# Maintain low-water mark
|
90
|
-
def feed_me
|
91
|
-
if rest_size < @options[:low_water] && @input && !@input.eof?
|
92
|
-
# Read up to high-water mark ensuring we're at an end of line
|
93
|
-
diff = @options[:high_water] - rest_size
|
94
|
-
string = @input.read(diff)
|
95
|
-
string << @input.gets unless @input.eof?
|
96
|
-
string = @block.call(string) if @block
|
97
|
-
self << string if string
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|