The Prism
Ruby parser.
“Parsing Ruby is suddenly manageable!”
- You, hopefully
Here we are reopening the prism module to provide methods on nodes that aren’t templated and are meant as convenience methods.
- MODULE Prism::Debug
- MODULE Prism::Pack
- CLASS Prism::Comment
- CLASS Prism::ConstantPathNode
- CLASS Prism::ConstantPathTargetNode
- CLASS Prism::ConstantReadNode
- CLASS Prism::DesugarCompiler
- CLASS Prism::EmbDocComment
- CLASS Prism::FloatNode
- CLASS Prism::ImaginaryNode
- CLASS Prism::InlineComment
- CLASS Prism::IntegerNode
- CLASS Prism::InterpolatedMatchLastLineNode
- CLASS Prism::InterpolatedRegularExpressionNode
- CLASS Prism::InterpolatedStringNode
- CLASS Prism::InterpolatedXStringNode
- CLASS Prism::LexCompat
- CLASS Prism::Location
- CLASS Prism::MagicComment
- CLASS Prism::MatchLastLineNode
- CLASS Prism::ParametersNode
- CLASS Prism::ParseError
- CLASS Prism::ParseResult
- CLASS Prism::ParseWarning
- CLASS Prism::Pattern
- CLASS Prism::RationalNode
- CLASS Prism::RegularExpressionNode
- CLASS Prism::RipperCompat
- CLASS Prism::Source
- CLASS Prism::StringNode
- CLASS Prism::Token
- CLASS Prism::XStringNode
- D
- L
- P
Constants
BACKEND | = | :FFI |
VERSION | = | LibRubyParser.pm_version.read_string |
The version constant is set by reading the result of calling pm_version. |
Class Public methods
dump(code, **options) Link
Mirror the Prism.dump
API by using the serialization API.
dump_file(filepath, **options) Link
Mirror the Prism.dump_file
API by using the serialization API.
Prism::lex_compat(source, **options) → ParseResult Link
Returns a parse result whose value is an array of tokens that closely resembles the return value of Ripper::lex
. The main difference is that the ‘:on_sp` token is not emitted.
For supported options, see Prism::parse
.
lex_file(filepath, **options) Link
Mirror the Prism.lex_file
API by using the serialization API.
Prism::lex_ripper(source) → Array Link
This lexes with the Ripper
lex. It drops any space events but otherwise returns the same tokens. Raises SyntaxError
if the syntax in source is invalid.
Prism::load(source, serialized) → ParseResult Link
Load the serialized AST using the source as a reference into a tree.
parse(code, **options) Link
Mirror the Prism.parse
API by using the serialization API.
parse_comments(code, **options) Link
Mirror the Prism.parse_comments
API by using the serialization API.
# File ruby/lib/prism/ffi.rb, line 226 def parse_comments(code, **options) LibRubyParser::PrismBuffer.with do |buffer| LibRubyParser.pm_serialize_parse_comments(buffer.pointer, code, code.bytesize, dump_options(options)) source = Source.new(code) loader = Serialize::Loader.new(source, buffer.read) loader.load_header loader.load_encoding loader.load_start_line loader.load_comments end end
Prism::parse_failure?(source, **options) → bool Link
Returns true if the source parses with errors.
parse_file(filepath, **options) Link
Mirror the Prism.parse_file
API by using the serialization API. This uses native strings instead of Ruby strings because it allows us to use mmap when it is available.
parse_file_comments(filepath, **options) Link
Mirror the Prism.parse_file_comments
API by using the serialization API. This uses native strings instead of Ruby strings because it allows us to use mmap when it is available.
Prism::parse_file_failure?(filepath, **options) → bool Link
Returns true if the file at filepath parses with errors.
parse_file_success?(filepath, **options) Link
Mirror the Prism.parse_file_success?
API by using the serialization API.
parse_lex(code, **options) Link
Mirror the Prism.parse_lex
API by using the serialization API.
# File ruby/lib/prism/ffi.rb, line 250 def parse_lex(code, **options) LibRubyParser::PrismBuffer.with do |buffer| LibRubyParser.pm_serialize_parse_lex(buffer.pointer, code, code.bytesize, dump_options(options)) source = Source.new(code) loader = Serialize::Loader.new(source, buffer.read) tokens = loader.load_tokens node, comments, magic_comments, data_loc, errors, warnings = loader.load_nodes tokens.each { |token,| token.value.force_encoding(loader.encoding) } ParseResult.new([node, tokens], comments, magic_comments, data_loc, errors, warnings, source) end end
parse_lex_file(filepath, **options) Link
Mirror the Prism.parse_lex_file
API by using the serialization API.
parse_success?(code, **options) Link
Mirror the Prism.parse_success?
API by using the serialization API.