| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
module Prism |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
autoload :BasicVisitor, "prism/visitor" |
| 16 |
autoload :Compiler, "prism/compiler" |
| 17 |
autoload :DesugarCompiler, "prism/desugar_compiler" |
| 18 |
autoload :Dispatcher, "prism/dispatcher" |
| 19 |
autoload :DotVisitor, "prism/dot_visitor" |
| 20 |
autoload :DSL, "prism/dsl" |
| 21 |
autoload :InspectVisitor, "prism/inspect_visitor" |
| 22 |
autoload :LexCompat, "prism/lex_compat" |
| 23 |
autoload :MutationCompiler, "prism/mutation_compiler" |
| 24 |
autoload :Pack, "prism/pack" |
| 25 |
autoload :Pattern, "prism/pattern" |
| 26 |
autoload :Reflection, "prism/reflection" |
| 27 |
autoload :Relocation, "prism/relocation" |
| 28 |
autoload :Serialize, "prism/serialize" |
| 29 |
autoload :StringQuery, "prism/string_query" |
| 30 |
autoload :Translation, "prism/translation" |
| 31 |
autoload :Visitor, "prism/visitor" |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
private_constant :LexCompat |
| 37 |
|
| 38 |
|
| 39 |
class CurrentVersionError < ArgumentError |
| 40 |
|
| 41 |
def initialize(version) |
| 42 |
message = +"invalid version: Requested to parse as `version: 'current'`; " |
| 43 |
segments = |
| 44 |
if version.match?(/\A\d+\.\d+.\d+\z/) |
| 45 |
version.split(".").map(&:to_i) |
| 46 |
end |
| 47 |
|
| 48 |
if segments && ((segments[0] < 3) || (segments[0] == 3 && segments[1] < 3)) |
| 49 |
message << " #{version} is below the minimum supported syntax." |
| 50 |
else |
| 51 |
message << " #{version} is unknown. Please update the `prism` gem." |
| 52 |
end |
| 53 |
|
| 54 |
super(message) |
| 55 |
end |
| 56 |
end |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
def self.lex_compat(source, **options) |
| 66 |
LexCompat.new(source, **options).result |
| 67 |
end |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
def self.load(source, serialized, freeze = false) |
| 74 |
Serialize.load_parse(source, serialized, freeze) |
| 75 |
end |
| 76 |
end |
| 77 |
|
| 78 |
require_relative "prism/polyfill/byteindex" |
| 79 |
require_relative "prism/polyfill/warn" |
| 80 |
require_relative "prism/node" |
| 81 |
require_relative "prism/node_ext" |
| 82 |
require_relative "prism/parse_result" |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
if RUBY_ENGINE == "ruby" and !ENV["PRISM_FFI_BACKEND"] |
| 89 |
|
| 90 |
Prism::BACKEND = :CEXT |
| 91 |
|
| 92 |
require "prism/prism" |
| 93 |
else |
| 94 |
|
| 95 |
Prism::BACKEND = :FFI |
| 96 |
|
| 97 |
require_relative "prism/ffi" |
| 98 |
end |