Prism 모듈

Prism 모듈

Prism Ruby 파서예요.

"Parsing Ruby is suddenly manageable!"

- You, hopefully

출처: Ruby 3.3 API

본문

이 파일은 templates/template.rb 스크립트로 생성되며 수동으로 수정하면 안 돼요. 템플릿을 수정하려면 templates/lib/prism/compiler.rb.erb, dispatcher.rb.erb, dsl.rb.erb, mutation_compiler.rb.erb, node.rb.erb, visitor.rb.erb를 보세요.

여기서는 템플릿에 포함되지 않고 편의 메서드로 사용되는 노드용 메서드들을 제공하기 위해 prism 모듈을 다시 여는 거예요.

상수 (Constants)

  • BACKEND

Public Class Methods

dump (code, **options)

serialization API를 사용해 Prism.dump API를 그대로 반영해요.

dump_file (filepath, **options)

serialization API를 사용해 Prism.dump_file API를 그대로 반영해요.

lex (code, **options)

serialization API를 사용해 Prism.lex API를 그대로 반영해요.

Prism::lex_compat(source, **options) → ParseResult

값이 Ripper::lex의 반환값과 매우 유사한 토큰 배열인 파싱 결과를 반환해요. 가장 큰 차이는 :on_sp 토큰을 내보내지 않는다는 점이에요.

지원 옵션은 Prism::parse를 보세요.

lex_file (filepath, **options)

serialization API를 사용해 Prism.lex_file API를 그대로 반영해요.

Prism::lex_ripper(source) → Array

Ripper lex로 lexing해요. 공백 이벤트는 버리지만 그 외에는 같은 토큰을 반환해요. source의 문법이 유효하지 않으면 SyntaxError를 던져요.

Prism::load(source, serialized) → ParseResult

serialize된 AST를 source를 참조로 사용해 트리로 불러와요.

parse (code, **options)

serialization API를 사용해 Prism.parse API를 그대로 반영해요.

parse_comments (code, **options)

serialization API를 사용해 Prism.parse_comments API를 그대로 반영해요.

Prism::parse_failure?(source, **options) → bool

source가 에러와 함께 파싱되면 true를 반환해요.

parse_file (filepath, **options)

serialization API를 사용해 Prism.parse_file API를 그대로 반영해요. Ruby 문자열 대신 native 문자열을 쓰는데, 그래야 사용 가능할 때 mmap을 쓸 수 있어요.

parse_file_comments (filepath, **options)

serialization API를 사용해 Prism.parse_file_comments API를 그대로 반영해요. Ruby 문자열 대신 native 문자열을 쓰는데, 그래야 사용 가능할 때 mmap을 쓸 수 있어요.

Prism::parse_file_failure?(filepath, **options) → bool

filepath의 파일이 에러와 함께 파싱되면 true를 반환해요.

parse_file_success? (filepath, **options)

serialization API를 사용해 Prism.parse_file_success? API를 그대로 반영해요.

parse_lex (code, **options)

serialization API를 사용해 Prism.parse_lex API를 그대로 반영해요.

parse_lex_file (filepath, **options)

serialization API를 사용해 Prism.parse_lex_file API를 그대로 반영해요.

parse_success? (code, **options)

serialization API를 사용해 Prism.parse_success? API를 그대로 반영해요.

Private Class Methods

dump_options (options)

주어진 옵션을 serialize된 옵션 문자열로 변환해요.