mutant-melbourne 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/LICENSE +25 -0
  2. data/README.md +69 -0
  3. data/Rakefile +14 -0
  4. data/ext/melbourne/.gitignore +3 -0
  5. data/ext/melbourne/bstring-license.txt +29 -0
  6. data/ext/melbourne/bstrlib.c +2687 -0
  7. data/ext/melbourne/bstrlib.h +267 -0
  8. data/ext/melbourne/encoding_compat.cpp +188 -0
  9. data/ext/melbourne/encoding_compat.hpp +57 -0
  10. data/ext/melbourne/extconf.rb +87 -0
  11. data/ext/melbourne/grammar18.cpp +11280 -0
  12. data/ext/melbourne/grammar18.hpp +13 -0
  13. data/ext/melbourne/grammar18.y +6088 -0
  14. data/ext/melbourne/grammar19.cpp +12420 -0
  15. data/ext/melbourne/grammar19.hpp +11 -0
  16. data/ext/melbourne/grammar19.y +7113 -0
  17. data/ext/melbourne/lex.c.blt +152 -0
  18. data/ext/melbourne/lex.c.tab +136 -0
  19. data/ext/melbourne/local_state.hpp +43 -0
  20. data/ext/melbourne/melbourne.cpp +88 -0
  21. data/ext/melbourne/melbourne.hpp +19 -0
  22. data/ext/melbourne/node18.hpp +262 -0
  23. data/ext/melbourne/node19.hpp +271 -0
  24. data/ext/melbourne/node_types.rb +304 -0
  25. data/ext/melbourne/node_types18.cpp +255 -0
  26. data/ext/melbourne/node_types18.hpp +129 -0
  27. data/ext/melbourne/node_types19.cpp +249 -0
  28. data/ext/melbourne/node_types19.hpp +126 -0
  29. data/ext/melbourne/parser_state18.hpp +181 -0
  30. data/ext/melbourne/parser_state19.hpp +251 -0
  31. data/ext/melbourne/quark.cpp +42 -0
  32. data/ext/melbourne/quark.hpp +45 -0
  33. data/ext/melbourne/symbols.cpp +224 -0
  34. data/ext/melbourne/symbols.hpp +119 -0
  35. data/ext/melbourne/var_table18.cpp +83 -0
  36. data/ext/melbourne/var_table18.hpp +33 -0
  37. data/ext/melbourne/var_table19.cpp +65 -0
  38. data/ext/melbourne/var_table19.hpp +35 -0
  39. data/ext/melbourne/visitor18.cpp +963 -0
  40. data/ext/melbourne/visitor18.hpp +12 -0
  41. data/ext/melbourne/visitor19.cpp +960 -0
  42. data/ext/melbourne/visitor19.hpp +15 -0
  43. data/lib/compiler/ast/constants.rb +81 -0
  44. data/lib/compiler/ast/control_flow.rb +290 -0
  45. data/lib/compiler/ast/data.rb +14 -0
  46. data/lib/compiler/ast/definitions.rb +749 -0
  47. data/lib/compiler/ast/encoding.rb +18 -0
  48. data/lib/compiler/ast/exceptions.rb +138 -0
  49. data/lib/compiler/ast/file.rb +11 -0
  50. data/lib/compiler/ast/grapher.rb +89 -0
  51. data/lib/compiler/ast/literals.rb +207 -0
  52. data/lib/compiler/ast/node.rb +362 -0
  53. data/lib/compiler/ast/operators.rb +106 -0
  54. data/lib/compiler/ast/self.rb +15 -0
  55. data/lib/compiler/ast/sends.rb +615 -0
  56. data/lib/compiler/ast/transforms.rb +298 -0
  57. data/lib/compiler/ast/values.rb +88 -0
  58. data/lib/compiler/ast/variables.rb +351 -0
  59. data/lib/compiler/ast.rb +20 -0
  60. data/lib/compiler/locals.rb +109 -0
  61. data/lib/melbourne/processor.rb +651 -0
  62. data/lib/melbourne/version.rb +3 -0
  63. data/lib/melbourne.rb +143 -0
  64. metadata +112 -0
