4
Copyright (c) 2019 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo/loom
9
#include "simodo/variable/convert/Ast.h"
10
#include "simodo/inout/convert/functions.h"
14
namespace simodo::variable
17
Value toValue(const ast::Tree & tree)
19
return std::make_shared<Object>(VariableSet_t {{
20
{u"files", toValue(tree.files())},
21
{u"root", toValue(tree.root())},
25
Value toValue(const inout::uri_set_t & files)
27
std::vector<Value> file_set;
29
for(const std::string & s : files)
30
file_set.push_back(inout::toU16(s));
32
return std::make_shared<Array>( file_set );
35
Value toValue(const ast::Node & node)
37
return std::make_shared<Object>(VariableSet_t {{
38
{u"host", node.host()},
39
{u"operation", node.operation()},
40
{u"token", toValue(node.token())},
41
{u"bound", toValue(node.bound())},
42
{u"branches", toValue(node.branches())},
46
Value toValue(const inout::Token & token)
48
return std::make_shared<Object>(VariableSet_t {{
49
{u"type", static_cast<int64_t>(token.type())},
50
{u"lexeme", token.lexeme()},
51
{u"token", token.token()},
52
{u"qualification", static_cast<int64_t>(token.qualification())},
53
{u"context", static_cast<int64_t>(token.context())},
54
{u"location", toValue(token.location())},
58
Value toValue(const inout::TokenLocation & location)
60
return std::make_shared<Object>(VariableSet_t {{
61
{u"uri_index", location.uri_index()},
62
{u"range", toValue(location.range())},
66
Value toValue(const inout::Range & range)
68
return std::make_shared<Object>(VariableSet_t {{
69
{u"start", toValue(range.start())},
70
{u"end", toValue(range.end())},
74
Value toValue(const inout::Position & position)
76
return std::make_shared<Object>(VariableSet_t {{
77
{u"line", static_cast<int64_t>(position.line())},
78
{u"character", static_cast<int64_t>(position.character())},
82
Value toValue(const std::vector<ast::Node> & branches)
84
std::vector<Value> branch_values;
86
for(const ast::Node & node : branches)
87
branch_values.push_back(toValue(node));
89
return std::make_shared<Array>( branch_values );