Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
16166be
Add lexert17 submodule
shewitt-au Jun 15, 2025
76f9fb2
Add new_lexer.cpp
shewitt-au Jun 15, 2025
85cbfec
Get stuff to build
shewitt-au Jun 15, 2025
a226237
Start setting up for parallel lexing
shewitt-au Jun 15, 2025
97df40b
Move lexertl17 submodule to external
shewitt-au Jun 16, 2025
f112bef
Initial hookup
shewitt-au Jun 16, 2025
ffadf8a
Progress
shewitt-au Jun 16, 2025
8ac462b
Remove enum class base type. Why so big?
shewitt-au Jun 16, 2025
c31a240
Init function
shewitt-au Jun 17, 2025
8705e94
Fix potential ODR violation
shewitt-au Jun 17, 2025
c31e378
Progress
shewitt-au Jun 18, 2025
073ac46
Progress
shewitt-au Jun 21, 2025
c667a4f
Progress
shewitt-au Jun 21, 2025
cc35009
Progress
shewitt-au Jun 22, 2025
813ee20
Progress
shewitt-au Jun 22, 2025
465177f
Progress
shewitt-au Jun 22, 2025
7cacb1d
Progress
shewitt-au Jun 22, 2025
847771b
Progress
shewitt-au Jun 28, 2025
145977e
Progress
shewitt-au Jun 28, 2025
441b47c
Remove some dead code
shewitt-au Jun 28, 2025
f5d6240
Remove some dead code
shewitt-au Jun 28, 2025
26703c7
Single line comment
shewitt-au Jun 28, 2025
8828518
Fix crash in ML comment
shewitt-au Jun 28, 2025
6d1dd69
Merge ML comments
shewitt-au Jun 28, 2025
1738491
MLC: remove stuff
shewitt-au Jun 28, 2025
20d02ff
Comments
shewitt-au Jun 28, 2025
4a59308
Rephrase comment
shewitt-au Jun 28, 2025
257212b
Single line doc comment
shewitt-au Jun 29, 2025
57d565f
Start on ML doc comments. Some bug fixes.
shewitt-au Jun 29, 2025
1908bca
ML doc comments
shewitt-au Jun 29, 2025
a90dbd4
Clean up includes
shewitt-au Jun 29, 2025
25dc144
Rework ErrorCollector
shewitt-au Jul 3, 2025
7a019ac
Better newline handling
shewitt-au Jul 3, 2025
a4b4f96
Max line len
shewitt-au Jul 3, 2025
77ce947
Initial import of old num parsing code
shewitt-au Jul 4, 2025
ca67d8f
TODO comment
shewitt-au Jul 4, 2025
ec9f5be
End-of-program token
shewitt-au Jul 4, 2025
822eeea
Remove var that was not needed
shewitt-au Jul 5, 2025
656f3bf
Strings. Use new lexer
shewitt-au Jul 5, 2025
177b34f
Progress
shewitt-au Jul 5, 2025
8e216c7
Separators
shewitt-au Jul 5, 2025
91588aa
Start on directives
shewitt-au Jul 6, 2025
07c3c99
Directives: progress...
shewitt-au Jul 6, 2025
4315100
Directives: comment
shewitt-au Jul 6, 2025
a82b596
std::isspace: cast to unsigned char
shewitt-au Jul 7, 2025
fcbd7d0
Progress: dump and comp token stream
shewitt-au Jul 7, 2025
06e041f
lextwice: potential found
shewitt-au Jul 8, 2025
56fb5be
Merge: update from master
shewitt-au Aug 2, 2025
a8d6e59
Hack in string code
shewitt-au Aug 2, 2025
fbf1e0d
Hack in operators
shewitt-au Aug 2, 2025
0327db9
Hack in chars
shewitt-au Aug 2, 2025
19d05f2
Actually use new lexer proper
shewitt-au Aug 2, 2025
3ba107d
Prepare buildsys to generate static lexer
shewitt-au Aug 3, 2025
9bd70d3
Prepare buildsys to generate static lexer
shewitt-au Aug 3, 2025
1afca76
Remove need for static lexer gen to use PL code
shewitt-au Aug 3, 2025
1baa2e7
Changes operator handling due to quirks
shewitt-au Aug 3, 2025
7b40498
Wow! That's fast!
shewitt-au Aug 3, 2025
f8ee4c6
Shut up MSVC error
shewitt-au Aug 3, 2025
b729cd3
Merge remote-tracking branch 'origin/master' into new_lexer_dev
shewitt-au Aug 3, 2025
276ed14
Changes: still have issues
shewitt-au Aug 4, 2025
6729bed
Add comment
shewitt-au Aug 5, 2025
ba94eab
Special case some directives as old lexer does
shewitt-au Aug 5, 2025
2622d2e
Fix error in comment
shewitt-au Aug 6, 2025
78b58c4
Try to fix lexer_gen on macOS 13 arm64
shewitt-au Aug 6, 2025
77718dd
Move code around
shewitt-au Aug 6, 2025
3941961
Remove dead code
shewitt-au Aug 6, 2025
fa9e9b7
lexer_gen: start
shewitt-au Aug 6, 2025
08c0c03
lexer_gen: gen static lexer
shewitt-au Aug 6, 2025
8638e0d
Remove dead code
shewitt-au Aug 6, 2025
38f9cda
NOT WORKKING: contains work I need though
shewitt-au Aug 7, 2025
69f310c
Remove static lexer for now
shewitt-au Aug 8, 2025
977d8b2
Remove snake_case
shewitt-au Aug 8, 2025
9c036a7
Fix multiline comment and integers
shewitt-au Aug 9, 2025
667d630
"Fix" incorrect highlighting in pattern editor
shewitt-au Aug 9, 2025
5761674
Update lexertl17
shewitt-au Aug 9, 2025
a405c79
Number handling
shewitt-au Aug 10, 2025
0c83976
Attempt to fix tests
shewitt-au Aug 10, 2025
1686272
Attempt to fix tests
shewitt-au Aug 10, 2025
c382ca4
Merge branch 'new_lexer_dev' of https://github.com/shewitt-au/StevePa…
shewitt-au Aug 10, 2025
691156f
Remove need for init fn. Fix Flatpak errors.
shewitt-au Aug 10, 2025
5d30e83
String and char handling
shewitt-au Aug 11, 2025
b426189
Undo some accidental formatting changes
shewitt-au Aug 11, 2025
a38e719
int parsing got broken somewhere. Fix
shewitt-au Aug 11, 2025
873fb92
Add debugging code. It's finding issues.
shewitt-au Aug 11, 2025
9c0a600
Add note
shewitt-au Aug 11, 2025
cdba4dd
Fix floating point suffix
shewitt-au Aug 11, 2025
59a787c
Fix include test
shewitt-au Aug 11, 2025
1fbdb92
Fix ints
shewitt-au Aug 12, 2025
4e37bce
Fix floating point lexing
shewitt-au Aug 12, 2025
461f9f1
Fix floating point lexing
shewitt-au Aug 12, 2025
8a92a9d
Merge branch 'new_lexer_dev' of https://github.com/shewitt-au/StevePa…
shewitt-au Aug 12, 2025
3fd1e61
Merge branch 'WerWolv:master' into new_lexer_dev
shewitt-au Aug 12, 2025
19911d4
Update submodules
shewitt-au Aug 12, 2025
aca693d
Compare token streams
shewitt-au Aug 13, 2025
4a9370a
Reinstate static lexer build step
shewitt-au Aug 13, 2025
12f7b53
Change debug test macro
shewitt-au Aug 13, 2025
c2a99aa
Exception handling in lexer build
shewitt-au Aug 13, 2025
402ab22
Comments
shewitt-au Aug 13, 2025
c094387
Comments and renaming stuff
shewitt-au Aug 14, 2025
7db62ef
WIP: issues with mods by others
shewitt-au Aug 14, 2025
b5c1530
New line macro
shewitt-au Aug 15, 2025
7dee928
Non-newline whitespace macro
shewitt-au Aug 15, 2025
8ff9354
Disable debugging code
shewitt-au Aug 15, 2025
25b1564
Little bits here and there
shewitt-au Aug 16, 2025
a10af43
Simplify comments
shewitt-au Aug 16, 2025
7264c1f
Add reset method. Comments
shewitt-au Aug 16, 2025
ab53949
Error handling
shewitt-au Aug 16, 2025
b494acd
Add missing header
shewitt-au Aug 16, 2025
b91064e
Attempt to fix macOS build
shewitt-au Aug 16, 2025
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
path = external/throwing_ptr
url = https://github.com/rockdreamer/throwing_ptr
ignore = dirty
[submodule "lexertl17"]
path = external/lexertl17
url = https://github.com/BenHanson/lexertl17.git
2 changes: 1 addition & 1 deletion external/cli11
Submodule cli11 updated 178 files
1 change: 1 addition & 0 deletions external/lexertl17
Submodule lexertl17 added at 5507ee
22 changes: 22 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ else ()
message(STATUS "libpl static library is being created")
endif ()

