class Representer
- Representer
- Reference
- Object
Overview
Representer allows to be integrated with other programs easilly through its API.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.representation
# => "def PLACEHOLDER_1\n 1 + 1\nend"
Defined in:
api.crInstance Method Summary
- #ast : Crystal::ASTNode
-
#debug_json : String
Returns a json formatted
String
with the debug information. -
#mapping_json : String
Returns a mapping of the replaced names to the original names.
-
#parse_file(file : Path)
Parses a single file by reading it and then parsing it with the Crystal parser.
-
#parse_folder(folder : Path, files : Array(String))
Parses specified files in a folder by grouping them into a single long
String
and then parsing thatString
with the Crystal parser. -
#parse_folder(folder : Path)
Parses all files in a folder by grouping them into a single long
String
and then parsing thatString
with the Crystal parser. -
#parse_string(content : String)
Parses a
String
by parsing it with the Crystal parser. -
#represent
Transforms the AST into a representation.
- #representation : String
-
#representation_json : String
Returns a version number for the representation format.
-
#update_counter(new_counter : Int32 = 1)
Allows changing the value of the counter which is which number of the placeholder item gets.
-
#update_data(new_data : Array(String))
Allows changing the value of the data variable which is what is holding all names when representation.
Instance Method Detail
Returns a json formatted String
with the debug information.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.debug_json
# => "[["PLACEHOLDER_1", "Crystal::Def"]]"
Returns a mapping of the replaced names to the original names.
The format returned is a json formatted String
.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.mapping
# => "{\"PLACEHOLDER_1\":\"foo\"}"
Parses a single file by reading it and then parsing it with the Crystal parser.
path = Path.new("path/to/file")
represent = Representer.new
represent.parse_file(path)
Parses specified files in a folder by grouping them into a single long String
and then parsing that String
with the Crystal parser.
path = Path.new("path/to/folder")
represent = Representer.new
represent.parse_folder(path, ["main.cr"])
Parses all files in a folder by grouping them into a single long String
and then parsing that String
with the Crystal parser.
path = Path.new("path/to/folder")
represent = Representer.new
represent.parse_folder(path)
Parses a String
by parsing it with the Crystal parser.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
Returns a version number for the representation format.
The format returned is a json formatted String
.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.representation_json
# => "{\"version\":1}"
Allows changing the value of the counter which is which number of the placeholder item gets. When wanting to represent brand new code, this variable has to be changed to one. When the method is called without any argumments will it defualt to one.
Example:
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.update_data([] of String)
represent.update_counter(1)
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
Allows changing the value of the data variable which is what is holding all names when representation. When wanting to represent brand new code, this variable has to be cleared
Example:
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.update_data([] of String)
represent.update_counter
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent