Skip to content

Commit

Permalink
Finish 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jun 19, 2020
2 parents f9dd085 + 405ea0e commit 1a76231
Show file tree
Hide file tree
Showing 99 changed files with 20,741 additions and 59,210 deletions.
2 changes: 1 addition & 1 deletion .yardopts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CREDITS
VERSION
UNLICENSE
etc/ebnf.ebnf
etc/ebnf.sxp
etc/ebnf.ll1.sxp
etc/ebnf.peg.sxp
examples/**/README.md
examples/**/*.rb
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ group :development do
gem "byebug", platforms: :mri
gem 'psych', platforms: [:mri, :rbx]
gem "redcarpet", platforms: :mri
gem "rocco", platforms: :mri
gem "pygmentize", platforms: :mri
end

group :development, :test do
gem 'simplecov', platforms: :mri
gem 'coveralls', '~> 0.8', platforms: :mri
gem 'awesome_print', github: 'MatthiasWinkelmann/awesome_print'
end
345 changes: 160 additions & 185 deletions README.md

Large diffs are not rendered by default.

92 changes: 74 additions & 18 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,43 +40,99 @@ namespace :doc do
YARD::Rake::YardocTask.new
end

desc 'Create versions of ebnf files in etc'
task etc: %w{
etc/ebnf.sxp etc/ebnf.ll1.sxp etc/ebnf.html etc/ebnf.rb
etc/turtle.sxp etc/turtle.ll1.sxp etc/turtle.html etc/turtle.rb
etc/sparql.sxp etc/sparql.ll1.sxp etc/sparql.html etc/sparql.rb
namespace :etc do
ETC_FILES = %w{
etc/ebnf.sxp etc/ebnf.ll1.sxp etc/ebnf.peg.sxp etc/ebnf.html etc/ebnf.ll1.rb etc/ebnf.peg.rb
etc/turtle.sxp etc/turtle.ll1.sxp etc/turtle.peg.sxp etc/turtle.html etc/turtle.peg.rb etc/turtle.ll1.rb
etc/sparql.sxp etc/sparql.ll1.sxp etc/sparql.peg.sxp etc/sparql.html etc/sparql.peg.rb etc/turtle.ll1.rb
}
desc 'Remove generated files in etc'
task :clean do
%x(rm #{ETC_FILES.join(' ')})
end

desc 'Create versions of ebnf files in etc'
task build: ETC_FILES
end


# Build SXP output with leading space to allow for Markdown formatting.
rule ".sxp" => %w{.ebnf} do |t|
puts "build #{t.name}"
%x(bin/ebnf -o #{t.name} #{t.source})
File.open(t.name, "w") do |f|
IO.popen(%(bin/ebnf #{t.source})).each_line do |line|
f.puts ' ' + line
end
end
end

rule ".peg.sxp" => %w{.ebnf} do |t|
puts "build #{t.name}"
File.open(t.name, "w") do |f|
IO.popen(%(bin/ebnf --peg #{t.source})).each_line do |line|
f.puts ' ' + line
end
end
end

rule ".html" => %w{.ebnf} do |t|
puts "build #{t.name}"
%x(bin/ebnf --format html -o #{t.name} #{t.source})
end

file "etc/ebnf.ll1.sxp" => "etc/ebnf.ebnf" do
%x(bin/ebnf --ll1 ebnf -o etc/ebnf.ll1.sxp etc/ebnf.ebnf)
file "etc/ebnf.ll1.sxp" => "etc/ebnf.ebnf" do |t|
puts "build #{t.name}"
File.open(t.name, "w") do |f|
IO.popen(%(bin/ebnf --ll1 ebnf #{t.source})).each_line do |line|
f.puts ' ' + line
end
end
end

file "etc/ebnf.rb" => "etc/ebnf.ebnf" do
%x(bin/ebnf --ll1 ebnf -f rb -o etc/ebnf.rb etc/ebnf.ebnf)
file "etc/ebnf.peg.rb" => "etc/ebnf.ebnf" do |t|
puts "build #{t.name}"
%x(bin/ebnf --peg -f rb -o etc/ebnf.peg.rb etc/ebnf.ebnf)
end

file "etc/turtle.ll1.sxp" => "etc/turtle.ebnf" do
%x(bin/ebnf --ll1 turtleDoc -o etc/turtle.ll1.sxp etc/turtle.ebnf)
file "etc/ebnf.ll1.rb" => "etc/ebnf.ebnf" do |t|
puts "build #{t.name}"
%x(bin/ebnf --ll1 ebnf -f rb -o etc/ebnf.ll1.rb etc/ebnf.ebnf)
end

file "etc/turtle.rb" => "etc/turtle.ebnf" do
%x(bin/ebnf --ll1 turtleDoc -f rb -o etc/turtle.rb etc/turtle.ebnf)
file "etc/turtle.ll1.sxp" => "etc/turtle.ebnf" do |t|
puts "build #{t.name}"
File.open(t.name, "w") do |f|
IO.popen(%(bin/ebnf --ll1 turtleDoc #{t.source})).each_line do |line|
f.puts ' ' + line
end
end
end

file "etc/sparql.ll1.sxp" => "etc/sparql.ebnf" do
%x(bin/ebnf --ll1 QueryUnit --ll1 UpdateUnit -o etc/sparql.ll1.sxp etc/sparql.ebnf)
file "etc/turtle.peg.rb" => "etc/turtle.ebnf" do |t|
puts "build #{t.name}"
%x(bin/ebnf --peg -f rb -o etc/turtle.peg.rb etc/turtle.ebnf)
end

file "etc/sparql.rb" => "etc/sparql.ebnf" do
%x(bin/ebnf --ll1 QueryUnit --ll1 UpdateUnit -f rb -o etc/sparql.rb etc/sparql.ebnf)
file "etc/turtle.ll1.rb" => "etc/turtle.ebnf" do |t|
puts "build #{t.name}"
%x(bin/ebnf --ll1 turtleDoc -f rb -o etc/turtle.ll1.rb etc/turtle.ebnf)
end

file "etc/sparql.ll1.sxp" => "etc/sparql.ebnf" do |t|
puts "build #{t.name}"
File.open(t.name, "w") do |f|
IO.popen(%(bin/ebnf --ll1 QueryUnit --ll1 UpdateUnit #{t.source})).each_line do |line|
f.puts ' ' + line
end
end
end

file "etc/sparql.peg.rb" => "etc/sparql.ebnf" do |t|
puts "build #{t.name}"
%x(bin/ebnf --peg -f rb -o etc/sparql.peg.rb etc/sparql.ebnf)
end

file "etc/sparql.ll1.rb" => "etc/sparql.ebnf" do |t|
puts "build #{t.name}"
%x(bin/ebnf --ll1 QueryUnit --ll1 UpdateUnit -f rb -o etc/sparql.ll1.rb etc/sparql.ebnf)
end
2 changes: 1 addition & 1 deletion UNLICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
For more information, please refer to <https://unlicense.org/>
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
2.0.0
9 changes: 6 additions & 3 deletions bin/ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ OPT_ARGS = [
["--input-format", GetoptLong::REQUIRED_ARGUMENT,"Specify input format one of ebnf or sxp"],
["--mod-name", GetoptLong::REQUIRED_ARGUMENT,"Module name used when creating ruby tables"],
["--output", "-o", GetoptLong::REQUIRED_ARGUMENT,"Output to the specified file path"],
["--peg", GetoptLong::NO_ARGUMENT, "Transform EBNF to PEG"],
["--prefix", "-p", GetoptLong::REQUIRED_ARGUMENT,"Prefix to use when generating Turtle"],
["--progress", "-v", GetoptLong::NO_ARGUMENT, "Detail on execution"],
["--namespace", "-n", GetoptLong::REQUIRED_ARGUMENT,"Namespace to use when generating Turtle"],
Expand Down Expand Up @@ -58,25 +59,27 @@ opts.each do |opt, arg|
when '--evaluate' then input = arg
when '--input-format' then options[:format] = arg.to_sym
when '--format' then options[:output_format] = arg.to_sym
when '--ll1' then (options[:ll1] ||= []) <<arg.to_sym
when '--ll1' then (options[:ll1] ||= []) << arg.to_sym
when '--mod-name' then options[:mod_name] = arg
when '--output' then out = File.open(arg, "w")
when '--peg' then options[:peg] = true
when '--prefix' then options[:prefix] = arg
when '--namespace' then options[:namespace] = arg
when '--progress' then options[:progress] = true
when '--help' then usage
end
end

if options[:output_format] == :rb && !options[:ll1]
STDERR.puts "outputing in .rb format requires -ll"
if options[:output_format] == :rb && !(options[:ll1] || options[:peg])
STDERR.puts "outputing in .rb format requires --ll or --peg"
exit(1)
end

input = File.open(ARGV[0]) if ARGV[0]

ebnf = EBNF.parse(input || STDIN, **options)
ebnf.make_bnf if options[:bnf] || options[:ll1]
ebnf.make_peg if options[:peg]
if options[:ll1]
ebnf.first_follow(*options[:ll1])
ebnf.build_tables
Expand Down
3 changes: 2 additions & 1 deletion ebnf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
gem.date = File.mtime('VERSION').strftime('%Y-%m-%d')

gem.name = "ebnf"
gem.homepage = "http://github.com/dryruby/ebnf"
gem.homepage = "https://github.com/dryruby/ebnf"
gem.license = 'Unlicense'
gem.summary = "EBNF parser and parser generator."
gem.description = %q{EBNF is a Ruby parser for W3C EBNF and a parser generator for compliant LL(1) grammars.}
Expand All @@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = '>= 2.4'
gem.requirements = []
gem.add_runtime_dependency 'sxp', '~> 1.1'
gem.add_runtime_dependency 'scanf', '~> 1.0'
gem.add_runtime_dependency 'rdf', '~> 3.1' # Required by sxp
gem.add_development_dependency 'rdf-spec', '~> 3.1'
gem.add_development_dependency 'haml', '~> 5.0'
Expand Down
Empty file added ebnf.rb
Empty file.
25 changes: 13 additions & 12 deletions etc/doap.ttl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@base <https://rubygems.org/gems/ebnf> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix dc: <http://purl.org/dc/terms/> .
Expand All @@ -7,26 +8,26 @@
@prefix ex: <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://rubygems.org/gems/ebnf> a doap:Project, earl:TestSubject, earl:Software ;
<> a doap:Project, earl:TestSubject, earl:Software ;
doap:name "ebnf" ;
doap:homepage <http://dryruby.github.com/ebnf> ;
doap:license <http://creativecommons.org/licenses/publicdomain/> ;
doap:homepage <https://github.com/dryruby/ebnf> ;
doap:license <https://unlicense.org/1.0/> ;
doap:shortdesc "EBNF parser and parser generator"@en ;
doap:description "EBNF is a Ruby parser for W3C EBNF and a parser generator for compliant LL(1) grammars."@en ;
doap:created "2011-08-29"^^xsd:date ;
doap:programming-language "Ruby" ;
doap:implements <http://dbpedia.org/resource/Compiler-compiler> ;
doap:category <http://dbpedia.org/resource/Resource_Description_Framework>,
<http://dbpedia.org/resource/Ruby_(programming_language)> ;
doap:download-page <http://rubygems.org/gems/ebnf> ;
doap:mailing-list <http://lists.w3.org/Archives/Public/public-rdf-ruby/> ;
doap:bug-database <http://github.com/dryruby/ebnf/issues> ;
doap:blog <http://greggkellogg.net/> ;
doap:developer <http://greggkellogg.net/foaf#me> ;
doap:maintainer <http://greggkellogg.net/foaf#me> ;
doap:documenter <http://greggkellogg.net/foaf#me> ;
foaf:maker <http://greggkellogg.net/foaf#me> ;
doap:download-page <> ;
doap:mailing-list <https://lists.w3.org/Archives/Public/public-rdf-ruby/> ;
doap:bug-database <https://github.com/dryruby/ebnf/issues> ;
doap:blog <https://greggkellogg.net/> ;
doap:developer <https://greggkellogg.net/foaf#me> ;
doap:maintainer <https://greggkellogg.net/foaf#me> ;
doap:documenter <https://greggkellogg.net/foaf#me> ;
foaf:maker <https://greggkellogg.net/foaf#me> ;
dc:title "ebnf" ;
dc:description "EBNF is a Ruby parser for W3C EBNF and a parser generator for compliant LL(1) grammars."@en ;
dc:date "2011-08-29"^^xsd:date ;
dc:creator <http://greggkellogg.net/foaf#me> .
dc:creator <https://greggkellogg.net/foaf#me> .
32 changes: 13 additions & 19 deletions etc/ebnf.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

[3] rule ::= LHS expression

# Use a terminal to match the identifier, rule name and assignment due to
# confusion between the identifier RANGE
# Use the LHS terminal to match the identifier, rule name and assignment due to
# confusion between the identifier and RANGE

[4] expression ::= alt

Expand All @@ -32,40 +32,34 @@

@terminals

[11] LHS ::= ('[' SYMBOL+ ']')? SYMBOL "::="
[11] LHS ::= ('[' SYMBOL+ ']' ' '+)? SYMBOL ' '* '::='

[12] SYMBOL ::= ([a-z] | [A-Z] | [0-9] | "_" | ".")+
[12] SYMBOL ::= ([a-z] | [A-Z] | [0-9] | '_' | '.')+

[13] HEX ::= '#x' ([0-9]|[a-f]|[A-F])+
[13] HEX ::= '#x' ([a-f] | [A-F] | [0-9])+

[14] ENUM ::= '[' ((R_BEGIN (HEX | R_CHAR)) | (HEX | R_CHAR)) '-' ((R_BEGIN (HEX | R_CHAR)) | (HEX | R_CHAR)) ']'
[14] ENUM ::= ('[' R_CHAR+ | HEX+ ']') - LHS

[15] O_ENUM ::= '[^' ((R_BEGIN (HEX | R_CHAR)) | (HEX | R_CHAR)) '-' ((R_BEGIN (HEX | R_CHAR)) | (HEX | R_CHAR)) ']'
[15] O_ENUM ::= '[^' R_CHAR+ | HEX+ ']'

# Range is any combination of R_CHAR '-' R_CHAR or R_CHAR+
[16] RANGE ::= '[' ((R_BEGIN (HEX | R_CHAR)) | (HEX | R_CHAR))+ ']'
[16] RANGE ::= '[' (R_CHAR '-' R_CHAR) | (HEX - HEX) ']'

# Range is any combination of R_CHAR '-' R_CHAR or R_CHAR+ preceded by ^
[17] O_RANGE ::= '[^' ((R_BEGIN (HEX | R_CHAR)) | (HEX | R_CHAR))+ ']'
[17] O_RANGE ::= '[^' (R_CHAR '-' R_CHAR) | (HEX - HEX) ']'

# Strings are unescaped Unicode, excepting control characters and hash (#)
[18] STRING1 ::= '"' (CHAR - '"')* '"'

[19] STRING2 ::= "'" (CHAR - "'")* "'"

[20] CHAR ::= HEX
| [#x20#x21#x22]
| [#x24-#x00FFFFFF]
[20] CHAR ::= [#x9#xA#xD] | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

[21] R_CHAR ::= CHAR - ']'

[22] R_BEGIN ::= (HEX | R_CHAR) "-"

# Should be able to do this inline, but not until terminal regular expressions are created automatically
[23] POSTFIX ::= [?*+]
[22] POSTFIX ::= [?*+]

[24] PASS ::= ( [#x00-#x20]
| ( '#' | '//' ) [^#x0A#x0D]*
[23] PASS ::= ( [#x00-#x20]
| ( ('#' - '#x') | '//' ) [^#x0A#x0Dx]*
| '/*' (( '*' [^/] )? | [^*] )* '*/'
| '(*' (( '*' [^)] )? | [^*] )* '*)'
)+
Expand Down

0 comments on commit 1a76231

Please sign in to comment.