mirror of
https://github.com/usatiuk/psil.git
synced 2025-10-29 03:07:49 +01:00
even better parser
This commit is contained in:
@@ -2,6 +2,6 @@ set(CMAKE_CXX_STANDARD 20)
|
|||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
add_library(vm src/VM.cpp src/Cell.cpp
|
add_library(vm src/VM.cpp src/Cell.cpp
|
||||||
src/Parser.cpp src/SParser.cpp src/MemoryContext.cpp src/ConsUtils.cpp)
|
src/Parser.cpp src/MemoryContext.cpp src/ConsUtils.cpp)
|
||||||
|
|
||||||
target_include_directories(vm PUBLIC includes)
|
target_include_directories(vm PUBLIC includes)
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Stepan Usatiuk on 25.12.2023.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef PSIL_SPARSER_H
|
|
||||||
#define PSIL_SPARSER_H
|
|
||||||
|
|
||||||
|
|
||||||
class SParser {
|
|
||||||
// SParser()
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif//PSIL_SPARSER_H
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "Parser.h"
|
#include "Parser.h"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
@@ -62,10 +63,23 @@ std::string_view Parser::Tokenizer::peek() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Parser::Tokenizer::load(std::string_view input) {
|
void Parser::Tokenizer::load(std::string_view input) {
|
||||||
for (const auto &w: input | std::views::split(' ') | std::views::transform([](auto &&rng) {
|
std::string_view::size_type curpos = input.find_first_not_of(' ');
|
||||||
return std::string_view(&*rng.begin(), std::ranges::distance(rng));
|
|
||||||
})) {
|
static const std::string alnum = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
_tokens.emplace(w);
|
static const std::string special = "().";
|
||||||
|
|
||||||
|
while (curpos != std::string_view::npos) {
|
||||||
|
if (alnum.find(input.at(curpos)) != std::string::npos) {
|
||||||
|
std::string_view::size_type end = input.find_first_not_of(alnum, curpos);
|
||||||
|
_tokens.emplace(input.cbegin() + curpos, input.cbegin() + end);
|
||||||
|
curpos = end;
|
||||||
|
} else if (special.find(input.at(curpos)) != std::string::npos) {
|
||||||
|
_tokens.emplace(1, input.at(curpos));
|
||||||
|
curpos++;
|
||||||
|
} else {
|
||||||
|
throw std::invalid_argument("Unexpected symbol " + std::string(1, input.at(curpos)));
|
||||||
|
}
|
||||||
|
curpos = input.find_first_not_of(' ', curpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Stepan Usatiuk on 25.12.2023.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "SParser.h"
|
|
||||||
Reference in New Issue
Block a user