data/lib/melbourne.rb ADDED
@@ -0,0 +1,143 @@
1
+ unless(defined?(RUBY_ENGINE) and RUBY_ENGINE == 'rbx')
2
+ module Rubinius
3
+
4
+ unless singleton_methods.map { |name| name.to_s }.include?('ruby18?')
5
+
6
+ # Test if running under 1.8 mode
7
+ #
8
+ # @return [true]
9
+ # if ruby version is lower than 1.9.0
10
+ #
11
+ # @return [false]
12
+ # otherwise
13
+ #
14
+ # @api private
15
+ #
16
+ def self.ruby18?
17
+ RUBY_VERSION < '1.9.0'
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+ require "melbourne.so"
25
+ require "melbourne/processor"
26
+
27
+ class String
28
+ def to_ast(name="(eval)", line=1)
29
+ Rubinius::Melbourne.parse_string self, name, line
30
+ end
31
+
32
+ def to_sexp(name="(eval)", line=1)
33
+ to_ast(name, line).to_sexp
34
+ end
35
+ end
36
+
37
+ class File
38
+ def self.to_ast(name, line=1)
39
+ Rubinius::Melbourne.parse_file name, line
40
+ end
41
+
42
+ def self.to_sexp(name, line=1)
43
+ to_ast(name, line).to_sexp
44
+ end
45
+ end
46
+
47
+ module Rubinius
48
+ class Melbourne
49
+ attr_accessor :transforms
50
+ attr_accessor :magic_handler
51
+ attr_accessor :references
52
+ attr_reader :pre_exe
53
+
54
+ def self.parse_string(string, name="(eval)", line=1)
55
+ system_parser.new(name, line).parse_string string
56
+ end
57
+
58
+ def self.parse_file(name, line=1)
59
+ system_parser.new(name, line).parse_file
60
+ end
61
+
62
+ def self.system_parser
63
+ case RUBY_VERSION
64
+ when /1\.8/
65
+ Melbourne
66
+ when /1\.9/
67
+ Melbourne19
68
+ else
69
+ raise Exception, "No parser configured for Ruby version #{RUBY_VERSION}."
70
+ end
71
+ end
72
+
73
+ def initialize(name, line, transforms=[])
74
+ @name = name
75
+ @line = line
76
+ @transforms = transforms
77
+ @magic_handler = nil
78
+ @data_offset = nil
79
+ @pre_exe = []
80
+
81
+ # There can be multiple reported, we need to track them all.
82
+ @syntax_errors = []
83
+ end
84
+
85
+ attr_reader :syntax_errors
86
+
87
+ def add_pre_exe(node)
88
+ @pre_exe << node if node
89
+ end
90
+
91
+ def add_magic_comment(str)
92
+ if @magic_handler
93
+ @magic_handler.add_magic_comment str
94
+ end
95
+ end
96
+
97
+ def process_data(offset)
98
+ @data_offset = offset
99
+ end
100
+
101
+ def syntax_error
102
+ raise @syntax_errors[0] unless @syntax_errors.empty?
103
+ end
104
+
105
+ alias_method :file_to_ast, :file_to_ast_18
106
+ alias_method :string_to_ast, :string_to_ast_18
107
+
108
+ def parse_string(string)
109
+ syntax_error unless ast = string_to_ast(string, @name, @line)
110
+ ast
111
+ end
112
+
113
+ def parse_file
114
+ unless @name and File.exists? @name
115
+ raise Errno::ENOENT, @name.inspect
116
+ end
117
+
118
+ syntax_error unless ast = file_to_ast(@name, @line)
119
+ ast = AST::EndData.new @data_offset, ast if @data_offset
120
+ ast
121
+ end
122
+
123
+ def process_transforms(line, receiver, name, arguments, privately=false)
124
+ @transforms.each do |transform|
125
+ next unless transform.transform_kind == :call
126
+
127
+ if node = transform.match?(line, receiver, name, arguments, privately)
128
+ unless node.kind_of? AST::Node
129
+ node = transform.new line, receiver, name, arguments, privately
130
+ end
131
+ return node
132
+ end
133
+ end
134
+ nil
135
+ end
136
+ end
137
+
138
+ class Melbourne19 < Melbourne
139
+ alias_method :file_to_ast, :file_to_ast_19
140
+ alias_method :string_to_ast, :string_to_ast_19
141
+ end
142
+ end
143
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mutant-melbourne
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Evan Phoenix
9
+ - Bryan Ford
10
+ - Bryan Helmkamp
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-12-07 00:00:00.000000000 Z
15
+ dependencies: []
16
+ description: An extraction of the Melrbourne Ruby 1.8 and 1.9 parser and AST from
17
+ Rubinius
18
+ email: bryan@brynary.com
19
+ executables: []
20
+ extensions:
21
+ - ext/melbourne/extconf.rb
22
+ extra_rdoc_files: []
23
+ files:
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - ext/melbourne/.gitignore
28
+ - ext/melbourne/bstring-license.txt
29
+ - ext/melbourne/bstrlib.c
30
+ - ext/melbourne/bstrlib.h
31
+ - ext/melbourne/encoding_compat.cpp
32
+ - ext/melbourne/encoding_compat.hpp
33
+ - ext/melbourne/extconf.rb
34
+ - ext/melbourne/grammar18.cpp
35
+ - ext/melbourne/grammar18.hpp
36
+ - ext/melbourne/grammar18.y
37
+ - ext/melbourne/grammar19.cpp
38
+ - ext/melbourne/grammar19.hpp
39
+ - ext/melbourne/grammar19.y
40
+ - ext/melbourne/lex.c.blt
41
+ - ext/melbourne/lex.c.tab
42
+ - ext/melbourne/local_state.hpp
43
+ - ext/melbourne/melbourne.cpp
44
+ - ext/melbourne/melbourne.hpp
45
+ - ext/melbourne/node18.hpp
46
+ - ext/melbourne/node19.hpp
47
+ - ext/melbourne/node_types.rb
48
+ - ext/melbourne/node_types18.cpp
49
+ - ext/melbourne/node_types18.hpp
50
+ - ext/melbourne/node_types19.cpp
51
+ - ext/melbourne/node_types19.hpp
52
+ - ext/melbourne/parser_state18.hpp
53
+ - ext/melbourne/parser_state19.hpp
54
+ - ext/melbourne/quark.cpp
55
+ - ext/melbourne/quark.hpp
56
+ - ext/melbourne/symbols.cpp
57
+ - ext/melbourne/symbols.hpp
58
+ - ext/melbourne/var_table18.cpp
59
+ - ext/melbourne/var_table18.hpp
60
+ - ext/melbourne/var_table19.cpp
61
+ - ext/melbourne/var_table19.hpp
62
+ - ext/melbourne/visitor18.cpp
63
+ - ext/melbourne/visitor18.hpp
64
+ - ext/melbourne/visitor19.cpp
65
+ - ext/melbourne/visitor19.hpp
66
+ - lib/compiler/ast.rb
67
+ - lib/compiler/ast/constants.rb
68
+ - lib/compiler/ast/control_flow.rb
69
+ - lib/compiler/ast/data.rb
70
+ - lib/compiler/ast/definitions.rb
71
+ - lib/compiler/ast/encoding.rb
72
+ - lib/compiler/ast/exceptions.rb
73
+ - lib/compiler/ast/file.rb
74
+ - lib/compiler/ast/grapher.rb
75
+ - lib/compiler/ast/literals.rb
76
+ - lib/compiler/ast/node.rb
77
+ - lib/compiler/ast/operators.rb
78
+ - lib/compiler/ast/self.rb
79
+ - lib/compiler/ast/sends.rb
80
+ - lib/compiler/ast/transforms.rb
81
+ - lib/compiler/ast/values.rb
82
+ - lib/compiler/ast/variables.rb
83
+ - lib/compiler/locals.rb
84
+ - lib/melbourne.rb
85
+ - lib/melbourne/processor.rb
86
+ - lib/melbourne/version.rb
87
+ homepage: https://github.com/rubinius/melbourne
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.24
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Rubinius Melbourne parser
111
+ test_files: []
112
+ has_rdoc: