-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
35 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
let x = 42 | ||
let y = x + 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
#include "lexer.h" | ||
#include "parser.h" | ||
|
||
#include <filesystem> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <sstream> | ||
|
||
int main() | ||
int main(int argc, char *argv[]) | ||
{ | ||
std::stringstream ss1{"let x = 0\nlet y = 1"}; | ||
lexer::print_tokens(lexer::lex(ss1)); | ||
std::stringstream ss2; | ||
lexer::print_tokens(lexer::lex(ss2)); | ||
// TODO Use CLI library. Clipp is unmaintained, find another one | ||
if (argc != 2) | ||
{ | ||
std::cerr << "USAGE: " << argv[0] << "<input file" << std::endl; | ||
return 1; | ||
} | ||
|
||
std::filesystem::path infile{argv[1]}; | ||
std::cout << "Input file: " << infile << std::endl; | ||
|
||
if (!std::filesystem::exists(infile)) | ||
{ | ||
std::cerr << "Input file " << infile << " does not exist"; | ||
return 1; | ||
} | ||
|
||
std::ifstream ifs; | ||
ifs.open(infile, std::ifstream::in); | ||
if (!ifs.is_open()) | ||
{ | ||
std::cerr << "Failed to open " << infile << std::endl; | ||
return 1; | ||
} | ||
|
||
std::cout << "-----\n"; | ||
lexer::print_tokens(lexer::lex(ifs)); | ||
std::cout << "\n-----\n"; | ||
} |