diff --git a/.gitignore b/.gitignore index 5bf9af9..a6dc78d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,10 @@ /build/ /release/ /.vscode/ +/vcpkg_installed/ CMakeUserPresets.json node_modules -tsconfig.tsbuildinfo \ No newline at end of file +tsconfig.tsbuildinfo +_codeql_detected_source_root +package-lock.json diff --git a/generated/include/annotate/syntax.h b/generated/include/annotate/syntax.h deleted file mode 100644 index 386f894..0000000 --- a/generated/include/annotate/syntax.h +++ /dev/null @@ -1,109 +0,0 @@ -/** - * @note This parser header file is generated from a template. - * Any modifications to this file will be overwritten. - * Please do not edit this file directly. - * - * @note 此文件是从模板生成的。 - * 任何对该文件的修改都将被覆盖。 - * 请不要直接编辑此文件。 - */ - -#ifndef __ANNOTATE_SYNTAX_H__ -#define __ANNOTATE_SYNTAX_H__ - -#include "alioth/ast.h" -#include "assignment/syntax.h" - - -namespace annotate { - -constexpr alioth::SymbolID COLON = 1; -constexpr alioth::SymbolID LANG = 2; -constexpr alioth::SymbolID ID = 3; -constexpr alioth::SymbolID COMMENT = 4; -constexpr alioth::SymbolID SPACE = 5; - -struct Annotate; // SymbolID = 7; Accepts: [7] - - -using Assignment = ::assignment::Assignment; - - -struct Annotate { - std::vector assignments() const; - alioth::AST lang() const; - alioth::AST node{}; - - operator alioth::AST() const { return node; } - operator bool() const { return node != nullptr; } - alioth::ASTNode* operator->() const { return node.get(); } - alioth::ASTNode& operator*() const { return *node; } -}; - - -} - -namespace alioth { -template<> -inline annotate::Annotate alioth::ASTNode::As() { - switch(id) { - case 7: - return annotate::Annotate{shared_from_this()}; - default: - return {}; - } -} - - -template<> -inline Syntax SyntaxOf() { - static auto syntax = []{ - using namespace nlohmann; - auto lex = Lexicon::Builder("annotate"); - lex.Define("COLON", R"(:)"_regex); - - lex.Define("LANG", R"(lang)"_regex, { "keyword", }); - - lex.Define("ID", R"([a-zA-Z_]\w*)"_regex); - - lex.Define("COMMENT", R"(#[^\n]*\n)"_regex); - lex.Annotate("COMMENT", "tokenize", R"({"type":"comment"})"_json); - - lex.Define("SPACE", R"(\s+)"_regex); - - - auto syntax = Syntactic::Builder(lex.Build()); - syntax.Ignore("COMMENT"); - syntax.Ignore("SPACE"); - - syntax.Import(::alioth::Syntax<::assignment::Assignment>(), "assignment"); - syntax.Formula("annotate").Symbol("LANG").Symbol("COLON").Symbol("ID", "lang").Symbol("assignments", "...").Commit(); - syntax.Formula("assignments").Symbol("assignment", "assignments").Commit(); - syntax.Formula("assignments").Symbol("assignments", "...").Symbol("assignment", "assignments").Commit(); - - return syntax.Build(); - }(); - - return syntax; -} -} - -namespace annotate { - -inline std::vector Annotate::assignments() const { - return alioth::generic::collect( - node->Attrs("assignments"), - [](auto n) { - return n->template As(); - } - ); -} -inline alioth::AST Annotate::lang() const { - return node->Attr("lang"); -} - - - -} - -#endif \ No newline at end of file diff --git a/generated/include/annotation/syntax.h b/generated/include/annotation/syntax.h deleted file mode 100644 index efbbb54..0000000 --- a/generated/include/annotation/syntax.h +++ /dev/null @@ -1,155 +0,0 @@ -/** - * @note This parser header file is generated from a template. - * Any modifications to this file will be overwritten. - * Please do not edit this file directly. - * - * @note 此文件是从模板生成的。 - * 任何对该文件的修改都将被覆盖。 - * 请不要直接编辑此文件。 - */ - -#ifndef __ANNOTATION_SYNTAX_H__ -#define __ANNOTATION_SYNTAX_H__ - -#include "alioth/ast.h" -#include "json/syntax.h" - - -namespace annotation { - -constexpr alioth::SymbolID COLON = 1; -constexpr alioth::SymbolID COMMA = 2; -constexpr alioth::SymbolID DOT = 3; -constexpr alioth::SymbolID LBRACE = 4; -constexpr alioth::SymbolID RBRACE = 5; -constexpr alioth::SymbolID ID = 6; -constexpr alioth::SymbolID COMMENT = 7; -constexpr alioth::SymbolID SPACE = 8; - -struct Annotation; // SymbolID = 10; Accepts: [10] -struct Attribute; // SymbolID = 13; Accepts: [13] - - -using Json = ::json::Json; - - -struct Annotation { - std::vector attributes() const; - alioth::AST node{}; - - operator alioth::AST() const { return node; } - operator bool() const { return node != nullptr; } - alioth::ASTNode* operator->() const { return node.get(); } - alioth::ASTNode& operator*() const { return *node; } -}; - -struct Attribute { - alioth::AST key() const; - alioth::AST of() const; - Json value() const; - alioth::AST node{}; - - operator alioth::AST() const { return node; } - operator bool() const { return node != nullptr; } - alioth::ASTNode* operator->() const { return node.get(); } - alioth::ASTNode& operator*() const { return *node; } -}; - - -} - -namespace alioth { -template<> -inline annotation::Annotation alioth::ASTNode::As() { - switch(id) { - case 10: - return annotation::Annotation{shared_from_this()}; - default: - return {}; - } -} - -template<> -inline annotation::Attribute alioth::ASTNode::As() { - switch(id) { - case 13: - return annotation::Attribute{shared_from_this()}; - default: - return {}; - } -} - - -template<> -inline Syntax SyntaxOf() { - static auto syntax = []{ - using namespace nlohmann; - auto lex = Lexicon::Builder("annotation"); - lex.Define("COLON", R"(:)"_regex); - - lex.Define("COMMA", R"(,)"_regex); - - lex.Define("DOT", R"(\.)"_regex); - - lex.Define("LBRACE", R"({)"_regex); - - lex.Define("RBRACE", R"(})"_regex); - - lex.Define("ID", R"([a-zA-Z_]\w*)"_regex); - - lex.Define("COMMENT", R"(#[^\n]*\n)"_regex); - lex.Annotate("COMMENT", "tokenize", R"({"type":"comment"})"_json); - - lex.Define("SPACE", R"(\s+)"_regex); - - - auto syntax = Syntactic::Builder(lex.Build()); - syntax.Ignore("COMMENT"); - syntax.Ignore("SPACE"); - - syntax.Import(::alioth::Syntax<::json::Json>(), "json"); - syntax.Formula("annotation").Symbol("LBRACE").Symbol("attributes", "...").Symbol("RBRACE").Commit(); - syntax.Formula("attributes").Symbol("attribute", "attributes").Commit(); - syntax.Formula("attributes").Symbol("attributes", "...").Symbol("COMMA").Symbol("attribute", "attributes").Commit(); - syntax.Formula("attribute").Symbol("ID", "key").Symbol("COLON").Symbol("json", "value") - .Annotate("key", "tokenize", R"({"modifier":["modification"],"type":"property"})"_json) - .Annotate("of", "tokenize", R"({"type":"property"})"_json) - .Commit(); - syntax.Formula("attribute").Symbol("ID", "of").Symbol("DOT").Symbol("ID", "key").Symbol("COLON").Symbol("json", "value") - .Annotate("key", "tokenize", R"({"modifier":["modification"],"type":"property"})"_json) - .Annotate("of", "tokenize", R"({"type":"property"})"_json) - .Commit(); - - return syntax.Build(); - }(); - - return syntax; -} -} - -namespace annotation { - -inline std::vector Annotation::attributes() const { - return alioth::generic::collect( - node->Attrs("attributes"), - [](auto n) { - return alioth::ViewOf(n); - } - ); -} - -inline alioth::AST Attribute::key() const { - return node->Attr("key"); -} -inline alioth::AST Attribute::of() const { - return node->Attr("of"); -} -inline Json Attribute::value() const { - return alioth::ViewOf(node->Attr("value")); -} - - - -} - -#endif \ No newline at end of file diff --git a/generated/include/assignment/syntax.h b/generated/include/assignment/syntax.h deleted file mode 100644 index b8a55d8..0000000 --- a/generated/include/assignment/syntax.h +++ /dev/null @@ -1,146 +0,0 @@ -/** - * @note This parser header file is generated from a template. - * Any modifications to this file will be overwritten. - * Please do not edit this file directly. - * - * @note 此文件是从模板生成的。 - * 任何对该文件的修改都将被覆盖。 - * 请不要直接编辑此文件。 - */ - -#ifndef __ASSIGNMENT_SYNTAX_H__ -#define __ASSIGNMENT_SYNTAX_H__ - -#include "alioth/ast.h" -#include "annotation/syntax.h" - - -namespace assignment { - -constexpr alioth::SymbolID SEMICOLON = 1; -constexpr alioth::SymbolID COMMA = 2; -constexpr alioth::SymbolID DOT = 3; -constexpr alioth::SymbolID ID = 4; -constexpr alioth::SymbolID COMMENT = 5; -constexpr alioth::SymbolID SPACE = 6; - -struct Assignment; // SymbolID = 8; Accepts: [8] -struct Selector; // SymbolID = 11; Accepts: [11] - - -using Annotation = ::annotation::Annotation; - - -struct Assignment { - std::vector selectors() const; - alioth::AST node{}; - - operator alioth::AST() const { return node; } - operator bool() const { return node != nullptr; } - alioth::ASTNode* operator->() const { return node.get(); } - alioth::ASTNode& operator*() const { return *node; } -}; - -struct Selector { - alioth::AST form() const; - alioth::AST symbol() const; - alioth::AST node{}; - - operator alioth::AST() const { return node; } - operator bool() const { return node != nullptr; } - alioth::ASTNode* operator->() const { return node.get(); } - alioth::ASTNode& operator*() const { return *node; } -}; - - -} - -namespace alioth { -template<> -inline assignment::Assignment alioth::ASTNode::As() { - switch(id) { - case 8: - return assignment::Assignment{shared_from_this()}; - default: - return {}; - } -} - -template<> -inline assignment::Selector alioth::ASTNode::As() { - switch(id) { - case 11: - return assignment::Selector{shared_from_this()}; - default: - return {}; - } -} - - -template<> -inline Syntax SyntaxOf() { - static auto syntax = []{ - using namespace nlohmann; - auto lex = Lexicon::Builder("assignment"); - lex.Define("SEMICOLON", R"(;)"_regex); - - lex.Define("COMMA", R"(,)"_regex); - - lex.Define("DOT", R"(\.)"_regex); - - lex.Define("ID", R"([a-zA-Z_]\w*)"_regex); - - lex.Define("COMMENT", R"(#[^\n]*\n)"_regex); - lex.Annotate("COMMENT", "tokenize", R"({"type":"comment"})"_json); - - lex.Define("SPACE", R"(\s+)"_regex); - - - auto syntax = Syntactic::Builder(lex.Build()); - syntax.Ignore("COMMENT"); - syntax.Ignore("SPACE"); - - syntax.Import(::alioth::Syntax<::annotation::Annotation>(), "annotation"); - syntax.Formula("assignment").Symbol("selectors", "...").Symbol("annotation", "...").Commit(); - syntax.Formula("assignment").Symbol("selectors", "...").Symbol("annotation", "...").Symbol("SEMICOLON").Commit(); - syntax.Formula("selectors").Symbol("selector", "selectors").Commit(); - syntax.Formula("selectors").Symbol("selectors", "...").Symbol("COMMA").Symbol("selector", "selectors").Commit(); - syntax.Formula("selector").Symbol("ID", "symbol") - .Annotate("form", "tokenize", R"({"type":"decorator"})"_json) - .Annotate("symbol", "tokenize", R"({"type":"class"})"_json) - .Commit(); - syntax.Formula("selector").Symbol("ID", "symbol").Symbol("DOT").Symbol("ID", "form") - .Annotate("form", "tokenize", R"({"type":"decorator"})"_json) - .Annotate("symbol", "tokenize", R"({"type":"class"})"_json) - .Commit(); - - return syntax.Build(); - }(); - - return syntax; -} -} - -namespace assignment { - -inline std::vector Assignment::selectors() const { - return alioth::generic::collect( - node->Attrs("selectors"), - [](auto n) { - return alioth::ViewOf(n); - } - ); -} - -inline alioth::AST Selector::form() const { - return node->Attr("form"); -} -inline alioth::AST Selector::symbol() const { - return node->Attr("symbol"); -} - - - -} - -#endif \ No newline at end of file diff --git a/grammar/annotate.grammar b/grammar/annotate.grammar deleted file mode 100644 index 658a4b9..0000000 --- a/grammar/annotate.grammar +++ /dev/null @@ -1,15 +0,0 @@ -# Annotation grammar - -lang: annotate - -import "./assignment.grammar" - -COLON = /:/ -LANG = /lang/ -ID = /[a-zA-Z_]\w*/ -COMMENT ?= /#[^\n]*\n/ { tokenize: { "type": "comment" } } -SPACE ?= /\s+/ - -annotate -> LANG COLON ID@lang ...assignments; - -assignments -> ...assignments? assignment@assignments; \ No newline at end of file diff --git a/grammar/annotation.grammar b/grammar/annotation.grammar deleted file mode 100644 index 69516a1..0000000 --- a/grammar/annotation.grammar +++ /dev/null @@ -1,25 +0,0 @@ -lang: annotation - -import "./json.grammar" - -COLON = /:/ -COMMA = /,/ -DOT = /\./ -LBRACE = /{/ -RBRACE = /}/ -ID = /[a-zA-Z_]\w*/ -COMMENT ?= /#[^\n]*\n/ { tokenize: { "type": "comment" } } -SPACE ?= /\s+/ - -annotation -> LBRACE ...attributes RBRACE; - -attributes -> attribute@attributes - | ...attributes COMMA attribute@attributes; - -attribute -> ID@key COLON json@value - | ID@of DOT ID@key COLON json@value; - -attribute { - key.tokenize: { "type": "property", "modifier": ["modification"] }, - of.tokenize: { "type": "property" } -} \ No newline at end of file diff --git a/grammar/assignment.grammar b/grammar/assignment.grammar deleted file mode 100644 index d87c860..0000000 --- a/grammar/assignment.grammar +++ /dev/null @@ -1,23 +0,0 @@ -lang: assignment - -import "./annotation.grammar" - -SEMICOLON = /;/ -COMMA = /,/ -DOT = /\./ -ID = /[a-zA-Z_]\w*/ -COMMENT ?= /#[^\n]*\n/ { tokenize: { "type": "comment" } } -SPACE ?= /\s+/ - -assignment -> ...selectors ...annotation SEMICOLON?; - -selectors -> selector@selectors - | ...selectors COMMA selector@selectors; - -selector -> ID@symbol - | ID@symbol DOT ID@form; - -selector { - symbol.tokenize: { "type": "class" }, - form.tokenize: { "type": "decorator" } -} \ No newline at end of file diff --git a/grammar/json.grammar b/grammar/json.grammar index 60b851c..dd3b8a2 100644 --- a/grammar/json.grammar +++ b/grammar/json.grammar @@ -9,8 +9,8 @@ RBRACKET = /]/ JNULL = /null/ TRUE = /true/ FALSE = /false/ -STRING = /\"([^\"\n\\]|\\[^\n])*\"/ { tokenize: { "type": "string" } } -NUMBER = /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/ { tokenize: { "type": "number" } } +STRING = /\"([^\"\n\\]|\\[^\n])*\"/ +NUMBER = /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/ SPACE ?= /\s+/ json -> ...object @@ -41,4 +41,4 @@ number -> NUMBER@number; boolean -> TRUE@boolean | FALSE@boolean; -null -> JNULL@null; \ No newline at end of file +null -> JNULL@null; diff --git a/grammar/template.grammar b/grammar/template.grammar index 0b757fc..2bd450a 100644 --- a/grammar/template.grammar +++ b/grammar/template.grammar @@ -2,8 +2,8 @@ # 参考 doc/template模板引擎介绍.md 了解使用方法 lang: template -TXT