Skip to content

Commit 7600905

Browse files
committed
Make main program read a file
Just lex it and print the tokens, since that's the only thing we can print atm. Run this in CI as a sanity check. I was going to use clipp for cmdline parsing, but it's broken as of C++20: muellan/clipp#53. It also seems to be unmaintained, the PR that fixes it has been open for >2 years: muellan/clipp#54 Will need to look into finding a new cmdline parsing library.
1 parent 472ccd7 commit 7600905

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

ci/build-and-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ cmake -S $SRC_DIR -B $BUILD_DIR -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPI
2424
cmake --build $BUILD_DIR || exit $?
2525

2626
ctest || exit $?
27-
$BUILD_DIR/bin/dumblang || exit $? # Just check that it runs
27+
$BUILD_DIR/bin/dumblang ../../../examples/example.dumb || exit $? # Just check that it runs

examples/example.dumb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let x = 42
2+
let y = x + 3

src/dumblang/main.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1-
#include "lexer.h"
1+
#include "parser.h"
22

3+
#include <filesystem>
4+
#include <fstream>
5+
#include <iostream>
36
#include <sstream>
47

5-
int main()
8+
int main(int argc, char *argv[])
69
{
7-
std::stringstream ss1{"let x = 0\nlet y = 1"};
8-
lexer::print_tokens(lexer::lex(ss1));
9-
std::stringstream ss2;
10-
lexer::print_tokens(lexer::lex(ss2));
10+
// TODO Use CLI library. Clipp is unmaintained, find another one
11+
if (argc != 2)
12+
{
13+
std::cerr << "USAGE: " << argv[0] << "<input file" << std::endl;
14+
return 1;
15+
}
16+
17+
std::filesystem::path infile{argv[1]};
18+
std::cout << "Input file: " << infile << std::endl;
19+
20+
if (!std::filesystem::exists(infile))
21+
{
22+
std::cerr << "Input file " << infile << " does not exist";
23+
return 1;
24+
}
25+
26+
std::ifstream ifs;
27+
ifs.open(infile, std::ifstream::in);
28+
if (!ifs.is_open())
29+
{
30+
std::cerr << "Failed to open " << infile << std::endl;
31+
return 1;
32+
}
33+
34+
std::cout << "-----\n";
35+
lexer::print_tokens(lexer::lex(ifs));
36+
std::cout << "\n-----\n";
1137
}

0 commit comments

Comments
 (0)