add_subdirectory(lexer_gen)

set(PL_STATICLEXERPATH "${CMAKE_CURRENT_SOURCE_DIR}/include/pl/core/new_lexer_static.hpp")

add_custom_command(
OUTPUT ${PL_STATICLEXERPATH}
COMMAND $<TARGET_FILE:lexer_gen> ${PL_STATICLEXERPATH}
DEPENDS lexer_gen
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating lexertl17 static lexer"
)

add_custom_target(run_lexer_gen
DEPENDS ${PL_STATICLEXERPATH}
)

add_library(libpl ${LIBRARY_TYPE}
source/pl/helpers/utils.cpp

Expand Down Expand Up @@ -53,6 +69,11 @@ add_library(libpl ${LIBRARY_TYPE}
source/pl/core/token.cpp
source/pl/core/evaluator.cpp
source/pl/core/lexer.cpp

$<$<NOT:$<CONFIG:Debug>>:${PL_STATICLEXERPATH}>
$<$<CONFIG:Debug>:source/pl/core/new_lexer_sm.cpp>
source/pl/core/new_lexer.cpp

source/pl/core/parser.cpp
source/pl/core/preprocessor.cpp
source/pl/core/validator.cpp
Expand Down Expand Up @@ -102,6 +123,7 @@ endif ()

target_include_directories(libpl PUBLIC include ../external/throwing_ptr/include)
target_include_directories(libpl_includes INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include ../external/throwing_ptr/include)
target_include_directories(libpl PRIVATE include ../external/lexertl17/include)
target_link_libraries(libpl PRIVATE ${FMT_LIBRARIES})
target_link_libraries(libpl PUBLIC wolv::types wolv::io wolv::utils wolv::hash wolv::containers)

Expand Down
59 changes: 42 additions & 17 deletions lib/include/pl/core/errors/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,27 @@ namespace pl::core::err {
std::vector<Location> m_trace;
};

class ErrorCollector {
class ErrorCollectorExplicitLocation
{
public:

virtual ~ErrorCollector() = default;

virtual Location location() = 0;
virtual ~ErrorCollectorExplicitLocation() = default;

template <typename... Args>
void error(const fmt::format_string<Args...>& fmt, Args&&... args) {
this->m_errors.emplace_back(fmt::format(fmt, std::forward<Args>(args)...), location());
void error(const Location &location, const fmt::format_string<Args...> &fmt, Args&&... args) {
this->m_errors.emplace_back(fmt::format(fmt, std::forward<Args>(args)...), location);
}

void error(const std::string &message) {
this->m_errors.emplace_back(message, location());
}

void errorDesc(const std::string &message, const std::string &description) {
this->m_errors.emplace_back(message, description, location());
void errorDesc(const Location &location, const std::string &message, const std::string &description) {
this->m_errors.emplace_back(message, description, location);
}

template<typename... Args>
void errorDesc(const fmt::format_string<Args...>& message, const std::string &description, Args&&... args) {
this->m_errors.emplace_back(fmt::format(message, std::forward<Args>(args)...), description, location());
void errorDesc(const Location &location, const fmt::format_string<Args...>& message, const std::string &description, Args&&... args) {
this->m_errors.emplace_back(fmt::format(message, std::forward<Args>(args)...), description, location);
}

void error(CompileError& error) {
error.getTrace().push_back(location());
void error(const Location &location, CompileError& error) {
error.getTrace().push_back(location);
this->m_errors.push_back(std::move(error));
}

Expand Down Expand Up @@ -188,8 +182,39 @@ namespace pl::core::err {
void clear() {
this->m_errors.clear();
}

private:
std::vector<CompileError> m_errors;
};

class ErrorCollector : public ErrorCollectorExplicitLocation {
public:

virtual ~ErrorCollector() = default;

virtual Location location() = 0;

template <typename... Args>
void error(const fmt::format_string<Args...> &fmt, Args&&... args) {
this->ErrorCollectorExplicitLocation::error(location(), fmt, std::forward<Args>(args)...);
}

void error(const std::string &message) {
this->errorAt(location(), message);
}

void errorDesc(const std::string &message, const std::string &description) {
this->ErrorCollectorExplicitLocation::errorDesc(location(), message, description);
}

template<typename... Args>
void errorDesc(const fmt::format_string<Args...>& message, const std::string &description, Args&&... args) {
this->ErrorCollectorExplicitLocation::errorDesc(location(), message, description, std::forward<Args>(args)...);
}

void error(CompileError& error) {
this->ErrorCollectorExplicitLocation::error(location(), error);
}
};

}
38 changes: 38 additions & 0 deletions lib/include/pl/core/new_lexer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// "new_lexer.hpp"
#pragma once

#include <cstddef>
#include <optional>
#include <vector>
#include <pl/core/token.hpp>
#include <pl/core/errors/error.hpp>
#include <pl/core/errors/result.hpp>
// Debugging
#include <string>

namespace pl::core {

class New_Lexer : err::ErrorCollectorExplicitLocation {
public:
New_Lexer();

void reset();

hlp::CompileResult<std::vector<Token>> lex(const api::Source *source);
size_t getLongestLineLength() const { return m_longestLineLength; }

private:
std::optional<Token::Literal> parseInteger(std::string_view literal, const auto &location);
std::optional<double> parseFloatingPoint(std::string_view literal, const char suffix, const auto &location);
std::optional<char> parseCharacter(const char* &pchar, const char* e, const auto &location);
std::optional<Token> parseStringLiteral(std::string_view literal, const auto &location);

std::vector<Token> m_tokens;
std::size_t m_longestLineLength = 0;
};

// Debugging
void compareCompileResults(const hlp::CompileResult<std::vector<Token>> &o, const hlp::CompileResult<std::vector<Token>> &n);
void saveCompileResults(const std::string &fn, const hlp::CompileResult<std::vector<Token>> &res);

} // namespace pl::core
23 changes: 23 additions & 0 deletions lib/include/pl/core/new_lexer_sm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <lexertl/state_machine.hpp>

namespace pl::core {

namespace {

namespace LexerToken {

enum {
EndOfFile, NewLine, KWNamedOpTypeConstIdent, SingleLineComment,
MultiLineCommentOpen, MultiLineCommentClose, String, Separator,
Directive, DirectiveType, DirectiveParam, Operator, Char,
Integer, FPNumber
};

}
}

void newLexerBuild(lexertl::state_machine &sm);

}
12 changes: 11 additions & 1 deletion lib/include/pl/core/token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace pl::core {

Token() = default;

enum class Type : u64 {
enum class Type /*: u64*/ { // Why so big?
Keyword,
ValueType,
Operator,
Expand Down Expand Up @@ -280,6 +280,16 @@ namespace pl::core {
bool operator==(const ValueTypes &other) const;
bool operator!=(const ValueTypes &other) const;

// Debugging
friend bool operator==(const Token &l, const Token &r) {
return l.type==r.type && l.value==r.value;
}

friend bool operator!=(const Token &l, const Token &r) {
return l.type!=r.type || l.value!=r.value;
}
//

Type type = {};
ValueTypes value = {};
Location location = {};
Expand Down
2 changes: 2 additions & 0 deletions lib/include/pl/pattern_language.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace pl {
namespace core {
class Preprocessor;
class Lexer;
class New_Lexer;
class Parser;
class Validator;
class Evaluator;
Expand Down Expand Up @@ -62,6 +63,7 @@ namespace pl {
struct Internals {
std::unique_ptr<core::Preprocessor> preprocessor;
std::unique_ptr<core::Lexer> lexer;
std::unique_ptr<core::New_Lexer> new_lexer;
std::unique_ptr<core::Parser> parser;
std::unique_ptr<core::Validator> validator;
std::unique_ptr<core::Evaluator> evaluator;
Expand Down
12 changes: 12 additions & 0 deletions lib/lexer_gen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(SOURCES
../source/pl/core/new_lexer_sm.cpp
main.cpp
)

add_executable(lexer_gen ${SOURCES})

target_include_directories(lexer_gen PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
)

target_include_directories(lexer_gen PRIVATE include ../../external/lexertl17/include)
29 changes: 29 additions & 0 deletions lib/lexer_gen/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Build a "static" lexer in release builds.

Static in the sense that the state machine is built in a pre-build
step to optimize application start-up time.
*/
#include <pl/core/new_lexer_sm.hpp>

#include <lexertl/state_machine.hpp>
#include <lexertl/generate_cpp.hpp>

#include <fstream>
#include <iostream>

int main(int argc, char *argv[])
{
if (argc!=2)
return 1;

lexertl::state_machine sm;

pl::core::newLexerBuild(sm);
sm.minimise();

std::ofstream ofs(argv[1]);
lexertl::table_based_cpp::generate("lookup", sm, false, ofs);

return 0;
}
Loading
Loading