Skip to content

Commit e46899e

Browse files
author
robertDurst
committed
move files around, rename some stuff, and add pretty display messages
1 parent 34ae1ca commit e46899e

17 files changed

+310
-388
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ set(CMAKE_CXX_STANDARD 17)
55

66
# Add sailfishc libs. TODO: write this more eloquently
77
ADD_LIBRARY(SailfishcLibs
8-
./src/lexar/Lexar2.cpp
9-
./src/lexar/Token2.cpp
10-
./src/parser/Parser2.cpp
11-
./src/errorhandler/Parser2ErrorHandler.cpp
8+
./src/lexar/Lexar.cpp
9+
./src/lexar/Token.cpp
10+
./src/parser/Parser.cpp
11+
./src/errorhandler/ParserErrorHandler.cpp
1212
./src/errorhandler/SemanticAnalyzerErrorHandler.cpp
1313
./src/main/CommandLine.cpp
1414
./src/semantics/SymbolTable.cpp
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ namespace Prettify
1212
enum Code
1313
{
1414
RESET = 0,
15+
BOLD = 1,
1516
UNDERLINE = 4,
1617
FG_RED = 31,
18+
FG_GREEN = 32,
1719
FG_YELLOW = 33,
1820
FG_DEFAULT = 39,
21+
BG_BLUE = 44,
22+
FG_LIGHT_BLUE = 94,
23+
FG_WHITE = 97,
1924
};
2025
class Formatter
2126
{
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* Sailfish Programming Language
44
*/
55
#pragma once
6-
#include "display.h"
6+
#include "../common/display.h"
77
#include <iostream>
88
#include <string>
99

10-
class Error2
10+
class Error
1111
{
1212
private:
1313
int col;
@@ -20,8 +20,8 @@ class Error2
2020
std::string filename;
2121

2222
public:
23-
Error2(int c, int l, const std::string& m, const std::string& le,
24-
const std::string& mid, const std::string& ri)
23+
Error(int c, int l, const std::string& m, const std::string& le,
24+
const std::string& mid, const std::string& ri)
2525
{
2626
col = c;
2727
line = l;

src/errorhandler/Parser2ErrorHandler.h

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* Robert Durst 2019
33
* Sailfish Programming Language
44
*/
5-
#include "Parser2ErrorHandler.h"
5+
#include "ParserErrorHandler.h"
66

77
void
8-
Parser2ErrorHandler::handle(std::unique_ptr<Error2> err)
8+
ParserErrorHandler::handle(std::unique_ptr<Error> err)
99
{
1010
// finish the initialization of Error
1111
err->setErrorType("PARSER");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Robert Durst 2019
3+
* Sailfish Programming Language
4+
*/
5+
#pragma once
6+
#include "Error.h"
7+
#include <memory>
8+
9+
class ParserErrorHandler
10+
{
11+
public:
12+
ParserErrorHandler(){};
13+
void handle(std::unique_ptr<Error>);
14+
};

src/errorhandler/SemanticAnalyzerErrorHandler.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "SemanticAnalyzerErrorHandler.h"
66

77
void
8-
SemanticAnalyzerErrorHandler::handle(std::unique_ptr<Error2> err)
8+
SemanticAnalyzerErrorHandler::handle(std::unique_ptr<Error> err)
99
{
1010
// finish the initialization of Error
1111
err->setErrorType("SEMANTIC");
@@ -16,16 +16,3 @@ SemanticAnalyzerErrorHandler::handle(std::unique_ptr<Error2> err)
1616
err->displayMessage();
1717
// throw "";
1818
}
19-
20-
void
21-
SemanticAnalyzerErrorHandler::handle(std::unique_ptr<Warning> err)
22-
{
23-
// finish the initialization of Error
24-
err->setWarningType("SEMANTIC");
25-
26-
err->setFilename(filename);
27-
28-
// throw an error since we stop at first error here
29-
err->displayMessage();
30-
// throw "";
31-
}

src/errorhandler/SemanticAnalyzerErrorHandler.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
* Sailfish Programming Language
44
*/
55
#pragma once
6-
#include "Error2.h"
7-
#include "Warning.h"
6+
#include "Error.h"
87
#include <memory>
98
#include <string>
109

1110
class SemanticAnalyzerErrorHandler
1211
{
1312
private:
1413
std::string filename;
14+
1515
public:
16-
SemanticAnalyzerErrorHandler(const std::string& f): filename(f){};
17-
void handle(std::unique_ptr<Error2>);
18-
void handle(std::unique_ptr<Warning>);
16+
SemanticAnalyzerErrorHandler(const std::string& f) : filename(f){};
17+
void handle(std::unique_ptr<Error>);
1918
};

src/errorhandler/Warning.h

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Robert Durst 2019
33
* Sailfish Programming Language
44
*/
5-
#include "Lexar2.h"
5+
#include "Lexar.h"
66
#include <iostream>
77

88
/*
@@ -11,8 +11,8 @@
1111
* having found the end of the token. In the second case, I need the buffer to
1212
* pop the last char and to return this char to the scanner.
1313
*/
14-
std::unique_ptr<Token2>
15-
Lexar2::makeToken(const TokenKind& k, const std::string& v)
14+
std::unique_ptr<Token>
15+
Lexar::makeToken(const TokenKind& k, const std::string& v)
1616
{
1717
auto kd = k; // since kd is constant we copy here
1818

@@ -30,8 +30,6 @@ Lexar2::makeToken(const TokenKind& k, const std::string& v)
3030
kd = TokenKind::UAT;
3131
else if (v == "Ufn")
3232
kd = TokenKind::UFN;
33-
else if (v == "Ife")
34-
kd = TokenKind::IFE;
3533
else if (v == "fun")
3634
kd = TokenKind::FUN;
3735
else if (v == "empty")
@@ -51,11 +49,11 @@ Lexar2::makeToken(const TokenKind& k, const std::string& v)
5149
else if (v == "true" || v == "false")
5250
kd = TokenKind::BOOL;
5351
}
54-
return std::make_unique<Token2>(kd, v, col, line);
52+
return std::make_unique<Token>(kd, v, col, line);
5553
}
5654

57-
std::unique_ptr<Token2>
58-
Lexar2::makeTokenPutback(const TokenKind& k, std::string& v, char& c)
55+
std::unique_ptr<Token>
56+
Lexar::makeTokenPutback(const TokenKind& k, std::string& v, char& c)
5957
{
6058
// readjust the col and line counters
6159
col = prevCol;
@@ -75,7 +73,7 @@ Lexar2::makeTokenPutback(const TokenKind& k, std::string& v, char& c)
7573
}
7674

7775
char
78-
Lexar2::getNextChar()
76+
Lexar::getNextChar()
7977
{
8078
if (isFile)
8179
{
@@ -95,7 +93,7 @@ Lexar2::getNextChar()
9593
return c;
9694
}
9795

98-
Lexar2::Lexar2(const std::string& fileString, bool isAFile)
96+
Lexar::Lexar(const std::string& fileString, bool isAFile)
9997
{
10098
if (isAFile)
10199
{
@@ -114,8 +112,8 @@ Lexar2::Lexar2(const std::string& fileString, bool isAFile)
114112
prevCol = 0;
115113
}
116114

117-
std::unique_ptr<Token2>
118-
Lexar2::getNextToken()
115+
std::unique_ptr<Token>
116+
Lexar::getNextToken()
119117
{
120118
char c;
121119
int state = State::START;

0 commit comments

Comments
 (0)