[feat] Addiditional initial project work.

This commit is contained in:
Johannes Janssen 2025-02-20 19:55:19 +01:00
commit 721235c843
19 changed files with 192 additions and 0 deletions

2
.clang-format Normal file
View File

@ -0,0 +1,2 @@
BasedOnStyle: LLVM
ColumnLimit: 120

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
.cache/
.idea/
build/
# Ignore all subdirectories (and their contents) under 'subprojects/'
subprojects/*/
# Optional: Ignore Meson's internal download tracking file (if unwanted)
subprojects/*.cache
subprojects/packagecache

18
meson.build Normal file
View File

@ -0,0 +1,18 @@
project('oak', ['cpp'],
version: '0.1.0',
default_options: ['cpp_std=20'],
)
oak_root_dir = meson.current_source_dir()
# Googletest imports
gtest = subproject('gtest')
gtest_dep = gtest.get_variable('gtest_dep')
gmock_dep = gtest.get_variable('gmock_dep')
gmock_main_dep = gtest.get_variable('gmock_main_dep')
icu = subproject('icu')
icu_dep = icu.get_variable('icuuc_dep')
subdir('src')
subdir('tests')

10
src/lib/common/core.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
namespace faust {
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
} // namespace faust

9
src/lib/common/string.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <string>
namespace faust {
typedef std::string String;
}

9
src/lib/common/vector.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <vector>
namespace faust {
template <typename type> using Vector = std::vector<type>;
}

1
src/lib/meson.build Normal file
View File

@ -0,0 +1 @@
subdir('parser')

59
src/lib/parser/lexer.h Normal file
View File

@ -0,0 +1,59 @@
#pragma once
#include "lib/common/vector.h"
#include "unicode/regex.h"
#include <unicode/utypes.h>
namespace faust {
template <typename TokenEnumeration> class Lexer {
public:
struct Lexeme {
TokenEnumeration token;
icu::UnicodeString value;
};
Lexer(const TokenEnumeration &endOfFile) { eofToken = endOfFile; }
void addToken(const icu::UnicodeString &pattern, const TokenEnumeration &token) {
UErrorCode status = U_ZERO_ERROR;
TokenDefinition td;
td.expression = pattern;
td.token = token;
td.matcher = icu::RegexMatcher(td.expression, 0, status);
tokens.push_back(td);
}
void setText(const icu::UnicodeString &newText) {
UErrorCode status = U_ZERO_ERROR;
position = 0;
state = newText;
icu::UnicodeString disjunctFullExpression = u"(";
for (size_t i = 0; i < tokens.size(); i++) {
disjunctFullExpression.append(tokens[i].expression);
if (i < (tokens.size() - 1)) {
disjunctFullExpression.append(u"|");
}
}
disjunctFullExpression.append(u")");
fullMatcher = icu::RegexMatcher(disjunctFullExpression, 0, status);
}
void next() { state.tempSubString(position); }
private:
struct TokenDefinition {
icu::UnicodeString expression;
icu::RegexMatcher matcher;
TokenEnumeration token;
};
TokenEnumeration eofToken;
icu::UnicodeString state;
icu::RegexMatcher fullMatcher;
size_t position;
Vector<TokenDefinition> tokens;
};
} // namespace faust

View File

@ -0,0 +1,8 @@
faust_parser_header = files('parser.h')
faust_parser_src = files('parser.cpp')
faust_parser_lib = library('faust-parser',
[faust_parser_header, faust_parser_src],
dependencies: icu_dep,
include_directories: faust_src_root_include)

View File

@ -0,0 +1,5 @@
#include "parser.h"
faust::Parser::Parser(String input) {
// TODO: Implement
}

15
src/lib/parser/parser.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include "lib/common/string.h"
namespace faust {
class Parser {
public:
Parser(String input);
private:
protected:
};
} // namespace faust

4
src/meson.build Normal file
View File

@ -0,0 +1,4 @@
faust_src_root_include = include_directories('.')
subdir('lib')
subdir('programs')

View File

@ -0,0 +1,5 @@
#include "lib/parser/lexer.h"
enum TestTokens { TK_FN, TK_DECIMAL_NUMBER, TK_STRING };
int main() { faust::Lexer<TestTokens> lex; }

View File

@ -0,0 +1,3 @@
faust_compiler_src = files('main.cpp')
executable('faustc', faust_compiler_src, include_directories: faust_src_root_include, link_with: faust_parser_lib)

1
src/programs/meson.build Normal file
View File

@ -0,0 +1 @@
subdir('compiler')

16
subprojects/gtest.wrap Normal file
View File

@ -0,0 +1,16 @@
[wrap-file]
directory = googletest-1.15.2
source_url = https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz
source_filename = gtest-1.15.2.tar.gz
source_hash = 7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926
patch_filename = gtest_1.15.2-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.15.2-1/get_patch
patch_hash = b41cba05fc61d47b2ba5bf95732eb86ce2b67303f291b68a9587b7563c318141
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/gtest_1.15.2-1/gtest-1.15.2.tar.gz
wrapdb_version = 1.15.2-1
[provide]
gtest = gtest_dep
gtest_main = gtest_main_dep
gmock = gmock_dep
gmock_main = gmock_main_dep

16
subprojects/icu.wrap Normal file
View File

@ -0,0 +1,16 @@
[wrap-file]
directory = icu
source_url = https://github.com/unicode-org/icu/releases/download/release-76-1/icu4c-76_1-src.tgz
source_filename = icu4c-76_1-src.tgz
source_hash = dfacb46bfe4747410472ce3e1144bf28a102feeaa4e3875bac9b4c6cf30f4f3e
patch_filename = icu_76.1-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/icu_76.1-2/get_patch
patch_hash = aa53ee7a3f742be81b597a7066d21777fcf9ab8f8793fa91b0565848854c27d6
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/icu_76.1-2/icu4c-76_1-src.tgz
wrapdb_version = 76.1-2
[provide]
icu-uc = icuuc_dep
icu-io = icuio_dep
icu-i18n = icui18n_dep
program_names = genbrk, genccode, gencmn

0
tests/mainTest.cpp Normal file
View File

3
tests/meson.build Normal file
View File

@ -0,0 +1,3 @@
test_exe = executable('test_gtest', 'mainTest.cpp',
dependencies: [gmock_main_dep, gtest_dep, gmock_dep])
test('GTest Suite', test_exe)