Compare commits
No commits in common. "ac5d29819c238eefc45d8b43cd40eda6ad5ae4de" and "b436ad831aa1a94f0bda9d6315dd6136d00e2b0b" have entirely different histories.
ac5d29819c
...
b436ad831a
6 changed files with 5 additions and 87 deletions
|
@ -54,16 +54,3 @@ fn main(a int) int {
|
|||
}
|
||||
|
||||
fn (v Typ) voidfunc() {}
|
||||
|
||||
struct Foo {
|
||||
a int
|
||||
mut:
|
||||
b int
|
||||
c int
|
||||
pub:
|
||||
d int
|
||||
pub mut:
|
||||
e int
|
||||
pub mut mut:
|
||||
f int
|
||||
}
|
||||
|
|
|
@ -227,10 +227,8 @@ pub const FieldList = std.ArrayList(StructField);
|
|||
pub const StructField = struct {
|
||||
name: Token,
|
||||
typ: Token,
|
||||
|
||||
mutable: bool = false,
|
||||
public: bool = false,
|
||||
mutable_outside: bool = false,
|
||||
mutable: bool = true,
|
||||
public: bool = true,
|
||||
};
|
||||
|
||||
pub const Struct = struct {
|
||||
|
|
|
@ -107,10 +107,6 @@ pub fn printNode(node: *Node, ident: usize) void {
|
|||
std.debug.warn("pub ");
|
||||
}
|
||||
|
||||
if (field.mutable_outside) {
|
||||
std.debug.warn("MUT_OUT ");
|
||||
}
|
||||
|
||||
std.debug.warn("{} {})\n", field.name.lexeme, field.typ.lexeme);
|
||||
}
|
||||
print(ident, "))\n");
|
||||
|
|
|
@ -18,12 +18,6 @@ const Stmt = ast.Stmt;
|
|||
|
||||
const TokenList = std.ArrayList(Token);
|
||||
|
||||
const FieldState = struct {
|
||||
public: bool = false,
|
||||
mutable: bool = false,
|
||||
mutable_outside: bool = false,
|
||||
};
|
||||
|
||||
pub const Parser = struct {
|
||||
allocator: *Allocator,
|
||||
scanner: *Scanner,
|
||||
|
@ -411,6 +405,8 @@ pub const Parser = struct {
|
|||
|
||||
while (self.peek().ttype != .RightParen) {
|
||||
const param_name = try self.consumeSingle(.Identifier);
|
||||
|
||||
// TODO dedicated function to consume a type?
|
||||
const param_type = try self.consumeSingle(.Identifier);
|
||||
|
||||
try param_list.append(ast.ParamDecl{
|
||||
|
@ -499,25 +495,14 @@ pub const Parser = struct {
|
|||
|
||||
_ = try self.consumeSingle(.LeftBrace);
|
||||
|
||||
var field_state = FieldState{};
|
||||
|
||||
while (!self.check(.RightBrace)) {
|
||||
try self.parseFieldModifiers(&field_state);
|
||||
|
||||
// TODO mut and pub
|
||||
const field_name = try self.consumeSingle(.Identifier);
|
||||
const field_type = try self.consumeSingle(.Identifier);
|
||||
|
||||
// we could create a FieldState on the heap and copy our current
|
||||
// field state into a StructField.state, but copying via this makes
|
||||
// things so much nicer.
|
||||
|
||||
try fields.append(ast.StructField{
|
||||
.name = field_name,
|
||||
.typ = field_type,
|
||||
|
||||
.mutable = field_state.mutable,
|
||||
.public = field_state.public,
|
||||
.mutable_outside = field_state.mutable_outside,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -526,51 +511,6 @@ pub const Parser = struct {
|
|||
return Node.mkStructDecl(self.allocator, name, fields);
|
||||
}
|
||||
|
||||
fn parseFieldModifiers(self: *@This(), field_state: *FieldState) !void {
|
||||
|
||||
// there are five access modifiers:
|
||||
// - none (private immutable)
|
||||
// - mut (private mutable)
|
||||
// - pub (public immutable)
|
||||
// - pub mut (public mutable only in module)
|
||||
// - pub mut mut (public mutable everywhere)
|
||||
|
||||
// this function takes care of that by changing the current FieldState
|
||||
// to what the modifiers dictate.
|
||||
switch (self.peek().ttype) {
|
||||
.Mut => {
|
||||
// There are no oher modifiers that start with mut, so we
|
||||
// can just go the way of marking it as mutable
|
||||
_ = try self.consumeSingle(.Mut);
|
||||
_ = try self.consumeSingle(.Colon);
|
||||
|
||||
field_state.mutable = true;
|
||||
},
|
||||
|
||||
// 'pub', 'pub mut', and 'pub mut mut' are all handled here
|
||||
.Pub => {
|
||||
_ = try self.consumeSingle(.Pub);
|
||||
field_state.public = true;
|
||||
|
||||
if (self.check(.Mut)) {
|
||||
_ = try self.consumeSingle(.Mut);
|
||||
|
||||
field_state.mutable = true;
|
||||
if (self.check(.Mut)) {
|
||||
_ = try self.consumeSingle(.Mut);
|
||||
field_state.mutable_outside = true;
|
||||
}
|
||||
}
|
||||
|
||||
_ = try self.consumeSingle(.Colon);
|
||||
},
|
||||
|
||||
// if it isn't mut or pub we're likely in an identifier, just
|
||||
// ignore it.
|
||||
else => return,
|
||||
}
|
||||
}
|
||||
|
||||
fn parseTopDecl(self: *@This()) !*Node {
|
||||
return switch (self.peek().ttype) {
|
||||
.Fn => try self.parseFnDecl(),
|
||||
|
|
|
@ -51,7 +51,6 @@ const keywords = [_][]const u8{
|
|||
"None",
|
||||
"println",
|
||||
"loop",
|
||||
"pub",
|
||||
};
|
||||
|
||||
const keyword_ttypes = [_]TokenType{
|
||||
|
@ -81,7 +80,6 @@ const keyword_ttypes = [_]TokenType{
|
|||
.None,
|
||||
.Println,
|
||||
.Loop,
|
||||
.Pub,
|
||||
};
|
||||
|
||||
fn getKeyword(keyword: []const u8) ?TokenType {
|
||||
|
|
|
@ -75,7 +75,6 @@ pub const TokenType = enum {
|
|||
None,
|
||||
|
||||
Println,
|
||||
Pub,
|
||||
|
||||
EOF,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue