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

Address small feedbacks #412

Merged
merged 4 commits into from
Feb 18, 2025
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: 0 additions & 7 deletions main/options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ const std::vector<ParserOptions> parser_options({
{"prism", Parser::PRISM},
});

struct AutogenConstCacheConfig {
// A file which contains a cache that can be used to potentially skip autogen
std::string cacheFile;
// A list of files which have changed since the last autogen run.
std::vector<std::string> changedFiles;
};

namespace {

#if !defined(EMSCRIPTEN)
Expand Down
13 changes: 8 additions & 5 deletions main/pipeline/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,14 @@ ast::ParsedFile indexOne(const options::Options &opts, core::GlobalState &lgs, c

bool stopAfterParser = opts.stopAfterPhase == options::Phase::PARSER;

if (parser == options::Parser::SORBET) {
parseTree = runParser(lgs, file, print, opts.traceLexer, opts.traceParser);
} else if (parser == options::Parser::PRISM) {
parseTree = runPrismParser(lgs, file, stopAfterParser, print);
} // Any other option would have been handled in the options parser
switch (parser) {
case options::Parser::SORBET:
parseTree = runParser(lgs, file, print, opts.traceLexer, opts.traceParser);
break;
case options::Parser::PRISM:
parseTree = runPrismParser(lgs, file, stopAfterParser, print);
break;
}

if (stopAfterParser) {
return emptyParsedFile(file);
Expand Down
4 changes: 2 additions & 2 deletions parser/prism/Parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace sorbet::parser::Prism {

pm_parser_t *Parser::get_raw_parser_pointer() {
pm_parser_t *Parser::getRawParserPointer() {
return &storage->parser;
}

Node Parser::parse_root() {
pm_node_t *root = pm_parse(get_raw_parser_pointer());
pm_node_t *root = pm_parse(getRawParserPointer());
return Node{*this, root};
};

Expand Down
6 changes: 3 additions & 3 deletions parser/prism/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ class Parser final {
void collectErrors();

private:
pm_parser_t *get_raw_parser_pointer();
pm_parser_t *getRawParserPointer();
};

class Node final {
struct NodeDeleter {
Parser parser;

void operator()(pm_node_t *node) {
pm_node_destroy(parser.get_raw_parser_pointer(), node);
pm_node_destroy(parser.getRawParserPointer(), node);
}
};

Expand All @@ -95,7 +95,7 @@ class Node final {
Node(const Node &) = delete; // Copy constructor
Node &operator=(const Node &) = delete; // Copy assignment

pm_node_t *get_raw_node_pointer() const {
pm_node_t *getRawNodePointer() const {
return node.get();
}
};
Expand Down
2 changes: 1 addition & 1 deletion parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
}

unique_ptr<parser::Node> Translator::translate(const Node &node) {
return translate(node.get_raw_node_pointer());
return translate(node.getRawNodePointer());
}

core::LocOffsets Translator::translateLoc(pm_location_t loc) {
Expand Down
2 changes: 1 addition & 1 deletion parser/prism/Translator.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef SORBET_PARSER_PRISM_TRANSLATOR_H
#define SORBET_PARSER_PRISM_TRANSLATOR_H

#include "../Node.h" // To clarify: these are Sorbet Parser nodes, not Prism ones.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I didn't know any better at the time.

#include "core/errors/parser.h"
#include "parser/Node.h" // To clarify: these are Sorbet Parser nodes, not Prism ones.
#include "parser/prism/Parser.h"
#include <memory>

Expand Down
20 changes: 12 additions & 8 deletions test/pipeline_test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,19 @@ vector<ast::ParsedFile> index(unique_ptr<core::GlobalState> &gs, absl::Span<core
}

unique_ptr<parser::Node> nodes;
if (parser == realmain::options::Parser::SORBET) {
std::cout << "Parsing with sorbet" << std::endl;
core::UnfreezeNameTable nameTableAccess(*gs); // enters original strings
switch (parser) {
case realmain::options::Parser::SORBET: {
std::cout << "Parsing with sorbet" << std::endl;
core::UnfreezeNameTable nameTableAccess(*gs); // enters original strings

auto settings = parser::Parser::Settings{};
nodes = parser::Parser::run(*gs, file, settings);
} else if (parser == realmain::options::Parser::PRISM) {
std::cout << "Parsing with prism" << std::endl;
nodes = realmain::pipeline::runPrismParser(*gs, file, false, {});
auto settings = parser::Parser::Settings{};
nodes = parser::Parser::run(*gs, file, settings);
break;
}
case realmain::options::Parser::PRISM:
std::cout << "Parsing with prism" << std::endl;
nodes = realmain::pipeline::runPrismParser(*gs, file, false, {});
break;
}

handler.drainErrors(*gs);
Expand Down
Loading