Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation for __FILE__ keyword #219

Merged
merged 1 commit into from
Aug 26, 2024
Merged
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
7 changes: 6 additions & 1 deletion parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,12 @@ std::unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
return make_unique<parser::SClass>(parser.translateLocation(loc), parser.translateLocation(declLoc),
std::move(expr), std::move(body));
}
case PM_SOURCE_FILE_NODE: {
auto sourceFileNode = reinterpret_cast<pm_source_file_node *>(node);
pm_location_t *loc = &sourceFileNode->base.location;

return make_unique<parser::FileLiteral>(parser.translateLocation(loc));
}
case PM_SPLAT_NODE: {
auto splatNode = reinterpret_cast<pm_splat_node *>(node);
pm_location_t *loc = &splatNode->base.location;
Expand Down Expand Up @@ -719,7 +725,6 @@ std::unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
case PM_RETRY_NODE:
case PM_SHAREABLE_CONSTANT_NODE:
case PM_SOURCE_ENCODING_NODE:
case PM_SOURCE_FILE_NODE:
case PM_SOURCE_LINE_NODE:
case PM_UNDEF_NODE:
case PM_WHILE_NODE:
Expand Down
2 changes: 2 additions & 0 deletions test/prism_regression/source_file.parse-tree.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FileLiteral {
}
3 changes: 3 additions & 0 deletions test/prism_regression/source_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# typed: true

__FILE__