blob: 620a1fce8d6e236bfe9dd5950a5d3fbcedb4a519 (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
*/
#include "preproc.hpp"
#include "../ast/ast.hpp"
#include "parseerror.hpp"
#include <cassert>
AST::Path Parse_Path(TokenStream& lex)
{
AST::Path path;
for(;;)
{
Token tok = lex.getToken();
if(tok.type() != TOK_IDENT)
throw ParseError::Unexpected(tok);
path.append( tok.str() );
tok = lex.getToken();
if(tok.type() != TOK_DOUBLE_COLON) {
lex.putback(tok);
break;
}
}
return path;
}
AST::Module Parse_ModRoot(bool is_own_file, Preproc& lex)
{
AST::Module mod;
for(;;)
{
bool is_public = false;
Token tok = lex.getToken();
switch(tok.type())
{
case TOK_BRACE_CLOSE:
if( is_own_file )
throw ParseError::Unexpected(tok);
return mod;
case TOK_EOF:
if( !is_own_file )
throw ParseError::Unexpected(tok);
return mod;
case TOK_RWORD_PUB:
assert(!is_public);
is_public = false;
break;
case TOK_RWORD_USE:
mod.add_alias( Parse_Path(lex) );
tok = lex.getToken();
if( tok.type() != TOK_SEMICOLON )
throw ParseError::Unexpected(tok, Token(TOK_SEMICOLON));
break;
case TOK_RWORD_CONST:
//mod.add_constant(is_public, name, type, value);
throw ParseError::Todo("modroot const");
case TOK_RWORD_STATIC:
//mod.add_global(is_public, is_mut, name, type, value);
throw ParseError::Todo("modroot static");
case TOK_RWORD_FN:
throw ParseError::Todo("modroot fn");
case TOK_RWORD_STRUCT:
throw ParseError::Todo("modroot struct");
default:
throw ParseError::Unexpected(tok);
}
}
}
void Parse_Crate(::std::string mainfile)
{
Preproc lex(mainfile);
AST::Module rootmodule = Parse_ModRoot(true, lex);
}
|