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

Generate error messages lazily #413

Merged
merged 2 commits into from
Jan 5, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
# echo "/usr/lib/ccache:/usr/local/opt/ccache/libexec" >> $GITHUB_PATH
# mkdir ./bin
# cd ./bin
# cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DSPICE_BUILT_BY="ghactions" -DSPICE_LINK_STATIC=OFF -DSPICE_RUN_COVERAGE=ON -GNinja -Wattributes ..
# cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DSPICE_BUILT_BY="ghactions" -DSPICE_PROF_COMPILE=ON -DSPICE_LINK_STATIC=OFF -DSPICE_RUN_COVERAGE=ON -GNinja -Wattributes ..
# cmake --build . --target spicetest -j$(nproc)

- name: Run Test target
Expand Down
33 changes: 10 additions & 23 deletions media/test-project/test.spice
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
import "std/io/cli-parser";
import "std/io/cli-subcommand";

type CliOptions struct {
string greetName = ""
}

p callback(bool& value) {
printf("Callback called with value %d\n", value);
}
import "../../src-bootstrap/lexer/lexer";

f<int> main(int argc, string[] argv) {
CliParser parser = CliParser("Test Program", "This is a simple test program");
parser.setVersion("v0.1.0");
parser.setFooter("Copyright (c) Marc Auberer 2021-2024");

CliOptions options;
CliSubcommand& greet = parser.addSubcommand("greet", "Greet someone");
greet.addOption("--name", options.greetName, "Name of the person to greet");

parser.parse(argc, argv);

// Greet persion if requested
if options.greetName != "" {
printf("Hello %s!\n", options.greetName);
Lexer lexer = Lexer(argv[1]);
unsigned long i = 1l;
while (!lexer.isEOF()) {
Token token = lexer.getToken();
//printf("Token %d: ", i);
//token.print();
lexer.advance();
i++;
}
printf("Tokens: %d\n", i);
}

/*type Visitable interface {
Expand Down
4 changes: 2 additions & 2 deletions src/SourceFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void SourceFile::runLexer() {
throw CompilerError(SOURCE_FILE_NOT_FOUND, "Source file at path '" + filePath.string() + "' does not exist.");

// Create error handlers for lexer and parser
antlrCtx.lexerErrorHandler = std::make_unique<AntlrThrowingErrorListener>(ThrowingErrorListenerMode::LEXER, filePath);
antlrCtx.parserErrorHandler = std::make_unique<AntlrThrowingErrorListener>(ThrowingErrorListenerMode::PARSER, filePath);
antlrCtx.lexerErrorHandler = std::make_unique<AntlrThrowingErrorListener>(ThrowingErrorListenerMode::LEXER, this);
antlrCtx.parserErrorHandler = std::make_unique<AntlrThrowingErrorListener>(ThrowingErrorListenerMode::PARSER, this);

// Tokenize input
antlrCtx.inputStream = std::make_unique<antlr4::ANTLRInputStream>(fileInputStream);
Expand Down
9 changes: 8 additions & 1 deletion src/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ enum CompileStageType : uint8_t {
FINISHED
};

enum CompileStageIOType { IO_CODE, IO_TOKENS, IO_CST, IO_AST, IO_IR, IO_OBJECT_FILE };
enum CompileStageIOType : uint8_t {
IO_CODE,
IO_TOKENS,
IO_CST,
IO_AST,
IO_IR,
IO_OBJECT_FILE,
};

struct SourceFileAntlrCtx {
// Create error handlers for lexer and parser
Expand Down
Loading