ebnf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/CREDITS +0 -0
- data/README.md +170 -0
- data/UNLICENSE +24 -0
- data/VERSION +1 -0
- data/bin/ebnf +54 -0
- data/etc/doap.ttl +33 -0
- data/etc/ebnf.bnf +54 -0
- data/lib/ebnf.rb +1029 -0
- data/lib/ebnf/ll1/lexer.rb +475 -0
- data/lib/ebnf/ll1/parser.rb +541 -0
- data/lib/ebnf/ll1/scanner.rb +101 -0
- data/lib/ebnf/version.rb +20 -0
- metadata +125 -0
@@ -0,0 +1,101 @@
|
|
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
|
data/lib/ebnf/version.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module EBNF
|
2
|
+
module VERSION
|
3
|
+
VERSION_FILE = File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "VERSION")
|
4
|
+
MAJOR, MINOR, TINY, EXTRA = File.read(VERSION_FILE).chomp.split(".")
|
5
|
+
|
6
|
+
STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
|
7
|
+
|
8
|
+
##
|
9
|
+
# @return [String]
|
10
|
+
def self.to_s() STRING end
|
11
|
+
|
12
|
+
##
|
13
|
+
# @return [String]
|
14
|
+
def self.to_str() STRING end
|
15
|
+
|
16
|
+
##
|
17
|
+
# @return [Array(Integer, Integer, Integer)]
|
18
|
+
def self.to_a() [MAJOR, MINOR, TINY] end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ebnf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gregg Kellogg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sxp
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.12.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.12.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.8.3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: EBNF is a Ruby parser for W3C EBNF and a parser generator for compliant
|
79
|
+
LL(1) grammars.
|
80
|
+
email: public-rdf-ruby@w3.org
|
81
|
+
executables:
|
82
|
+
- ebnf
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- AUTHORS
|
87
|
+
- CREDITS
|
88
|
+
- README.md
|
89
|
+
- UNLICENSE
|
90
|
+
- VERSION
|
91
|
+
- lib/ebnf/ll1/lexer.rb
|
92
|
+
- lib/ebnf/ll1/parser.rb
|
93
|
+
- lib/ebnf/ll1/scanner.rb
|
94
|
+
- lib/ebnf/version.rb
|
95
|
+
- lib/ebnf.rb
|
96
|
+
- etc/doap.ttl
|
97
|
+
- etc/ebnf.bnf
|
98
|
+
- bin/ebnf
|
99
|
+
homepage: http://github.com/gkellogg/ebnf
|
100
|
+
licenses:
|
101
|
+
- Public Domain
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 1.9.3
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.8.25
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: EBNF parser and parser generator.
|
124
|
+
test_files: []
|
125
|
+
has_rdoc: false
|