-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.cpp
More file actions
40 lines (35 loc) · 988 Bytes
/
mod.cpp
File metadata and controls
40 lines (35 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#line 899 "1_fn-gen.md"
#include "mod.h"
#include "proc.h"
Module::Ptr Module::create(std::string name, Declaration::Ptr parent) {
auto result { Ptr { new Module { name, parent } } };
if (parent) { parent->insert(result); }
return result;
}
Module::Ptr Module::parse(Lexer &l, Declaration::Ptr parent) {
l.consume(Token::Kind::MODULE);
l.expect(Token::Kind::identifier);
auto module_name { l.representation() };
l.advance();
l.consume(Token::Kind::semicolon);
auto mod { create(module_name, parent) };
// imports
// types
// consts
// vars
while (l.is(Token::Kind::PROCEDURE)) {
Procedure::parse(l, mod);
}
Procedure::parse_init(l, mod);
l.consume(Token::Kind::END);
l.expect(Token::Kind::identifier);
if (l.representation() != module_name) {
err(quote(mod), " does not match END ", quote(l.representation()));
}
l.advance();
l.consume(Token::Kind::period);
return mod;
}
std::string Module::mangle(std::string name) {
return this->name() + "_" + name;
}