From 20433e3ad229a1b0bc1e0cba6e7508d0c1ab4707 Mon Sep 17 00:00:00 2001 From: Nigel Thorne Date: Wed, 4 Jun 2014 21:48:32 +1000 Subject: [PATCH] Change to NigelThorne fork to detect infinite loops and fixed grammar to ignore missing parameter list. --- Gemfile | 5 ++- Gemfile.lock | 73 +++++++++++++++++++++++++++++-- lib/parser/crystal.rb | 3 +- lib/parser/function_definition.rb | 2 +- lib/parser/module_definition.rb | 4 +- 5 files changed, 79 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 80c17c72..e6867a8c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,11 @@ source "http://rubygems.org" -gem "parslet" , "~> 1.6.1" +gem "parslet" , :git => 'https://github.com/NigelThorne/parslet.git' group :development do gem "minitest" gem "simplecov" + gem "jeweler" + gem "roodi" + gem 'pry' end diff --git a/Gemfile.lock b/Gemfile.lock index c3d7f5c7..d0a3c2b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,22 +1,89 @@ +GIT + remote: https://github.com/NigelThorne/parslet.git + revision: be698466bfa21a35d838fc7d3cd741b8aa1977b0 + specs: + parslet (1.7.0) + blankslate (~> 2.0) + GEM remote: http://rubygems.org/ specs: + addressable (2.3.6) blankslate (2.1.2.4) + builder (3.2.2) + coderay (1.1.0) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) docile (1.1.3) + faraday (0.9.0) + multipart-post (>= 1.2, < 3) + git (1.2.6) + github_api (0.11.3) + addressable (~> 2.3) + descendants_tracker (~> 0.0.1) + faraday (~> 0.8, < 0.10) + hashie (>= 1.2) + multi_json (>= 1.7.5, < 2.0) + nokogiri (~> 1.6.0) + oauth2 + hashie (2.1.1) + highline (1.6.21) + jeweler (2.0.1) + builder + bundler (>= 1.0) + git (>= 1.2.5) + github_api + highline (>= 1.6.15) + nokogiri (>= 1.5.10) + rake + rdoc + json (1.8.1) + jwt (1.0.0) + method_source (0.8.2) + mini_portile (0.6.0) minitest (5.3.2) multi_json (1.9.2) - parslet (1.6.1) - blankslate (~> 2.0) + multi_xml (0.5.5) + multipart-post (2.0.0) + nokogiri (1.6.2.1) + mini_portile (= 0.6.0) + nokogiri (1.6.2.1-x64-mingw32) + mini_portile (= 0.6.0) + oauth2 (0.9.4) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (~> 1.2) + pry (0.9.12.6) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + rack (1.5.2) + rake (10.3.2) + rdoc (4.1.1) + json (~> 1.4) + roodi (4.0.0) + ruby_parser (~> 3.2, >= 3.2.2) + ruby_parser (3.6.1) + sexp_processor (~> 4.1) + sexp_processor (4.4.3) simplecov (0.8.2) docile (~> 1.1.0) multi_json simplecov-html (~> 0.8.0) simplecov-html (0.8.0) + slop (3.5.0) + thread_safe (0.3.4) PLATFORMS ruby + x64-mingw32 DEPENDENCIES + jeweler minitest - parslet (~> 1.6.1) + parslet! + pry + roodi simplecov diff --git a/lib/parser/crystal.rb b/lib/parser/crystal.rb index 9a95d7b2..bb52818d 100644 --- a/lib/parser/crystal.rb +++ b/lib/parser/crystal.rb @@ -31,6 +31,7 @@ module Parser include Operators include ModuleDef - rule(:root){ (module_definition | class_definition | function_definition | expression | call_site ).repeat } + rule(:root_body) {(module_definition | class_definition | function_definition | expression | call_site )} + rule(:root) { root_body.repeat() } end end diff --git a/lib/parser/function_definition.rb b/lib/parser/function_definition.rb index dd7fdb2b..1aa1815c 100644 --- a/lib/parser/function_definition.rb +++ b/lib/parser/function_definition.rb @@ -4,7 +4,7 @@ module Parser rule(:function_definition) { keyword_def >> ((module_name|instance_variable|name).as(:receiver) >> str(".")).maybe >> #possibly qualified - name.as(:function_name) >> parmeter_list >> newline >> expressions_end >> newline + name.as(:function_name) >> parmeter_list.maybe >> newline >> expressions_end >> newline } rule(:parmeter_list) { diff --git a/lib/parser/module_definition.rb b/lib/parser/module_definition.rb index 146557d7..023685fd 100644 --- a/lib/parser/module_definition.rb +++ b/lib/parser/module_definition.rb @@ -3,12 +3,12 @@ module Parser include Parslet rule(:module_definition) do keyword_module >> module_name >> eol >> - ( (keyword_end.absent? >> root).repeat(1)).as(:module_expressions) >> keyword_end >> newline + ( (keyword_end.absent? >> root_body).repeat()).as(:module_expressions) >> keyword_end >> newline end rule(:class_definition) do keyword_class >> module_name >> eol >> - ( (keyword_end.absent? >> root).repeat(1)).as(:class_expressions) >> keyword_end >> newline + ( (keyword_end.absent? >> root_body).repeat()).as(:class_expressions) >> keyword_end >> newline end end