annotate parser/Parser.d @ 144:6e6355fb5f0f

- Parsing nested attributes. - Creating classes and interfaces in AST. - Updated AstPrinter to print attributes, classes and interfaces.
author Anders Johnsen <skabet@gmail.com>
date Mon, 21 Jul 2008 17:41:40 +0200
parents d76cc5cad4fc
children 8c09fdaa724e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1 module parser.Parser;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
2
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
3 import lexer.Lexer,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
4 lexer.Token;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
5
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
6 import parser.Action;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
7
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
8 import basic.Message,
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
9 basic.Attribute;
21
0fb2d13dce37 Now working with gdc also (gdc use reverse paremeter validating on function calls)
johnsen@johnsen-laptop
parents: 12
diff changeset
10
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
11 import basic.SmallArray,
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
12 basic.SourceManager;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
13
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
14 import tango.io.Stdout,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
15 Integer = tango.text.convert.Integer;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
16
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
17 class Parser
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
18 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
19 Action action;
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
20 MessageHandler messages;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
21 alias Object Exp;
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
22 alias Object Stmt;
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
23 alias Object Decl;
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
24 alias Object Module;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
25
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
26 this(MessageHandler messages)
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
27 {
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
28 this.messages = messages;
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
29 }
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
30
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
31 Module parse(SourceManager sm, Lexer lexer, Action act)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
32 {
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
33 this.sm = sm;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
34 this.lexer = lexer;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
35 this.action = act;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
36
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
37 Module m;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
38 if ( isa(Tok.Module) )
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
39 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
40 Token _module = next;
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
41 ModuleName name = parseModuleName();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
42 m = action.actOnModule(_module, sm.getText(name.asRange()));
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
43 require(Tok.Seperator);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
44 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
45 else
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
46 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
47 SLoc loc = peek.location;
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
48 m = action.actOnImplicitModule(loc, sm.getFile(loc));
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
49 }
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
50
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
51 auto nes = parseAttributeInit;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
52 while( !isa(Tok.EOF) )
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
53 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
54 while ( peek.isAttribute )
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
55 nes ~= parseAttribute(nes[$-1]);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
56
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
57 foreach (d; parseDeclDef(nes[$-1].a))
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
58 action.actOnModuleDecl(m, d);
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
59
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
60 nes = parseAttributeScope(nes);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
61 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
62
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
63 return m;
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
64 }
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
65
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
66 private:
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
67 Decl[] parseDeclDef(Attribute a)
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
68 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
69 if ( isa (Tok.Import) )
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
70 return parseImports();
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
71
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
72 return [parseDecl(a)];
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
73 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
74
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
75 Decl parseDecl(Attribute att)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
76 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
77 Token t = peek;
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
78
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
79 if (t.isBasicType || t.isIdentifier)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
80 {
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
81 Id type;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
82 Id iden;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
83 int len = peekParseType;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
84 if (peek(len).type == Tok.Identifier && len != 0)
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
85 {
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
86 type = parseType;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
87 parseDeclAfterInvalidType:
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
88 iden = Id(require(Tok.Identifier));
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
89 if ( isa(Tok.Seperator) )
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
90 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
91 Token sep = next;
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
92 return action.actOnDeclarator(type, iden, null, att);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
93 }
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
94 else if ( isa(Tok.Assign) )
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
95 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
96 Token assign = next();
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
97 Exp exp = parseExpression();
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
98 require(Tok.Seperator);
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
99 return action.actOnDeclarator(type, iden, exp, att);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
100 }
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
101 else if ( isa(Tok.OpenParentheses) )
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
102 return parseFunc(type, iden, att);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
103 else
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
104 messages.report(UnexpectedTok, next.location).arg(next.getType);
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
105 return null;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
106 }
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
107 t = peek(len);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
108 messages.report(InvalidDeclType, t.location)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
109 .arg(sm.getText(t.asRange));
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
110 while(len--)
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
111 next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
112 while(peek.type != Tok.Identifier)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
113 next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
114 type = Id(peek);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
115 goto parseDeclAfterInvalidType;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
116 }
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
117 else if (t.type == Tok.Struct)
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
118 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
119 Id type = Id(next);
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
120 Id iden = Id(require(Tok.Identifier));
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
121
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
122 return parseStruct(type, iden, att);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
123 }
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
124 else if (t.type == Tok.Class)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
125 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
126 Id type = Id(next);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
127 Id iden = Id(require(Tok.Identifier));
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
128
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
129 return parseClass(type, iden, att);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
130 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
131 else if (t.type == Tok.Interface)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
132 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
133 Id type = Id(next);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
134 Id iden = Id(require(Tok.Identifier));
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
135
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
136 return parseInterface(type, iden, att);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
137 }
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
138 messages.report(UnexpectedTok, t.location)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
139 .arg(t.getType)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
140 .arg(Tok.Identifier)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
141 .fatal(ExitLevel.Parser);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
142 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
143
140
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
144 Extern parseLinkageType()
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
145 {
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
146 Extern e = Extern.D;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
147 if(peek(1).type != Tok.OpenParentheses)
140
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
148 return e;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
149
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
150 next; next;
140
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
151
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
152 Token t = require(Tok.Identifier);
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
153
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
154 switch(sm.getText(t.asRange))
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
155 {
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
156 case "C":
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
157 if (peek(0).type == Tok.Plus &&
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
158 peek(1).type == Tok.Plus)
140
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
159 e = Extern.CPlusPlus;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
160 else
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
161 e = Extern.C;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
162 break;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
163 case "D":
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
164 break;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
165 case "Windows":
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
166 e = Extern.Windows;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
167 break;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
168 case "Pascal":
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
169 e = Extern.Pascal;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
170 break;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
171 case "System":
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
172 e = Extern.System;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
173 break;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
174 default:
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
175 messages.report(UnexpectedLinkType, t.location);
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
176 }
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
177
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
178 require(Tok.CloseParentheses);
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
179
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
180 return e;
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
181 }
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
182
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
183 /**
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
184 Parse a series of imports belonging to a single import token.
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
185 */
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
186 Decl[] parseImports()
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
187 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
188 Token _import = require(Tok.Import);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
189 SmallArray!(Decl) res;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
190 void addToRes(Decl d) { res ~= d; }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
191
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
192 bool done = false;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
193 while (!done && !isa(Tok.Seperator))
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
194 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
195 ModuleName mod = parseModuleName();
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
196 Token tok = peek;
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
197 switch (tok.type)
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
198 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
199 case Tok.Comma:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
200 // import A, B.C;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
201 // parse another module-name
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
202 next();
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
203 res ~= action.actOnImport(_import, mod, null);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
204 break;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
205 case Tok.Assign:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
206 // import B = A.A;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
207 // ^- must be a single identifier
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
208 // renamed import
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
209 if (mod.packages.length != 0)
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
210 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
211 SLoc loc = mod.packages[0].tok.location;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
212 messages.report(RenameMustBeSingleIdent, loc);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
213 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
214 //if (isStatic)
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
215 // error("Static imports cannot be renamed");
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
216 next();
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
217 Id name = mod.id;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
218 mod = parseModuleName();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
219 // create from mod and rename to `name`
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
220 res ~= action.actOnImport(_import, mod, &name);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
221 break;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
222 case Tok.Colon:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
223 // import A : a;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
224 // selective imports, potentially import A : print = a
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
225 next();
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
226 Decl d = action.actOnImport(_import, mod, null);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
227 // do-while on a comma:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
228 // add explicit symbol
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
229 do
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
230 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
231 Id sym = parseIdentifier();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
232 Id dummy;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
233 Id* name = null;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
234 if (skip(Tok.Assign))
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
235 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
236 dummy = sym;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
237 name = &dummy;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
238 sym = parseIdentifier();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
239 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
240 action.addSelectiveImport(d, sym, name);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
241
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
242 } while (skip(Tok.Comma));
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
243 require(Tok.Seperator);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
244 res ~= d;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
245 return res.safe();
100
5f258eaf9517 Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
246 case Tok.Seperator:
5f258eaf9517 Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
247 done = true;
5f258eaf9517 Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
248 break;
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
249 default:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
250 goto Lerror;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
251 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
252 res ~= action.actOnImport(_import, mod, null);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
253 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
254
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
255 require(Tok.Seperator);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
256 return res.safe();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
257 Lerror:
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
258 while (!isa (Tok.Seperator))
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
259 next();
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
260 return res.safe();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
261 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
262
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
263 /**
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
264 Parse interface
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
265 */
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
266 Decl parseInterface(Id type, Id iden, Attribute att)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
267 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
268 auto decl = action.actOnDeclarator(type, iden, null, att);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
269
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
270 if (peek.type == Tok.Colon)
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
271 // SuperInterfaces
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
272 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
273 next; // Remove colon.
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
274
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
275 Id identifier;
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
276
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
277 // The identifier
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
278 identifier = Id(require(Tok.Identifier));
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
279
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
280 action.actOnInterfaceBaseClass(decl, identifier);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
281
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
282 // We should now have an optional list of items, each starting ','
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
283 while (peek.type == Tok.Comma)
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
284 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
285 next; // Remove comma
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
286
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
287 // The identifier
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
288 identifier = Id(require(Tok.Identifier));
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
289
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
290 action.actOnInterfaceBaseClass(decl, identifier);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
291 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
292 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
293
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
294 require(Tok.OpenBrace);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
295
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
296 auto nes = parseAttributeInit;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
297 while( !isa(Tok.EOF) && !isa(Tok.CloseBrace) )
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
298 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
299 while ( peek.isAttribute )
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
300 nes ~= parseAttribute(nes[$-1]);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
301
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
302 auto m_decl = parseDecl(nes[$-1].a);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
303 action.actOnInterfaceMember(decl, m_decl);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
304
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
305 nes = parseAttributeScope(nes);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
306 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
307
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
308 require(Tok.CloseBrace);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
309
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
310 return decl;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
311 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
312
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
313 /**
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
314 Parse class
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
315 */
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
316 Decl parseClass(Id type, Id iden, Attribute att)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
317 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
318 auto decl = action.actOnDeclarator(type, iden, null, att);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
319
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
320 if (peek.type == Tok.Colon)
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
321 // BaseClassList - Super class and interfaces(in that order)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
322 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
323 next; // Remove colon.
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
324
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
325 Token protection;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
326 Id identifier;
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
327
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
328 // First we expect an optional protection level.
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
329 if (peek.isBaseClassProtection)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
330 protection = next;
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
331 // Then the identifier
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
332 identifier = Id(require(Tok.Identifier));
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
333
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
334 action.actOnClassBaseClass(decl, identifier);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
335
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
336 // We should now have an optional list of items, each starting ','
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
337 while (peek.type == Tok.Comma)
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
338 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
339 next; // Remove comma
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
340
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
341 // First we expect an optional protection level.
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
342 if (peek.isBaseClassProtection)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
343 protection = next;
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
344 // Then the identifier
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
345 identifier = Id(require(Tok.Identifier));
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
346
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
347 action.actOnClassBaseClass(decl, identifier);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
348 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
349 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
350
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
351 require(Tok.OpenBrace);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
352
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
353 auto nes = parseAttributeInit;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
354 while( !isa(Tok.EOF) && !isa(Tok.CloseBrace) )
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
355 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
356 while ( peek.isAttribute )
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
357 nes ~= parseAttribute(nes[$-1]);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
358
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
359 auto m_decl = parseDecl(nes[$-1].a);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
360 action.actOnClassMember(decl, m_decl);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
361
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
362 nes = parseAttributeScope(nes);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
363 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
364
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
365 require(Tok.CloseBrace);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
366
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
367 return decl;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
368 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
369
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
370 /**
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
371 Parse struct
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
372 */
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
373 Decl parseStruct(Id type, Id iden, Attribute att)
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
374 {
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
375 auto decl = action.actOnDeclarator(type, iden, null, att);
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
376
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
377 require(Tok.OpenBrace);
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
378
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
379 auto nes = parseAttributeInit;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
380 while( !isa(Tok.EOF) && !isa(Tok.CloseBrace) )
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
381 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
382 while ( peek.isAttribute )
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
383 nes ~= parseAttribute(nes[$-1]);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
384
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
385 auto m_decl = parseDecl(nes[$-1].a);
102
cd066f3b539a Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
386 action.actOnStructMember(decl, m_decl);
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
387
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
388 nes = parseAttributeScope(nes);
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
389 }
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
390
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
391 require(Tok.CloseBrace);
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
392
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
393 return decl;
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
394 }
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
395
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
396 Att[] parseAttributeInit()
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
397 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
398 Att[] nes;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
399 nes ~= Att();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
400 nes[0].nested = Scope;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
401 return nes;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
402 }
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
403
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
404 Att[] parseAttributeScope(Att[] nes)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
405 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
406 while ( nes[$-1].nested == Single )
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
407 nes.length = nes.length - 1;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
408
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
409 while ( isa(Tok.CloseBrace) && nes.length > 1)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
410 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
411 while ( nes.length > 1 )
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
412 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
413 if( nes[$-1].nested == Scope )
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
414 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
415 nes.length = nes.length - 1;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
416 next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
417 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
418 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
419 nes.length = nes.length - 1;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
420 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
421 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
422
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
423 return nes;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
424 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
425
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
426 Att parseAttribute(Att last)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
427 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
428 Att _parseAttribute(Att last)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
429 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
430 Att a = last;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
431 a.nested = Single;
5
2c5a8f4c254a Added very simple if support.
Anders Halager <halager@gmail.com>
parents: 1
diff changeset
432
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
433 switch(peek.type)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
434 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
435 case Tok.Public:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
436 a.a.setProtection(Protection.Public);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
437 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
438 case Tok.Private:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
439 a.a.setProtection(Protection.Private);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
440 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
441 case Tok.Package:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
442 a.a.setProtection(Protection.Package);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
443 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
444 case Tok.Protected:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
445 a.a.setProtection(Protection.Protected);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
446 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
447 case Tok.Export:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
448 a.a.setProtection(Protection.Export);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
449 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
450 case Tok.Static:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
451 a.a.setStatic;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
452 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
453 case Tok.Final:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
454 a.a.setFinal;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
455 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
456 case Tok.Const:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
457 a.a.setConst;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
458 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
459 case Tok.Abstract:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
460 a.a.setAbstract;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
461 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
462 case Tok.Override:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
463 a.a.setOverride;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
464 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
465 case Tok.Depracted:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
466 a.a.setDepracted;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
467 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
468 case Tok.Auto:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
469 a.a.setAuto;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
470 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
471 case Tok.Extern:
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
472 Extern e = parseLinkageType;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
473 a.a.setExtern(e);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
474 break;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
475 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
476 next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
477
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
478 return a;
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
479 }
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
480
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
481 Att a = _parseAttribute(last);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
482
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
483 while (peek.isAttribute)
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
484 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
485 a = parseAttribute(a);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
486 }
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
487
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
488 if (peek.type == Tok.Colon)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
489 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
490 a.nested = All;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
491 next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
492 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
493 else if (peek.type == Tok.OpenBrace)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
494 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
495 a.nested = Scope;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
496 next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
497 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
498
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
499 return a;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
500 }
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
501
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
502 enum : uint { Single, Scope, All }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
503
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
504 struct Att
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
505 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
506 Attribute a;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
507 uint nested;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
508 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
509
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
510 /**
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
511 Parse statements.
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
512
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
513 This is the place to attack!
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
514 */
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
515 Stmt parseStatement()
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
516 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
517 Token t = peek;
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
518
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
519 if (t.isReturn)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
520 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
521 Token ret = next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
522 Exp exp;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
523 if (peek.type != Tok.Seperator)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
524 exp = parseExpression();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
525 require(Tok.Seperator);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
526 return action.actOnReturnStmt(ret, exp);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
527
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
528 /*
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
529 if (cond)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
530 single statement | compound statement
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
531 [else
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
532 single statement | compound statement]
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
533 */
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
534 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
535 else if (t.isIf)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
536 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
537 Token _if = next();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
538
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
539 require(Tok.OpenParentheses);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
540 Exp cond = parseExpression();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
541 require(Tok.CloseParentheses);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
542
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
543 Stmt thenB = parseSingleOrCompoundStatement();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
544
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
545 // if there is no else part we use the if as token, to have
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
546 // something than can be passed along
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
547 Token _else = _if;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
548 Stmt elseB;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
549 if (peek.type == Tok.Else)
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
550 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
551 _else = next;
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
552 elseB = parseSingleOrCompoundStatement();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
553 }
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
554
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
555 return action.actOnIfStmt(_if, cond, thenB, _else, elseB);
5
2c5a8f4c254a Added very simple if support.
Anders Halager <halager@gmail.com>
parents: 1
diff changeset
556
47
b0a691727a0c Stricter while - the () was optional before
Anders Halager <halager@gmail.com>
parents: 46
diff changeset
557 /*
b0a691727a0c Stricter while - the () was optional before
Anders Halager <halager@gmail.com>
parents: 46
diff changeset
558 while (cond)
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
559 single statement | compound statement
47
b0a691727a0c Stricter while - the () was optional before
Anders Halager <halager@gmail.com>
parents: 46
diff changeset
560 */
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
561 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
562 else if (t.isWhile)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
563 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
564 Token _while = next;
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
565 require(Tok.OpenParentheses);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
566 Exp cond = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
567 require(Tok.CloseParentheses);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
568 Stmt bodyStmt = parseSingleOrCompoundStatement();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
569 return action.actOnWhileStmt(_while, cond, bodyStmt);
5
2c5a8f4c254a Added very simple if support.
Anders Halager <halager@gmail.com>
parents: 1
diff changeset
570
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
571 /*
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
572 One of four things:
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
573 A declaration of a function/variable `type id ...`
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
574 A direct assignment `id = exp;`
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
575 An indirect assignment `id.id = exp`
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
576 Some sort of free standing expression
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
577
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
578 The assignments should be handled as binary expressions?
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
579 */
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
580 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
581 else if (t.isBasicType || t.isIdentifier)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
582 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
583 Token iden = peek;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
584 Token n = peek(1);
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
585 // Must be an decl, if we start with a basic type, or two
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
586 // identifiers in a row
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
587 if ( n.type == Tok.Star || n.type == Tok.OpenBracket)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
588 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
589 int len = peekParseType;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
590 if(peek(len).type == Tok.Identifier && len != 0)
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
591 return action.actOnDeclStmt(parseVarDecl());
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
592
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
593 Exp exp = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
594 require(Tok.Seperator);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
595 return action.actOnExprStmt(exp);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
596 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
597
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
598 if (n.isIdentifier())
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
599 return action.actOnDeclStmt(parseVarDecl());
76
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
600
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
601 // Expression: a.b, a = b, a(b) etc.
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
602 Exp exp = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
603 require(Tok.Seperator);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
604 return action.actOnExprStmt(exp);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
605 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
606 else if(t.isSwitch)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
607 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
608 next;
143
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
609 require(Tok.OpenParentheses);
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
610 auto target = parseExpression();
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
611 auto res = action.actOnStartOfSwitchStmt(target);
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
612 require(Tok.CloseParentheses);
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
613 require(Tok.OpenBrace);
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
614 while (true)
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
615 {
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
616 Stmt[] statements;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
617 if (skip(Tok.Default))
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
618 {
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
619 require(Tok.Colon);
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
620 statements.length = 0;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
621 while (peek.type != Tok.Case
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
622 && peek.type != Tok.Default
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
623 && peek.type != Tok.CloseBrace)
143
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
624 statements ~= parseStatement();
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
625 action.actOnDefaultStmt(res, statements);
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
626 continue;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
627 }
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
628
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
629 Token _case = peek;
143
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
630 if (_case.type != Tok.Case)
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
631 break;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
632 next();
143
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
633
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
634 Exp[] literals;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
635 do
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
636 {
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
637 Exp e = parseExpression();
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
638 // IntegerLit lit = cast(IntegerLit)e;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
639 // if (lit is null)
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
640 // messages.report(CaseValueMustBeInt, peek.location).arg(next.getType);
143
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
641 // else
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
642 literals ~= e;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
643 }
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
644 while (skip(Tok.Comma));
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
645 require(Tok.Colon);
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
646
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
647 while (peek.type != Tok.Case
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
648 && peek.type != Tok.Default
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
649 && peek.type != Tok.CloseBrace)
143
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
650 statements ~= parseStatement();
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
651
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
652 action.actOnCaseStmt(res, literals, statements);
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
653
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
654 if (peek.type == Tok.CloseBrace)
143
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
655 break;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
656 }
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
657 require(Tok.CloseBrace);
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
658 return res;
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
659 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
660 else
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
661 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
662 if (t.type == Tok.Star)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
663 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
664 auto exp = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
665 require(Tok.Seperator);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
666 return action.actOnExprStmt(exp);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
667 }
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
668 messages.report(UnexpectedBeginStmt, peek.location).arg(next.getType);
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
669 return null;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
670 }
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
671 messages.report(UnexpectedTok, t.location);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
672 return null;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
673 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
674
76
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
675 Decl parseVarDecl()
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
676 {
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
677 // manually hardcoded to only support "type id [= exp];"
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
678 // as that is the only thing the codegen understands
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
679 Id type = parseType;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
680 Id id = Id(next);
76
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
681 Exp init;
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
682 if (skip(Tok.Assign))
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
683 init = parseExpression();
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
684 require(Tok.Seperator);
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
685 Attribute att;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
686 Decl d = action.actOnDeclarator(type, id, init, att);
76
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
687 return d;
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
688 }
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
689
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
690 /**
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
691 Parses a function/method given the already parsed return type and name
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
692 */
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
693 Decl parseFunc(ref Id type, ref Id name, Attribute att)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
694 {
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
695 Decl func = action.actOnStartOfFunctionDef(type, name, att);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
696 parseFuncArgs(func);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
697
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
698 if(peek.type == Tok.Seperator)
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
699 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
700 next;
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
701 return func;
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
702 }
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
703 Stmt stmt = parseCompoundStatement();
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
704
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
705 return action.actOnEndOfFunction(func, stmt);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
706 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
707
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
708 /**
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
709 Parse the function arguments, assumes current token is (.
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
710
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
711 Both the intitial paren and the ending paren is consumed.
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
712 */
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
713 void parseFuncArgs(Decl func)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
714 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
715 require(Tok.OpenParentheses); // Remove the "(" token.
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
716
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
717 while(peek.type != Tok.CloseParentheses)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
718 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
719 auto t = parseType();
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
720 Id i;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
721 if(peek.type == Tok.Identifier)
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
722 i = parseIdentifier();
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
723 action.addFuncArg(func, t, i);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
724
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
725 if(peek.type == Tok.Comma)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
726 next;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
727 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
728
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
729 require(Tok.CloseParentheses); // Remove the ")"
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
730 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
731
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
732 /**
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
733 Parse either a block, or a single statement as allowed after if, while
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
734 and for.
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
735 */
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
736 Stmt parseSingleOrCompoundStatement()
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
737 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
738 if (peek.type == Tok.OpenBrace)
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
739 return parseCompoundStatement();
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
740 return parseStatement();
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
741 }
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
742
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
743 /**
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
744 Parses a function-body or similar, expects an opening brace to be the
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
745 current token.
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
746
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
747 Will consume both the starting { and ending }
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
748 */
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
749 Stmt parseCompoundStatement()
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
750 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
751 Token lbrace = require(Tok.OpenBrace);
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
752 SmallArray!(Stmt, 32) stmts; // Try to use the stack only
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
753 while (peek.type != Tok.CloseBrace)
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
754 stmts ~= parseStatement();
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
755 Token rbrace = require(Tok.CloseBrace);
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
756 return action.actOnCompoundStmt(lbrace, rbrace, stmts.unsafe());
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
757 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
758
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
759 Id parseIdentifier()
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
760 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
761 Token tok = next;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
762
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
763 if (tok.type is Tok.Identifier)
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
764 return Id(tok);
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
765
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
766 messages.report(UnexpectedTokSingle, tok.location)
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
767 .arg(tok.getType)
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
768 .arg(Tok.Identifier);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
769 }
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
770
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
771 ModuleName parseModuleName()
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
772 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
773 auto id = parseIdentifier();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
774 ModuleName mod;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
775 while (skip(Tok.Dot))
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
776 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
777 mod.packages ~= id;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
778 if (peek.type != Tok.Identifier) {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
779 messages.report(ExpectedIdAfterPackage, peek.location);
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
780 goto Lerror;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
781 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
782 id = parseIdentifier();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
783 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
784 mod.id = id;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
785 return mod;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
786 Lerror:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
787 while (!skip(Tok.Seperator))
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
788 next();
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
789 return mod;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
790 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
791
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
792
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
793 /**
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
794 Parse a type - this includes pointer and array(at some point) types.
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
795 */
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
796 Id parseType()
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
797 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
798 Token type = next;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
799
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
800 Id currentType;
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
801
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
802 if ( !(type.isBasicType || type.type == Tok.Identifier) )
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
803 messages.report(InvalidType, type.location);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
804
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
805 currentType = Id(type);
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
806 type = peek;
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
807
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
808 while(type.type == Tok.Star || type.type == Tok.OpenBracket)
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
809 {
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
810 if(type.type == Tok.Star)
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
811 {
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
812 currentType = PointerId(currentType);
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
813 next;
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
814 }
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
815 else
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
816 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
817 next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
818 if(peek.type == Tok.Integer)
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
819 currentType = StaticArrayId(
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
820 currentType,
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
821 action.actOnNumericConstant(
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
822 require(Tok.Integer)));
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
823 require(Tok.CloseBracket);
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
824
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
825 }
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
826 type = peek;
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
827 }
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
828
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
829 return currentType;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
830 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
831
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
832 int peekParseType()
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
833 {
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
834 int i;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
835 Token type = peek(i);
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
836
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
837 Id currentType;
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
838
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
839 if ( !(type.isBasicType || type.type == Tok.Identifier) )
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
840 return 0;
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
841
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
842 currentType = Id(type);
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
843 type = peek(++i);
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
844
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
845 while(type.type == Tok.Star || type.type == Tok.OpenBracket)
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
846 {
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
847 if(type.type == Tok.Star)
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
848 {
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
849 i++;
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
850 }
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
851 else
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
852 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
853 if(peek(i++).type != Tok.OpenBracket)
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
854 return 0;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
855 if(peek(i).type == Tok.Integer)
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
856 {
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
857 i++;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
858 if(peek(i++).type != Tok.CloseBracket)
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
859 return 0;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
860 }
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
861 else
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
862 if(peek(i++).type != Tok.CloseBracket)
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
863 return 0;
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
864
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
865 }
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
866 type = peek(i);
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
867 }
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
868
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
869 return i;
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
870 }
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
871
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
872 private:
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
873 // -- Expression parsing -- //
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
874 Exp parsePostfixExp(Exp target)
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
875 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
876 switch(peek.type)
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
877 {
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
878 case Tok.Dot:
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
879 switch(peek(1).type)
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
880 {
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
881 case Tok.Identifier:
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
882 Token op = next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
883 Id member = Id(next);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
884 Exp exp = action.actOnMemberReference(target, op.location, member);
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
885 return parsePostfixExp(exp);
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
886 default:
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
887 Token t = peek(1);
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
888 messages.report(ExpectedIdAfterDot, t.location);
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
889 }
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
890 case Tok.OpenBracket:
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
891 Token open = next;
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
892 Exp index = parseExpression();
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
893 Token close = require(Tok.CloseBracket);
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
894 return action.actOnIndexEpr(target, open, index, close);
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
895 default:
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
896 return target;
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
897 }
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
898 }
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
899
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
900 Exp parseExpression(int p = 0)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
901 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
902 auto exp = P();
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
903 Token n = peek();
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
904 BinOp* op = null;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
905 while ((op = binary(n.type)) != null && op.prec >= p)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
906 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
907 next();
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
908 int q = op.leftAssoc? 1 + op.prec : op.prec;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
909 auto exp2 = parseExpression(q);
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
910 exp = action.actOnBinaryOp(n.location, op.operator, exp, exp2);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
911 n = peek();
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
912 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
913
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
914 return exp;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
915 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
916
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
917 Exp P()
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
918 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
919 Token n = next();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
920 if (auto op = unary(n.type))
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
921 return action.actOnUnaryOp(n, parseExpression(op.prec));
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
922 else if (n.type == Tok.OpenParentheses)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
923 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
924 auto e = parseExpression(0);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
925 require(Tok.CloseParentheses);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
926 return e;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
927 }
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
928 else if (n.type == Tok.Identifier)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
929 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
930 Exp value = action.actOnIdentifierExp(Id(n));
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
931 Exp iden = parsePostfixExp(value);
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
932 switch(peek.type)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
933 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
934 case Tok.OpenParentheses:
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
935 Token lp = next;
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
936 SmallArray!(Exp, 8) args;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
937 while(peek.type != Tok.CloseParentheses)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
938 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
939 if(peek.type == Tok.Comma)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
940 next;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
941 args ~= parseExpression();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
942 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
943
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
944 Token rp = next();
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
945 return action.actOnCallExpr(iden, lp, args.unsafe(), rp);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
946
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
947 default:
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
948 return iden;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
949 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
950 }
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
951 else if (n.type == Tok.Cast)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
952 return parseCast(n);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
953 else if (n.type == Tok.Integer)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
954 return action.actOnNumericConstant(n);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
955 else if (n.type == Tok.String)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
956 return action.actOnStringExp(n);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
957
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
958 messages.report(ExpectedExp, n.location)
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
959 .fatal(ExitLevel.Parser);
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
960 return null;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
961 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
962
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
963 Exp parseCast(ref Token _cast)
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
964 {
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
965 require(Tok.OpenParentheses);
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
966 auto n = next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
967 if(!n.isBasicType && !n.isIdentifier)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
968 messages.report(ExpectedCastType, n.location);
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
969
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
970 require(Tok.CloseParentheses);
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
971 auto exp = P();
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
972 return action.actOnCastExpr(_cast, Id(n), exp);
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
973 }
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
974
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
975 struct UnOp
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
976 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
977 Tok tokenType;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
978 int prec;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
979 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
980
78
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
981 static const UnOp[] _unary =
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
982 [
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
983 {Tok.Minus, 4},
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
984 {Tok.Star, 4}
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
985 ];
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
986 UnOp* unary(Tok t)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
987 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
988 foreach (ref op; _unary)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
989 if (op.tokenType == t)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
990 return &op;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
991 return null;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
992 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
993
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
994 struct BinOp
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
995 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
996 Tok tokenType;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
997 int prec;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
998 bool leftAssoc;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
999 Operator operator;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1000 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1001
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
1002 static const BinOp[] _binary =
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1003 [
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
1004 {Tok.Assign, 1, false, Operator.Assign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
1005 {Tok.PlusAssign, 1, false, Operator.AddAssign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
1006 {Tok.MinusAssign, 1, false, Operator.SubAssign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
1007 {Tok.StarAssign, 1, false, Operator.MulAssign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
1008 {Tok.SlashAssign, 1, false, Operator.DivAssign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
1009 {Tok.PercentAssign, 1, false, Operator.ModAssign},
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
1010
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1011 // =, += etc. 1
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1012 // (need special-case for the ternary operator at this level)
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1013 // ||, 2
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1014 // &&, 3
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1015 // |, 4
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1016 // &, 5
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1017 // ^, 6
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1018 // ==, !=, is, !is, 7
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1019 // <, <= etc, 7
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1020 // in, 7
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1021 // <<, >>, >>>, 8
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1022 // +, -, ~, 9
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1023 // *, /, %, 10
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1024 // unary operators here
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
1025
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
1026 {Tok.Eq, 2, true, Operator.Eq},
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
1027 {Tok.Ne, 2, true, Operator.Ne},
10
2f493057cf17 Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents: 7
diff changeset
1028
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
1029 {Tok.Lt, 2, true, Operator.Lt},
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
1030 {Tok.Le, 2, true, Operator.Le},
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
1031 {Tok.Gt, 2, true, Operator.Gt},
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
1032 {Tok.Ge, 2, true, Operator.Ge},
10
2f493057cf17 Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents: 7
diff changeset
1033
74
192da4976daa Renamed Add, Sub, Mul, Div and Mod in lexer to what they are (Plus, Minus....)
johnsen@johnsen-laptop
parents: 71
diff changeset
1034 {Tok.Plus, 3, true, Operator.Add},
192da4976daa Renamed Add, Sub, Mul, Div and Mod in lexer to what they are (Plus, Minus....)
johnsen@johnsen-laptop
parents: 71
diff changeset
1035 {Tok.Minus, 3, true, Operator.Sub},
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
1036
74
192da4976daa Renamed Add, Sub, Mul, Div and Mod in lexer to what they are (Plus, Minus....)
johnsen@johnsen-laptop
parents: 71
diff changeset
1037 {Tok.Star, 5, true, Operator.Mul},
192da4976daa Renamed Add, Sub, Mul, Div and Mod in lexer to what they are (Plus, Minus....)
johnsen@johnsen-laptop
parents: 71
diff changeset
1038 {Tok.Slash, 5, true, Operator.Div},
123
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
1039 {Tok.Percent, 5, true, Operator.Mod},
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
1040
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
1041 {Tok.LeftShift, 8, true, Operator.LeftShift},
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
1042 {Tok.RightShift, 8, true, Operator.RightShift},
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
1043 {Tok.UnsignedRightShift, 8, true, Operator.UnsignedRightShift}
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1044 ];
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1045 BinOp* binary(Tok t)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1046 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1047 foreach (ref op; _binary)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1048 if (op.tokenType == t)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1049 return &op;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1050 return null;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1051 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1052
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1053 private:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1054
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
1055 Token require(Tok t)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1056 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1057 if (peek().type != t)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1058 messages.report(UnexpectedTokSingle, peek.location)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1059 .arg(peek.getType)
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
1060 .arg(t);
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1061 return next();
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
1062 }
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
1063
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
1064 bool skip(Tok t)
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
1065 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1066 if (peek().type != t)
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
1067 return false;
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1068 next();
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
1069 return true;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1070 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1071
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1072 bool isa(Tok t)
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
1073 {
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1074 return peek.type == t;
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
1075 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
1076
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1077 Token next()
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1078 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1079 return lexer.next;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1080 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1081
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1082 Token peek(int i = 0)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1083 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1084 return lexer.peek(i);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1085 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1086
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
1087 Lexer lexer;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
1088 SourceManager sm;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1089 }
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
1090