Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test/prism/fixtures/seattlerb/**/*.txt linguist-vendored
test/prism/fixtures/unparser/**/*.txt linguist-vendored
test/prism/fixtures/whitequark/**/*.txt linguist-vendored
test/prism/snapshots/**/*.txt linguist-generated
sig/generated/**/*.rbs linguist-generated

# All .rb files should have LF line ending, even on Windows, regardless of the git config core.autocrlf value.
# All .txt should have their line endings as committed in the repository (there are some intentional CR in there),
Expand Down
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ out.svg
/src/serialize.c
/src/token_type.c
/src/**/*.o
/sig/prism.rbs
/sig/prism/dsl.rbs
/sig/prism/mutation_compiler.rbs
/sig/prism/node.rbs
/sig/prism/visitor.rbs
/sig/prism/_private/dot_visitor.rbs
/rbi/prism/dsl.rbi
/rbi/prism/node.rbi
/rbi/prism/visitor.rbi
Expand Down
21 changes: 9 additions & 12 deletions Steepfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# frozen_string_literal: true

target :lib do
check "lib"
signature "sig"

library "cgi" # in lib/prism/dot_visitor.rb (Prism::DotVisitor)

check "lib"
library "cgi"
library "pp"

# TODO: Type-checking these files is still WIP
ignore "lib/prism/desugar_compiler.rb"
ignore "lib/prism/lex_compat.rb"
ignore "lib/prism/serialize.rb"
ignore "lib/prism/ffi.rb"
# Ignored because it requires other libraries.
ignore "lib/prism/translation"

ignore "lib/prism/polyfill/append_as_bytes.rb"
ignore "lib/prism/polyfill/byteindex.rb"
ignore "lib/prism/polyfill/scan_byte.rb"
ignore "lib/prism/polyfill/unpack1.rb"
# Ignored because they are only for older Rubies.
ignore "lib/prism/polyfill"

# Ignored because we do not want to overlap with the C extension.
ignore "lib/prism/ffi.rb"
end
2 changes: 2 additions & 0 deletions gemfiles/typecheck/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ gem "minitest"
gem "parser"
gem "rake-compiler"
gem "rake"
gem "rbs-inline"
gem "ruby_parser"
gem "sorbet", "<= 0.6.12666" # until tapioca is bumped
gem "steep", ">= 1.7.0.dev.1"
gem "tapioca"
gem "test-unit"
gem "tsort" # until rbs is bumped
13 changes: 9 additions & 4 deletions gemfiles/typecheck/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ GEM
csv (3.3.5)
drb (2.2.3)
erubi (1.13.1)
ffi (1.17.3-arm64-darwin)
ffi (1.17.3-x86_64-linux-gnu)
ffi (1.17.3)
fileutils (1.8.0)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -57,12 +56,15 @@ GEM
rbs (>= 3.4.4)
rbs (3.10.2)
logger
rbs-inline (0.13.0)
prism (>= 0.29)
rbs (>= 3.8.0)
rexml (3.4.4)
ruby_parser (3.22.0)
racc (~> 1.5)
sexp_processor (~> 4.16)
securerandom (0.4.1)
sexp_processor (4.17.4)
sexp_processor (4.17.5)
sorbet (0.6.12666)
sorbet-static (= 0.6.12666)
sorbet-runtime (0.6.12666)
Expand Down Expand Up @@ -111,11 +113,12 @@ GEM
test-unit (3.7.7)
power_assert
thor (1.4.0)
tsort (0.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.1.0)
unicode-emoji (4.2.0)
uri (1.1.1)
yard (0.9.37)
yard-sorbet (0.9.0)
Expand All @@ -131,11 +134,13 @@ DEPENDENCIES
parser
rake
rake-compiler
rbs-inline
ruby_parser
sorbet (<= 0.6.12666)
steep (>= 1.7.0.dev.1)
tapioca
test-unit
tsort

BUNDLED WITH
2.5.16
34 changes: 34 additions & 0 deletions lib/prism.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true
# :markup: markdown
#--
# rbs_inline: enabled

# The Prism Ruby parser.
#
Expand Down Expand Up @@ -37,6 +39,8 @@ module Prism
# Raised when requested to parse as the currently running Ruby version but Prism has no support for it.
class CurrentVersionError < ArgumentError
# Initialize a new exception for the given ruby version string.
#--
#: (String version) -> void
def initialize(version)
message = +"invalid version: Requested to parse as `version: 'current'`; "
segments =
Expand All @@ -61,6 +65,8 @@ def initialize(version)
# resembles the return value of Ripper.lex.
#
# For supported options, see Prism.parse.
#--
#: (String source, **untyped options) -> LexCompat::Result
def self.lex_compat(source, **options)
LexCompat.new(source, **options).result # steep:ignore
end
Expand All @@ -69,9 +75,37 @@ def self.lex_compat(source, **options)
# load(source, serialized, freeze) -> ParseResult
#
# Load the serialized AST using the source as a reference into a tree.
#--
#: (String source, String serialized, ?bool freeze) -> ParseResult
def self.load(source, serialized, freeze = false)
Serialize.load_parse(source, serialized, freeze)
end

# @rbs!
# VERSION: String
# BACKEND: :CEXT | :FFI
#
# interface _Stream
# def gets: (?Integer integer) -> (String | nil)
# end
#
# def self.parse: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult
# def self.profile: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> void
# def self.lex: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult
# def self.parse_lex: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult
# def self.dump: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> String
# def self.parse_comments: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment]
# def self.parse_success?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
# def self.parse_failure?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
# def self.parse_stream: (_Stream stream, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult
# def self.parse_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult
# def self.profile_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> void
# def self.lex_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult
# def self.parse_lex_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult
# def self.dump_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> String
# def self.parse_file_comments: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment]
# def self.parse_file_success?: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
# def self.parse_file_failure?: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
end

require_relative "prism/polyfill/byteindex"
Expand Down
Loading