Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke committed Jun 25, 2020
1 parent 5958f77 commit c8c8378
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions refm/api/src/_builtin/RubyVM__AbstractSyntaxTree
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,36 @@ pp RubyVM::AbstractSyntaxTree.of(method(:hello))

--- parse(string) -> RubyVM::AbstractSyntaxTree::Node

#@# Parses the given string into an abstract syntax tree, returning the root node of that tree.
#@#
#@# SyntaxError is raised if the given string is invalid syntax.
文字列を抽象構文木にパースし、その木の根ノードを返します。

#@# RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
#@# # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-1:9>
@param string パースする対象の Ruby のコードを文字列で指定します。
@raise SyntaxError string が Ruby のコードとして正しくない場合に発生します。

#@samplecode
pp RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
# => (SCOPE@1:0-1:9
# tbl: [:x]
# args: nil
# body:
# (LASGN@1:0-1:9 :x
# (OPCALL@1:4-1:9 (LIT@1:4-1:5 1) :+ (LIST@1:8-1:9 (LIT@1:8-1:9 2) nil))))
#@end

--- parse_file(pathname) -> RubyVM::AbstractSyntaxTree::Node

#@# Reads the file from pathname, then parses it like ::parse, returning the root node of the abstract syntax tree.
#@#
#@# SyntaxError is raised if pathname's contents are not valid Ruby syntax.
pathname のファイルを読み込み、その内容を抽象構文木にパースし、その木の根ノードを返します。

@param pathname パースする対象のファイルパスを指定します
@raise SyntaxError string が Ruby のコードとして正しくない場合に発生します。

#@# RubyVM::AbstractSyntaxTree.parse_file("my-app/app.rb")
#@# # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-31:3>
#@samplecode
# => (SCOPE@1:0-1:50
# tbl: []
# args: nil
# body:
# (FCALL@1:0-1:50 :pp
# (LIST@1:3-1:50
# (CALL@1:3-1:50
# (COLON2@1:3-1:29 (CONST@1:3-1:9 :RubyVM) :AbstractSyntaxTree)
# :parse_file (LIST@1:41-1:49 (STR@1:41-1:49 "") nil)) nil)))
#@end

0 comments on commit c8c8378

Please sign in to comment.