mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
print + build partially tested
This commit is contained in:
parent
0d62ae0814
commit
15e36c203a
22 changed files with 179 additions and 116 deletions
18
.clang_tidy
Normal file
18
.clang_tidy
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
Checks: "*,
|
||||||
|
-abseil-*,
|
||||||
|
-altera-*,
|
||||||
|
-android-*,
|
||||||
|
-fuchsia-*,
|
||||||
|
-google-*,
|
||||||
|
-llvm*,
|
||||||
|
-modernize-use-trailing-return-type,
|
||||||
|
-zircon-*,
|
||||||
|
-readability-else-after-return,
|
||||||
|
-readability-static-accessed-through-instance,
|
||||||
|
-readability-avoid-const-params-in-decls,
|
||||||
|
-cppcoreguidelines-non-private-member-variables-in-classes,
|
||||||
|
-misc-non-private-member-variables-in-classes,
|
||||||
|
"
|
||||||
|
WarningsAsErrors: ''
|
||||||
|
HeaderFilterRegex: ''
|
||||||
|
FormatStyle: none
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -13,3 +13,4 @@ _deps
|
||||||
|
|
||||||
|
|
||||||
build
|
build
|
||||||
|
build_make
|
||||||
|
|
|
||||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
LangInterpreter
|
||||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
2
.idea/lang-interpreter.iml
generated
Normal file
2
.idea/lang-interpreter.iml
generated
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
||||||
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/lang-interpreter.iml" filepath="$PROJECT_DIR$/.idea/lang-interpreter.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
7
.idea/vcs.xml
generated
Normal file
7
.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/tree-sitter" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -8,7 +8,7 @@ namespace interpreter {
|
||||||
|
|
||||||
class BuildVisitor : public Visitor {
|
class BuildVisitor : public Visitor {
|
||||||
public:
|
public:
|
||||||
BuildVisitor(const parser::ParseTree& parse_tree) : parse_tree_(parse_tree) {}
|
explicit BuildVisitor(const parser::ParseTree& parse_tree) : parse_tree_(parse_tree) {}
|
||||||
|
|
||||||
void VisitSourceFile(SourceFile* source_file) override {
|
void VisitSourceFile(SourceFile* source_file) override {
|
||||||
current_node_ = parse_tree_.GetRoot();
|
current_node_ = parse_tree_.GetRoot();
|
||||||
|
|
@ -23,7 +23,7 @@ private:
|
||||||
void Visit(SourceFile* node) override;
|
void Visit(SourceFile* node) override;
|
||||||
void Visit(Sources* node) override;
|
void Visit(Sources* node) override;
|
||||||
|
|
||||||
// Namespaces, partittions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
void Visit(Partition* node) override;
|
void Visit(Partition* node) override;
|
||||||
void Visit(Namespace* node) override;
|
void Visit(Namespace* node) override;
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,7 @@
|
||||||
#include "node.hpp"
|
#include "node.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace interpreter {
|
namespace interpreter::tokens {
|
||||||
|
|
||||||
namespace tokens {
|
|
||||||
|
|
||||||
// ----------------- Declarations -----------------
|
// ----------------- Declarations -----------------
|
||||||
|
|
||||||
|
|
@ -30,7 +28,7 @@ using TypeclassIdentifier = std::string;
|
||||||
struct SourceFile;
|
struct SourceFile;
|
||||||
struct Sources;
|
struct Sources;
|
||||||
|
|
||||||
// Namespaces, partittions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
struct Partition;
|
struct Partition;
|
||||||
struct Namespace;
|
struct Namespace;
|
||||||
|
|
@ -101,7 +99,7 @@ struct Block;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
struct NameExpression;
|
struct NameSuperExpression;
|
||||||
struct ScopedStatement;
|
struct ScopedStatement;
|
||||||
|
|
||||||
enum class LoopControlExpression {
|
enum class LoopControlExpression {
|
||||||
|
|
@ -110,7 +108,7 @@ enum class LoopControlExpression {
|
||||||
};
|
};
|
||||||
|
|
||||||
using SubExpressionToken = std::variant<
|
using SubExpressionToken = std::variant<
|
||||||
std::unique_ptr<NameExpression>,
|
std::unique_ptr<NameSuperExpression>,
|
||||||
std::unique_ptr<ScopedStatement>>;
|
std::unique_ptr<ScopedStatement>>;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -576,6 +574,4 @@ struct CharLiteral : public Node {
|
||||||
char value;
|
char value;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tokens
|
} // namespace interpereter::tokens
|
||||||
|
|
||||||
} // namespace interpereter
|
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,14 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace parser {
|
namespace parser::tokens {
|
||||||
|
|
||||||
namespace tokens {
|
|
||||||
|
|
||||||
// Sources -----------------
|
// Sources -----------------
|
||||||
|
|
||||||
const std::string SourceFile = "source_file";
|
const std::string SourceFile = "source_file";
|
||||||
const std::string Sources = "sources";
|
const std::string Sources = "sources";
|
||||||
|
|
||||||
// Namespaces, partittions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
const std::string Partition = "partition";
|
const std::string Partition = "partition";
|
||||||
const std::string Namespace = "namespace";
|
const std::string Namespace = "namespace";
|
||||||
|
|
@ -64,7 +62,7 @@ const std::string SubExpressionToken = "subexpression_token";
|
||||||
const std::string SubExpression = "subexpression";
|
const std::string SubExpression = "subexpression";
|
||||||
const std::string PrefixedExpression = "prefixed_expression";
|
const std::string PrefixedExpression = "prefixed_expression";
|
||||||
const std::string Expression = "expression";
|
const std::string Expression = "expression";
|
||||||
const std::string SuperExpression = "super_expression";
|
const std::string SuperExpression = "superexpression";
|
||||||
|
|
||||||
const std::string BlockStatement = "block_statement";
|
const std::string BlockStatement = "block_statement";
|
||||||
|
|
||||||
|
|
@ -120,9 +118,9 @@ const std::string TypeclassExpression = "typeclass_expression";
|
||||||
|
|
||||||
const std::string TypeIdentifierDefinition = "type_identifier_definition";
|
const std::string TypeIdentifierDefinition = "type_identifier_definition";
|
||||||
|
|
||||||
const std::string TypeclassIdentifier = "typeclass_identifer";
|
const std::string TypeclassIdentifier = "typeclass_identifier";
|
||||||
const std::string NameIdentifier = "name_identifier";
|
const std::string NameIdentifier = "name_identifier";
|
||||||
const std::string TypeIdentifier = "type_identifer";
|
const std::string TypeIdentifier = "type_identifier";
|
||||||
const std::string AbstractTypeIdentifier = "abstract_type_identifier";
|
const std::string AbstractTypeIdentifier = "abstract_type_identifier";
|
||||||
|
|
||||||
const std::string OperatorIdentifier = "operator_identifier";
|
const std::string OperatorIdentifier = "operator_identifier";
|
||||||
|
|
@ -138,6 +136,4 @@ const std::string Literal = "literal";
|
||||||
|
|
||||||
const std::string NameSubSuperExpression = "name_subsuperexpression";
|
const std::string NameSubSuperExpression = "name_subsuperexpression";
|
||||||
|
|
||||||
} // namespace tokens
|
} // namespace parser::tokens
|
||||||
|
|
||||||
} // namespace parser
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,16 @@ class ParseTree {
|
||||||
public:
|
public:
|
||||||
class Node {
|
class Node {
|
||||||
public:
|
public:
|
||||||
Node() = default;
|
Node() : uninitialized_(true) {
|
||||||
Node(const TSNode &node, const std::string* source) : node_(node), source_(source) {}
|
for (unsigned int& i : node_.context) {
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
node_.id = nullptr;
|
||||||
|
node_.tree = nullptr;
|
||||||
|
|
||||||
|
source_ = nullptr;
|
||||||
|
};
|
||||||
|
Node(const TSNode& node, const std::string* source) : uninitialized_(false), node_(node), source_(source) {}
|
||||||
|
|
||||||
std::string GetType() {
|
std::string GetType() {
|
||||||
return ts_node_type(node_);
|
return ts_node_type(node_);
|
||||||
|
|
@ -81,8 +89,9 @@ public:
|
||||||
// ?? use field id instaed of name ??
|
// ?? use field id instaed of name ??
|
||||||
// ?? node equality check needed ??
|
// ?? node equality check needed ??
|
||||||
private:
|
private:
|
||||||
|
bool uninitialized_;
|
||||||
TSNode node_;
|
TSNode node_;
|
||||||
const std::string* source_ = nullptr;
|
const std::string* source_;
|
||||||
};
|
};
|
||||||
class Cursor { // ?? needed ??
|
class Cursor { // ?? needed ??
|
||||||
public:
|
public:
|
||||||
|
|
@ -106,15 +115,22 @@ public:
|
||||||
|
|
||||||
tree_ = ts_parser_parse_string(
|
tree_ = ts_parser_parse_string(
|
||||||
parser,
|
parser,
|
||||||
NULL,
|
nullptr,
|
||||||
source_.c_str(),
|
source_.c_str(),
|
||||||
source_.size());
|
source_.size());
|
||||||
|
|
||||||
|
ts_parser_delete(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ParseTree(const ParseTree& parse_tree) : tree_(ts_tree_copy(parse_tree.tree_)), source_(parse_tree.source_) {}
|
||||||
|
|
||||||
Node GetRoot() const {
|
Node GetRoot() const {
|
||||||
return Node(ts_tree_root_node(tree_), &source_);
|
return Node(ts_tree_root_node(tree_), &source_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~ParseTree() {
|
||||||
|
ts_tree_delete(tree_);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
TSTree* tree_;
|
TSTree* tree_;
|
||||||
std::string source_; // for token value extraction
|
std::string source_; // for token value extraction
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace interpreter {
|
||||||
|
|
||||||
class PrintVisitor : public Visitor {
|
class PrintVisitor : public Visitor {
|
||||||
public:
|
public:
|
||||||
PrintVisitor(std::ostream& out) : out_(out) {}
|
explicit PrintVisitor(std::ostream& out) : out_(out) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Visit(Node* node) override;
|
void Visit(Node* node) override;
|
||||||
|
|
@ -19,7 +19,7 @@ private:
|
||||||
void Visit(SourceFile* node) override;
|
void Visit(SourceFile* node) override;
|
||||||
void Visit(Sources* node) override;
|
void Visit(Sources* node) override;
|
||||||
|
|
||||||
// Namespaces, partittions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
void Visit(Partition* node) override;
|
void Visit(Partition* node) override;
|
||||||
void Visit(Namespace* node) override;
|
void Visit(Namespace* node) override;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ protected:
|
||||||
virtual void Visit(SourceFile* node) {}
|
virtual void Visit(SourceFile* node) {}
|
||||||
virtual void Visit(Sources* node) {}
|
virtual void Visit(Sources* node) {}
|
||||||
|
|
||||||
// Namespaces, partittions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
virtual void Visit(Partition* node) {}
|
virtual void Visit(Partition* node) {}
|
||||||
virtual void Visit(Namespace* node) {}
|
virtual void Visit(Namespace* node) {}
|
||||||
|
|
|
||||||
BIN
src/.build_visitor.cpp.kate-swp
Normal file
BIN
src/.build_visitor.cpp.kate-swp
Normal file
Binary file not shown.
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
// forclangd
|
// for clangd
|
||||||
#include "../include/build_visitor.hpp"
|
#include "../include/build_visitor.hpp"
|
||||||
#include "../include/parse_token_types.hpp"
|
#include "../include/parse_token_types.hpp"
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ void BuildVisitor::Visit(Sources* node) {
|
||||||
current_node_ = parse_node;
|
current_node_ = parse_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespaces, partittions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
void BuildVisitor::Visit(Partition* node) {
|
void BuildVisitor::Visit(Partition* node) {
|
||||||
auto parse_node = current_node_;
|
auto parse_node = current_node_;
|
||||||
|
|
@ -76,7 +76,7 @@ void BuildVisitor::Visit(Partition* node) {
|
||||||
void BuildVisitor::Visit(Namespace* node) {
|
void BuildVisitor::Visit(Namespace* node) {
|
||||||
auto parse_node = current_node_;
|
auto parse_node = current_node_;
|
||||||
|
|
||||||
auto current_node_ = parse_node.ChildByFieldName("name");
|
current_node_ = parse_node.ChildByFieldName("name");
|
||||||
|
|
||||||
auto current_node_type = current_node_.GetType();
|
auto current_node_type = current_node_.GetType();
|
||||||
|
|
||||||
|
|
@ -380,7 +380,7 @@ void BuildVisitor::Visit(DefinedAnnotatedName* node) {
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
size_t child_count = parse_node.NamedChildCount();
|
||||||
|
|
||||||
if (child_count > 1) {
|
if (child_count > 1) {
|
||||||
auto current_node_ = parse_node.NthNamedChild(1);
|
current_node_ = parse_node.NthNamedChild(1);
|
||||||
|
|
||||||
auto current_node_type = current_node_.GetType();
|
auto current_node_type = current_node_.GetType();
|
||||||
if (current_node_type == parser::tokens::DefinedType) {
|
if (current_node_type == parser::tokens::DefinedType) {
|
||||||
|
|
@ -558,7 +558,7 @@ void BuildVisitor::Visit(MatchCase* node) {
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
size_t child_count = parse_node.NamedChildCount();
|
||||||
|
|
||||||
if (child_count > 1) {
|
if (child_count > 1) {
|
||||||
std::string prefix = parse_node.NthChild(3).GetValue(); // TODO
|
std::string prefix = parse_node.NthChild(2).GetValue(); // TODO
|
||||||
|
|
||||||
if (child_count > 2 || prefix == "?") {
|
if (child_count > 2 || prefix == "?") {
|
||||||
current_node_ = parse_node.ChildByFieldName("condition");
|
current_node_ = parse_node.ChildByFieldName("condition");
|
||||||
|
|
@ -742,9 +742,9 @@ void BuildVisitor::Visit(SubExpressionToken& node) {
|
||||||
|
|
||||||
std::string current_node_type = current_node_.GetType();
|
std::string current_node_type = current_node_.GetType();
|
||||||
|
|
||||||
if (current_node_type == parser::tokens::NameExpression) { // optimize ??
|
if (current_node_type == parser::tokens::NameSuperExpression) { // optimize ??
|
||||||
node = std::make_unique<NameExpression>();
|
node = std::make_unique<NameSuperExpression>();
|
||||||
Visit(std::get<std::unique_ptr<NameExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<NameSuperExpression>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::ScopedStatement) {
|
} else if (current_node_type == parser::tokens::ScopedStatement) {
|
||||||
node = std::make_unique<ScopedStatement>();
|
node = std::make_unique<ScopedStatement>();
|
||||||
Visit(std::get<std::unique_ptr<ScopedStatement>>(node).get());
|
Visit(std::get<std::unique_ptr<ScopedStatement>>(node).get());
|
||||||
|
|
@ -770,7 +770,7 @@ void BuildVisitor::Visit(SubExpression& node) {
|
||||||
Visit(std::get<std::unique_ptr<BinaryOperatorExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<BinaryOperatorExpression>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::SubExpressionToken) {
|
} else if (current_node_type == parser::tokens::SubExpressionToken) {
|
||||||
node = std::make_unique<SubExpressionToken>();
|
node = std::make_unique<SubExpressionToken>();
|
||||||
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node).get());
|
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node));
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
@ -790,7 +790,7 @@ void BuildVisitor::Visit(PrefixedExpression& node) {
|
||||||
Visit(std::get<std::unique_ptr<ReturnExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<ReturnExpression>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::LoopControlExpression) {
|
} else if (current_node_type == parser::tokens::LoopControlExpression) {
|
||||||
node = std::make_unique<LoopControlExpression>();
|
node = std::make_unique<LoopControlExpression>();
|
||||||
Visit(*std::get<std::unique_ptr<LoopControlExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<LoopControlExpression>>(node));
|
||||||
} else if (current_node_type == parser::tokens::Block) {
|
} else if (current_node_type == parser::tokens::Block) {
|
||||||
node = std::make_unique<Block>();
|
node = std::make_unique<Block>();
|
||||||
Visit(std::get<std::unique_ptr<Block>>(node).get());
|
Visit(std::get<std::unique_ptr<Block>>(node).get());
|
||||||
|
|
@ -816,13 +816,13 @@ void BuildVisitor::Visit(Expression& node) {
|
||||||
Visit(std::get<std::unique_ptr<TypeConstructor>>(node).get());
|
Visit(std::get<std::unique_ptr<TypeConstructor>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::PrefixedExpression) {
|
} else if (current_node_type == parser::tokens::PrefixedExpression) {
|
||||||
node = std::make_unique<PrefixedExpression>();
|
node = std::make_unique<PrefixedExpression>();
|
||||||
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node));
|
||||||
} else if (current_node_type == parser::tokens::UnaryOperatorExpression) {
|
} else if (current_node_type == parser::tokens::UnaryOperatorExpression) {
|
||||||
node = std::make_unique<UnaryOperatorExpression>();
|
node = std::make_unique<UnaryOperatorExpression>();
|
||||||
Visit(std::get<std::unique_ptr<UnaryOperatorExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<UnaryOperatorExpression>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::SubExpression) {
|
} else if (current_node_type == parser::tokens::SubExpression) {
|
||||||
node = std::make_unique<SubExpression>();
|
node = std::make_unique<SubExpression>();
|
||||||
Visit(*std::get<std::unique_ptr<SubExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<SubExpression>>(node));
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
@ -839,7 +839,7 @@ void BuildVisitor::Visit(SuperExpression& node) {
|
||||||
|
|
||||||
if (current_node_type == parser::tokens::FlowControl) { // optimize ??
|
if (current_node_type == parser::tokens::FlowControl) { // optimize ??
|
||||||
node = std::make_unique<FlowControl>();
|
node = std::make_unique<FlowControl>();
|
||||||
Visit(*std::get<std::unique_ptr<FlowControl>>(node).get());
|
Visit(*std::get<std::unique_ptr<FlowControl>>(node));
|
||||||
} else if (current_node_type == parser::tokens::TupleExpression) {
|
} else if (current_node_type == parser::tokens::TupleExpression) {
|
||||||
node = std::make_unique<TupleExpression>();
|
node = std::make_unique<TupleExpression>();
|
||||||
Visit(std::get<std::unique_ptr<TupleExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<TupleExpression>>(node).get());
|
||||||
|
|
@ -848,7 +848,7 @@ void BuildVisitor::Visit(SuperExpression& node) {
|
||||||
Visit(std::get<std::unique_ptr<VariantExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<VariantExpression>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::Expression) {
|
} else if (current_node_type == parser::tokens::Expression) {
|
||||||
node = std::make_unique<Expression>();
|
node = std::make_unique<Expression>();
|
||||||
Visit(*std::get<std::unique_ptr<Expression>>(node).get());
|
Visit(*std::get<std::unique_ptr<Expression>>(node));
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
@ -866,7 +866,7 @@ void BuildVisitor::Visit(BlockStatement& node) {
|
||||||
|
|
||||||
if (current_node_type == parser::tokens::Expression) { // optimize ??
|
if (current_node_type == parser::tokens::Expression) { // optimize ??
|
||||||
node = std::make_unique<Expression>();
|
node = std::make_unique<Expression>();
|
||||||
Visit(*std::get<std::unique_ptr<Expression>>(node).get());
|
Visit(*std::get<std::unique_ptr<Expression>>(node));
|
||||||
} else if (current_node_type == parser::tokens::AliasDefinition) {
|
} else if (current_node_type == parser::tokens::AliasDefinition) {
|
||||||
node = std::make_unique<AliasDefinition>();
|
node = std::make_unique<AliasDefinition>();
|
||||||
Visit(std::get<std::unique_ptr<AliasDefinition>>(node).get());
|
Visit(std::get<std::unique_ptr<AliasDefinition>>(node).get());
|
||||||
|
|
@ -875,10 +875,10 @@ void BuildVisitor::Visit(BlockStatement& node) {
|
||||||
Visit(std::get<std::unique_ptr<VariableDefinition>>(node).get());
|
Visit(std::get<std::unique_ptr<VariableDefinition>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::FlowControl) {
|
} else if (current_node_type == parser::tokens::FlowControl) {
|
||||||
node = std::make_unique<FlowControl>();
|
node = std::make_unique<FlowControl>();
|
||||||
Visit(*std::get<std::unique_ptr<FlowControl>>(node).get());
|
Visit(*std::get<std::unique_ptr<FlowControl>>(node));
|
||||||
} else if (current_node_type == parser::tokens::PrefixedExpression) {
|
} else if (current_node_type == parser::tokens::PrefixedExpression) {
|
||||||
node = std::make_unique<PrefixedExpression>();
|
node = std::make_unique<PrefixedExpression>();
|
||||||
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node));
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
@ -986,10 +986,10 @@ void BuildVisitor::Visit(FunctionArgument& node) {
|
||||||
|
|
||||||
if (current_node_type == parser::tokens::SubExpressionToken) { // optimize ??
|
if (current_node_type == parser::tokens::SubExpressionToken) { // optimize ??
|
||||||
node = std::make_unique<SubExpressionToken>();
|
node = std::make_unique<SubExpressionToken>();
|
||||||
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node).get());
|
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node));
|
||||||
} else if (current_node_type == parser::tokens::TypeSubExpression) {
|
} else if (current_node_type == parser::tokens::TypeSubExpression) {
|
||||||
node = std::make_unique<TypeSubExpression>();
|
node = std::make_unique<TypeSubExpression>();
|
||||||
Visit(*std::get<std::unique_ptr<TypeSubExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<TypeSubExpression>>(node));
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
@ -1043,7 +1043,7 @@ void BuildVisitor::Visit(NameSuperExpression* node) {
|
||||||
current_node_ = parse_node.NthNamedChild(i);
|
current_node_ = parse_node.NthNamedChild(i);
|
||||||
std::string current_node_type = current_node_.GetType();
|
std::string current_node_type = current_node_.GetType();
|
||||||
|
|
||||||
if (current_node_type != parser::tokens::TypeSubExpression) {
|
if (current_node_type != parser::tokens::TypeSubExpression && !namespaces_ended) {
|
||||||
namespaces_ended = true;
|
namespaces_ended = true;
|
||||||
|
|
||||||
if (i + 1 == child_count) {
|
if (i + 1 == child_count) {
|
||||||
|
|
@ -1053,11 +1053,13 @@ void BuildVisitor::Visit(NameSuperExpression* node) {
|
||||||
node->expressions.back() = std::make_unique<NameIdentifier>(current_node_.GetValue());
|
node->expressions.back() = std::make_unique<NameIdentifier>(current_node_.GetValue());
|
||||||
} else if (current_node_type == parser::tokens::Literal) {
|
} else if (current_node_type == parser::tokens::Literal) {
|
||||||
node->expressions.back() = std::make_unique<Literal>();
|
node->expressions.back() = std::make_unique<Literal>();
|
||||||
Visit(*std::get<std::unique_ptr<Literal>>(node->expressions.back()).get());
|
Visit(*std::get<std::unique_ptr<Literal>>(node->expressions.back()));
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
// error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1172,27 +1174,27 @@ void BuildVisitor::Visit(AnyName& node) {
|
||||||
// Type
|
// Type
|
||||||
|
|
||||||
void BuildVisitor::Visit(TypeConstructor* node) {
|
void BuildVisitor::Visit(TypeConstructor* node) {
|
||||||
// auto parse_node = current_node_;
|
auto parse_node = current_node_;
|
||||||
//
|
|
||||||
// current_node_ = parse_node.ChildByFieldName("type");
|
current_node_ = parse_node.ChildByFieldName("type");
|
||||||
// node->type = std::make_unique<ParametrizedType>();
|
node->type = std::make_unique<ParametrizedType>();
|
||||||
// Visit(node->type.get());
|
Visit(node->type.get());
|
||||||
//
|
|
||||||
// size_t parameter_count = (parse_node.NamedChildCount() - 1) / 2;
|
size_t parameter_count = (parse_node.NamedChildCount() - 1) / 2;
|
||||||
//
|
|
||||||
// node->parameters.resize(parameter_count);
|
node->parameters.resize(parameter_count);
|
||||||
//
|
|
||||||
// for (size_t i = 0; i < parameter_count * 2; ++i) {
|
for (size_t i = 0; i < parameter_count * 2; ++i) {
|
||||||
// current_node_ = parse_node.NthNamedChild(i + 1);
|
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||||
//
|
|
||||||
// if (i % 2 == 0) {
|
if (i % 2 == 0) {
|
||||||
// node->parameters[i / 2].first = current_node_.GetValue();
|
node->parameters[i / 2].first = current_node_.GetValue();
|
||||||
// } else {
|
} else {
|
||||||
// Visit(node->parameters[i / 2].second);
|
Visit(node->parameters[i / 2].second);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// current_node_ = parse_node;
|
current_node_ = parse_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildVisitor::Visit(TupleType* node) {
|
void BuildVisitor::Visit(TupleType* node) {
|
||||||
|
|
@ -1397,7 +1399,7 @@ void BuildVisitor::Visit(TypeParameter& node) {
|
||||||
Visit(std::get<std::unique_ptr<ParametrizedType>>(node).get());
|
Visit(std::get<std::unique_ptr<ParametrizedType>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::Expression) {
|
} else if (current_node_type == parser::tokens::Expression) {
|
||||||
node = std::make_unique<Expression>();
|
node = std::make_unique<Expression>();
|
||||||
Visit(*std::get<std::unique_ptr<Expression>>(node).get());
|
Visit(*std::get<std::unique_ptr<Expression>>(node));
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
@ -1487,11 +1489,11 @@ void BuildVisitor::Visit(AnyIdentifier* node) { // std::string
|
||||||
} // TODO use in other places ??
|
} // TODO use in other places ??
|
||||||
|
|
||||||
void BuildVisitor::Visit(FloatNumberLiteral* node) {
|
void BuildVisitor::Visit(FloatNumberLiteral* node) {
|
||||||
node->value = std::stod(current_node_.NthChild(0).GetValue());
|
node->value = std::stod(current_node_.GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildVisitor::Visit(NumberLiteral* node) {
|
void BuildVisitor::Visit(NumberLiteral* node) {
|
||||||
node->value = std::stoll(current_node_.NthChild(0).GetValue());
|
node->value = std::stoll(current_node_.GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildVisitor::Visit(StringLiteral* node) {
|
void BuildVisitor::Visit(StringLiteral* node) {
|
||||||
|
|
@ -1536,14 +1538,14 @@ void BuildVisitor::Visit(NameSubSuperExpression& node) {
|
||||||
std::string current_node_type = current_node_.GetType();
|
std::string current_node_type = current_node_.GetType();
|
||||||
|
|
||||||
if (current_node_type == parser::tokens::NameIdentifier) { // optimize ??
|
if (current_node_type == parser::tokens::NameIdentifier) { // optimize ??
|
||||||
node = std::make_unique<NameIdentifier>();
|
// TODO: choose node = std::make_unique<NameIdentifier>(current_node_.GetValue());
|
||||||
Visit(std::get<std::unique_ptr<NameIdentifier>>(node).get());
|
Visit(std::get<std::unique_ptr<NameIdentifier>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::Literal) {
|
} else if (current_node_type == parser::tokens::Literal) {
|
||||||
node = std::make_unique<Literal>();
|
node = std::make_unique<Literal>();
|
||||||
Visit(*std::get<std::unique_ptr<Literal>>(node).get());
|
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||||
} else if (current_node_type == parser::tokens::SuperExpression) {
|
} else if (current_node_type == parser::tokens::SuperExpression) {
|
||||||
node = std::make_unique<SuperExpression>();
|
node = std::make_unique<SuperExpression>();
|
||||||
Visit(*std::get<std::unique_ptr<SuperExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<SuperExpression>>(node));
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,5 @@ int main(int argc, char** argv) { // TODO, only test version
|
||||||
interpreter::PrintVisitor print_visitor(std::cout);
|
interpreter::PrintVisitor print_visitor(std::cout);
|
||||||
|
|
||||||
build_visitor.VisitSourceFile(source_file.get());
|
build_visitor.VisitSourceFile(source_file.get());
|
||||||
//print_visitor.VisitSourceFile(source_file.get());
|
print_visitor.VisitSourceFile(source_file.get());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ void PrintVisitor::Visit(Sources* node) {
|
||||||
out_ << "\n)\n";
|
out_ << "\n)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespaces, partittions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
void PrintVisitor::Visit(Partition* node) {
|
void PrintVisitor::Visit(Partition* node) {
|
||||||
out_ << "(Partition ";
|
out_ << "(Partition ";
|
||||||
|
|
@ -82,7 +82,7 @@ void PrintVisitor::Visit(Namespace* node) {
|
||||||
|
|
||||||
void PrintVisitor::Visit(ImportStatement* node) {
|
void PrintVisitor::Visit(ImportStatement* node) {
|
||||||
out_ << "(Import \"" << node->module_name << "\" ";
|
out_ << "(Import \"" << node->module_name << "\" ";
|
||||||
if (node->symbols.size() > 0) {
|
if (!node->symbols.empty()) {
|
||||||
out_ << '\n';
|
out_ << '\n';
|
||||||
}
|
}
|
||||||
for (auto& symbol : node->symbols) {
|
for (auto& symbol : node->symbols) {
|
||||||
|
|
@ -157,7 +157,7 @@ void PrintVisitor::Visit(TypeDefinition* node) {
|
||||||
void PrintVisitor::Visit(TypeclassDefinition* node) {
|
void PrintVisitor::Visit(TypeclassDefinition* node) {
|
||||||
out_ << "(Typeclass ";
|
out_ << "(Typeclass ";
|
||||||
Visit(node->typeclass.get());
|
Visit(node->typeclass.get());
|
||||||
if (node->requirements.size() > 0) {
|
if (!node->requirements.empty()) {
|
||||||
out_ << " : \n";
|
out_ << " : \n";
|
||||||
}
|
}
|
||||||
for (auto& requirement : node->requirements) {
|
for (auto& requirement : node->requirements) {
|
||||||
|
|
@ -172,13 +172,13 @@ void PrintVisitor::Visit(TypeclassDefinition* node) {
|
||||||
void PrintVisitor::Visit(DefinedName* node) {
|
void PrintVisitor::Visit(DefinedName* node) {
|
||||||
out_ << "(DefinedName ";
|
out_ << "(DefinedName ";
|
||||||
Visit(&node->name);
|
Visit(&node->name);
|
||||||
if (node->parameters.size() > 0) {
|
if (!node->parameters.empty()) {
|
||||||
out_ << "\n";
|
out_ << "\n";
|
||||||
}
|
}
|
||||||
for (auto& parameter : node->parameters) {
|
for (auto& parameter : node->parameters) {
|
||||||
Visit(parameter.get());
|
Visit(parameter.get());
|
||||||
}
|
}
|
||||||
if (node->arguments.size() > 0) {
|
if (!node->arguments.empty()) {
|
||||||
out_ << " : \n";
|
out_ << " : \n";
|
||||||
}
|
}
|
||||||
for (auto& argument : node->arguments) {
|
for (auto& argument : node->arguments) {
|
||||||
|
|
@ -204,13 +204,13 @@ void PrintVisitor::Visit(DefinedAnnotatedName* node) {
|
||||||
void PrintVisitor::Visit(DefinedType* node) {
|
void PrintVisitor::Visit(DefinedType* node) {
|
||||||
out_ << "(DefinedType ";
|
out_ << "(DefinedType ";
|
||||||
Visit(node->type.get());
|
Visit(node->type.get());
|
||||||
if (node->parameters.size() > 0) {
|
if (!node->parameters.empty()) {
|
||||||
out_ << "\n";
|
out_ << "\n";
|
||||||
}
|
}
|
||||||
for (auto& parameter : node->parameters) {
|
for (auto& parameter : node->parameters) {
|
||||||
Visit(parameter.get());
|
Visit(parameter.get());
|
||||||
}
|
}
|
||||||
if (node->arguments.size() > 0) {
|
if (!node->arguments.empty()) {
|
||||||
out_ << " : \n";
|
out_ << " : \n";
|
||||||
}
|
}
|
||||||
for (auto& argument : node->arguments) {
|
for (auto& argument : node->arguments) {
|
||||||
|
|
@ -222,13 +222,13 @@ void PrintVisitor::Visit(DefinedType* node) {
|
||||||
void PrintVisitor::Visit(DefinedTypeclass* node) {
|
void PrintVisitor::Visit(DefinedTypeclass* node) {
|
||||||
out_ << "(DefinedTypeclass ";
|
out_ << "(DefinedTypeclass ";
|
||||||
Visit(node->typeclass.get());
|
Visit(node->typeclass.get());
|
||||||
if (node->parameters.size() > 0) {
|
if (!node->parameters.empty()) {
|
||||||
out_ << "\n";
|
out_ << "\n";
|
||||||
}
|
}
|
||||||
for (auto& parameter : node->parameters) {
|
for (auto& parameter : node->parameters) {
|
||||||
Visit(parameter.get());
|
Visit(parameter.get());
|
||||||
}
|
}
|
||||||
if (node->arguments.size() > 0) {
|
if (!node->arguments.empty()) {
|
||||||
out_ << " : \n";
|
out_ << " : \n";
|
||||||
}
|
}
|
||||||
for (auto& argument : node->arguments) {
|
for (auto& argument : node->arguments) {
|
||||||
|
|
@ -238,7 +238,7 @@ void PrintVisitor::Visit(DefinedTypeclass* node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintVisitor::Visit(DefinitionParameter* node) {
|
void PrintVisitor::Visit(DefinitionParameter* node) {
|
||||||
out_ << "(DefinitionParameter " << (node->typeclasses.size() > 0 ? "(" : "");
|
out_ << "(DefinitionParameter " << (!node->typeclasses.empty() > 0 ? "(" : "");
|
||||||
Visit(&node->type);
|
Visit(&node->type);
|
||||||
out_ << ' ';
|
out_ << ' ';
|
||||||
for (auto& typeclass : node->typeclasses) {
|
for (auto& typeclass : node->typeclasses) {
|
||||||
|
|
@ -248,7 +248,7 @@ void PrintVisitor::Visit(DefinitionParameter* node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintVisitor::Visit(DefinitionArgument* node) {
|
void PrintVisitor::Visit(DefinitionArgument* node) {
|
||||||
out_ << "(DefinitionArgument " << (node->types.size() > 0 ? "(" : "");
|
out_ << "(DefinitionArgument " << (!node->types.empty() ? "(" : "");
|
||||||
Visit(&node->name);
|
Visit(&node->name);
|
||||||
out_ << ' ';
|
out_ << ' ';
|
||||||
for (auto& type : node->types) {
|
for (auto& type : node->types) {
|
||||||
|
|
@ -428,7 +428,7 @@ void PrintVisitor::Visit(LambdaFunction* node) {
|
||||||
for (auto& parameter : node->parameters) {
|
for (auto& parameter : node->parameters) {
|
||||||
Visit(parameter.get());
|
Visit(parameter.get());
|
||||||
}
|
}
|
||||||
if (node->parameters.size() > 0) {
|
if (!node->parameters.empty()) {
|
||||||
out_ << " : ";
|
out_ << " : ";
|
||||||
}
|
}
|
||||||
for (auto& argument : node->arguments) {
|
for (auto& argument : node->arguments) {
|
||||||
|
|
@ -553,7 +553,7 @@ void PrintVisitor::Visit(VariantType* node) {
|
||||||
void PrintVisitor::Visit(AnnotatedType* node) {
|
void PrintVisitor::Visit(AnnotatedType* node) {
|
||||||
out_ << "(AnnotatedType ";
|
out_ << "(AnnotatedType ";
|
||||||
Visit(node->type_expression.get());
|
Visit(node->type_expression.get());
|
||||||
if (node->annotations.size() > 0) {
|
if (!node->annotations.empty()) {
|
||||||
out_ << " :";
|
out_ << " :";
|
||||||
}
|
}
|
||||||
for (auto& annotation : node->annotations) {
|
for (auto& annotation : node->annotations) {
|
||||||
|
|
@ -566,9 +566,9 @@ void PrintVisitor::Visit(AnnotatedType* node) {
|
||||||
void PrintVisitor::Visit(ParametrizedType* node) {
|
void PrintVisitor::Visit(ParametrizedType* node) {
|
||||||
out_ << "(ParametrizedType ";
|
out_ << "(ParametrizedType ";
|
||||||
Visit(node->type_expression.get());
|
Visit(node->type_expression.get());
|
||||||
for (auto& paramater : node->parameters) {
|
for (auto& parameter : node->parameters) {
|
||||||
out_ << ' ';
|
out_ << ' ';
|
||||||
Visitor::Visit(paramater);
|
Visitor::Visit(parameter);
|
||||||
}
|
}
|
||||||
out_ << " )";
|
out_ << " )";
|
||||||
}
|
}
|
||||||
|
|
@ -588,7 +588,7 @@ void PrintVisitor::Visit(TypeExpression* node) {
|
||||||
void PrintVisitor::Visit(AnnotatedTypeclass* node) {
|
void PrintVisitor::Visit(AnnotatedTypeclass* node) {
|
||||||
out_ << "(AnnotatedTypeclass ";
|
out_ << "(AnnotatedTypeclass ";
|
||||||
Visit(node->typeclass_expression.get());
|
Visit(node->typeclass_expression.get());
|
||||||
if (node->annotations.size() > 0) {
|
if (!node->annotations.empty()) {
|
||||||
out_ << " :";
|
out_ << " :";
|
||||||
}
|
}
|
||||||
for (auto& annotation : node->annotations) {
|
for (auto& annotation : node->annotations) {
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ void Visitor::Visit(FlowControl& node) {
|
||||||
void Visitor::Visit(SubExpressionToken& node) {
|
void Visitor::Visit(SubExpressionToken& node) {
|
||||||
switch (node.index()) {
|
switch (node.index()) {
|
||||||
case 0:
|
case 0:
|
||||||
Visit(std::get<std::unique_ptr<NameExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<NameSuperExpression>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Visit(std::get<std::unique_ptr<ScopedStatement>>(node).get());
|
Visit(std::get<std::unique_ptr<ScopedStatement>>(node).get());
|
||||||
|
|
@ -135,7 +135,7 @@ void Visitor::Visit(SubExpression& node) {
|
||||||
Visit(std::get<std::unique_ptr<BinaryOperatorExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<BinaryOperatorExpression>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node).get());
|
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error
|
// error
|
||||||
|
|
@ -149,7 +149,7 @@ void Visitor::Visit(PrefixedExpression& node) {
|
||||||
Visit(std::get<std::unique_ptr<ReturnExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<ReturnExpression>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Visit(*std::get<std::unique_ptr<LoopControlExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<LoopControlExpression>>(node));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Visit(std::get<std::unique_ptr<Block>>(node).get());
|
Visit(std::get<std::unique_ptr<Block>>(node).get());
|
||||||
|
|
@ -169,13 +169,13 @@ void Visitor::Visit(Expression& node) {
|
||||||
Visit(std::get<std::unique_ptr<TypeConstructor>>(node).get());
|
Visit(std::get<std::unique_ptr<TypeConstructor>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
Visit(std::get<std::unique_ptr<UnaryOperatorExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<UnaryOperatorExpression>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
Visit(*std::get<std::unique_ptr<SubExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<SubExpression>>(node));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error
|
// error
|
||||||
|
|
@ -186,7 +186,7 @@ void Visitor::Visit(Expression& node) {
|
||||||
void Visitor::Visit(SuperExpression& node) {
|
void Visitor::Visit(SuperExpression& node) {
|
||||||
switch (node.index()) {
|
switch (node.index()) {
|
||||||
case 0:
|
case 0:
|
||||||
Visit(*std::get<std::unique_ptr<FlowControl>>(node).get());
|
Visit(*std::get<std::unique_ptr<FlowControl>>(node));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Visit(std::get<std::unique_ptr<TupleExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<TupleExpression>>(node).get());
|
||||||
|
|
@ -195,7 +195,7 @@ void Visitor::Visit(SuperExpression& node) {
|
||||||
Visit(std::get<std::unique_ptr<VariantExpression>>(node).get());
|
Visit(std::get<std::unique_ptr<VariantExpression>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
Visit(*std::get<std::unique_ptr<Expression>>(node).get());
|
Visit(*std::get<std::unique_ptr<Expression>>(node));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error
|
// error
|
||||||
|
|
@ -208,7 +208,7 @@ void Visitor::Visit(SuperExpression& node) {
|
||||||
void Visitor::Visit(BlockStatement& node) {
|
void Visitor::Visit(BlockStatement& node) {
|
||||||
switch (node.index()) {
|
switch (node.index()) {
|
||||||
case 0:
|
case 0:
|
||||||
Visit(*std::get<std::unique_ptr<Expression>>(node).get());
|
Visit(*std::get<std::unique_ptr<Expression>>(node));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Visit(std::get<std::unique_ptr<AliasDefinition>>(node).get());
|
Visit(std::get<std::unique_ptr<AliasDefinition>>(node).get());
|
||||||
|
|
@ -217,10 +217,10 @@ void Visitor::Visit(BlockStatement& node) {
|
||||||
Visit(std::get<std::unique_ptr<VariableDefinition>>(node).get());
|
Visit(std::get<std::unique_ptr<VariableDefinition>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
Visit(*std::get<std::unique_ptr<FlowControl>>(node).get());
|
Visit(*std::get<std::unique_ptr<FlowControl>>(node));
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error
|
// error
|
||||||
|
|
@ -233,10 +233,10 @@ void Visitor::Visit(BlockStatement& node) {
|
||||||
void Visitor::Visit(FunctionArgument& node) {
|
void Visitor::Visit(FunctionArgument& node) {
|
||||||
switch (node.index()) {
|
switch (node.index()) {
|
||||||
case 0:
|
case 0:
|
||||||
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node).get());
|
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Visit(*std::get<std::unique_ptr<TypeSubExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<TypeSubExpression>>(node));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error
|
// error
|
||||||
|
|
@ -307,7 +307,7 @@ void Visitor::Visit(TypeParameter& node) {
|
||||||
Visit(std::get<std::unique_ptr<ParametrizedType>>(node).get());
|
Visit(std::get<std::unique_ptr<ParametrizedType>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Visit(*std::get<std::unique_ptr<Expression>>(node).get());
|
Visit(*std::get<std::unique_ptr<Expression>>(node));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error
|
// error
|
||||||
|
|
@ -345,10 +345,10 @@ void Visitor::Visit(NameSubSuperExpression& node) {
|
||||||
Visit(std::get<std::unique_ptr<NameIdentifier>>(node).get());
|
Visit(std::get<std::unique_ptr<NameIdentifier>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Visit(*std::get<std::unique_ptr<Literal>>(node).get());
|
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Visit(*std::get<std::unique_ptr<SuperExpression>>(node).get());
|
Visit(*std::get<std::unique_ptr<SuperExpression>>(node));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error
|
// error
|
||||||
|
|
@ -356,4 +356,4 @@ void Visitor::Visit(NameSubSuperExpression& node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace interpreter
|
} // namespace interpreter
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
namespace Employee {
|
namespace Employee {
|
||||||
decl gen_employee : Unit -> Employee
|
decl gen_employee : Unit -> Employee
|
||||||
def gen_employee = {
|
def gen_employee = {
|
||||||
; a = b + c
|
|
||||||
return
|
return
|
||||||
$Employee
|
$Employee
|
||||||
& name = "John"
|
& name = "John"
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ def fact : n =
|
||||||
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> Array 'H
|
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> Array 'H
|
||||||
def find_prefix_hashes ('H : (#AccHash Char)) : str = {
|
def find_prefix_hashes ('H : (#AccHash Char)) : str = {
|
||||||
var hashes = (Array 'H).new (str.size + 1)
|
var hashes = (Array 'H).new (str.size + 1)
|
||||||
|
|
||||||
; hashes.0 = 'H.of str.0
|
; hashes.0 = 'H.of str.0
|
||||||
for i in 1..hashes.size do {
|
for i in 1..hashes.size do {
|
||||||
; hashes.i = hashes.(i - 1).clone
|
; hashes.i = hashes.(i - 1).clone
|
||||||
|
|
@ -68,3 +67,4 @@ decl mul_10 : Int -> Int
|
||||||
def mul_10 = mul 10 // or argument can be used
|
def mul_10 = mul 10 // or argument can be used
|
||||||
|
|
||||||
// ?? is partial application feature needed ??
|
// ?? is partial application feature needed ??
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue