global variables
This commit is contained in:
@@ -121,6 +121,21 @@ public sealed class Parser(string fileName, List<Token> tokens)
|
||||
return new NodeDefinitionStruct(TokensFrom(startIndex), exported, packed, name, fields);
|
||||
}
|
||||
|
||||
if (TryExpectKeyword(Keyword.Let))
|
||||
{
|
||||
var exported = modifiers.Remove(Keyword.Export);
|
||||
|
||||
foreach (var modifier in modifiers)
|
||||
// todo(nub31): Add to diagnostics instead of throwing
|
||||
throw new CompileException(Diagnostic.Error("Invalid modifier for global variable").At(fileName, modifier.Value).Build());
|
||||
|
||||
var name = ExpectIdent();
|
||||
ExpectSymbol(Symbol.Colon);
|
||||
var type = ParseType();
|
||||
|
||||
return new NodeDefinitionGlobalVariable(TokensFrom(startIndex), exported, name, type);
|
||||
}
|
||||
|
||||
throw new CompileException(Diagnostic.Error("Not a valid definition").At(fileName, Peek()).Build());
|
||||
}
|
||||
|
||||
@@ -622,6 +637,13 @@ public sealed class NodeDefinitionStruct(List<Token> tokens, bool exported, bool
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NodeDefinitionGlobalVariable(List<Token> tokens, bool exported, TokenIdent name, NodeType type) : NodeDefinition(tokens)
|
||||
{
|
||||
public bool Exported { get; } = exported;
|
||||
public TokenIdent Name { get; } = name;
|
||||
public NodeType Type { get; } = type;
|
||||
}
|
||||
|
||||
public abstract class NodeStatement(List<Token> tokens) : Node(tokens);
|
||||
|
||||
public sealed class NodeStatementBlock(List<Token> tokens, List<NodeStatement> statements) : NodeStatement(tokens)
|
||||
|
||||
Reference in New Issue
Block a user