...
This commit is contained in:
@@ -62,7 +62,7 @@ public sealed class Parser
|
||||
_ => throw new CompileException(Diagnostic
|
||||
.Error($"Expected 'func', 'struct', 'enum', 'import' or 'module' but found '{keyword.Symbol}'")
|
||||
.WithHelp("Valid top level statements are 'func', 'struct', 'enum', 'import' and 'module'")
|
||||
.At(keyword)
|
||||
.At(keyword, _tokens)
|
||||
.Build())
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ public sealed class Parser
|
||||
}
|
||||
}
|
||||
|
||||
return new SyntaxTree(topLevelSyntaxNodes);
|
||||
return new SyntaxTree(topLevelSyntaxNodes, _tokens);
|
||||
}
|
||||
|
||||
private ModuleSyntax ParseModule(int startIndex)
|
||||
@@ -190,7 +190,7 @@ public sealed class Parser
|
||||
{
|
||||
throw new CompileException(Diagnostic
|
||||
.Error("Value of enum field must be an integer literal")
|
||||
.At(CurrentToken)
|
||||
.At(CurrentToken, _tokens)
|
||||
.Build());
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ public sealed class Parser
|
||||
IdentifierToken identifier => ParseIdentifier(startIndex, identifier),
|
||||
SymbolToken symbolToken => symbolToken.Symbol switch
|
||||
{
|
||||
Symbol.Ampersand => ParseAddressOf(startIndex),
|
||||
Symbol.Caret => ParseAddressOf(startIndex),
|
||||
Symbol.OpenParen => ParseParenthesizedExpression(),
|
||||
Symbol.Minus => ParseUnaryNegate(startIndex),
|
||||
Symbol.Bang => ParseUnaryInvert(startIndex),
|
||||
@@ -472,13 +472,13 @@ public sealed class Parser
|
||||
_ => throw new CompileException(Diagnostic
|
||||
.Error($"Unexpected symbol '{symbolToken.Symbol}' in expression")
|
||||
.WithHelp("Expected '(', '-', '!', '[' or '{'")
|
||||
.At(symbolToken)
|
||||
.At(symbolToken, _tokens)
|
||||
.Build())
|
||||
},
|
||||
_ => throw new CompileException(Diagnostic
|
||||
.Error($"Unexpected token '{token.GetType().Name}' in expression")
|
||||
.WithHelp("Expected literal, identifier, or parenthesized expression")
|
||||
.At(token)
|
||||
.At(token, _tokens)
|
||||
.Build())
|
||||
};
|
||||
|
||||
@@ -698,7 +698,7 @@ public sealed class Parser
|
||||
throw new CompileException(Diagnostic
|
||||
.Error("Arbitrary uint size is not supported")
|
||||
.WithHelp("Use u8, u16, u32 or u64")
|
||||
.At(name)
|
||||
.At(name, _tokens)
|
||||
.Build());
|
||||
}
|
||||
|
||||
@@ -712,7 +712,7 @@ public sealed class Parser
|
||||
throw new CompileException(Diagnostic
|
||||
.Error("Arbitrary int size is not supported")
|
||||
.WithHelp("Use i8, i16, i32 or i64")
|
||||
.At(name)
|
||||
.At(name, _tokens)
|
||||
.Build());
|
||||
}
|
||||
|
||||
@@ -726,7 +726,7 @@ public sealed class Parser
|
||||
throw new CompileException(Diagnostic
|
||||
.Error("Arbitrary float size is not supported")
|
||||
.WithHelp("Use f32 or f64")
|
||||
.At(name)
|
||||
.At(name, _tokens)
|
||||
.Build());
|
||||
}
|
||||
|
||||
@@ -810,7 +810,7 @@ public sealed class Parser
|
||||
throw new CompileException(Diagnostic
|
||||
.Error("Invalid type syntax")
|
||||
.WithHelp("Expected type name, '^' for pointer, or '[]' for array")
|
||||
.At(CurrentToken)
|
||||
.At(CurrentToken, _tokens)
|
||||
.Build());
|
||||
}
|
||||
|
||||
@@ -821,7 +821,7 @@ public sealed class Parser
|
||||
throw new CompileException(Diagnostic
|
||||
.Error("Unexpected end of file")
|
||||
.WithHelp("Expected more tokens to complete the syntax")
|
||||
.At(_tokens[^1])
|
||||
.At(_tokens[^1], _tokens)
|
||||
.Build());
|
||||
}
|
||||
|
||||
@@ -838,7 +838,7 @@ public sealed class Parser
|
||||
throw new CompileException(Diagnostic
|
||||
.Error($"Expected symbol, but found {token.GetType().Name}")
|
||||
.WithHelp("This position requires a symbol like '(', ')', '{', '}', etc.")
|
||||
.At(token)
|
||||
.At(token, _tokens)
|
||||
.Build());
|
||||
}
|
||||
|
||||
@@ -853,7 +853,7 @@ public sealed class Parser
|
||||
throw new CompileException(Diagnostic
|
||||
.Error($"Expected '{expectedSymbol}', but found '{token.Symbol}'")
|
||||
.WithHelp($"Insert '{expectedSymbol}' here")
|
||||
.At(token)
|
||||
.At(token, _tokens)
|
||||
.Build());
|
||||
}
|
||||
}
|
||||
@@ -903,7 +903,7 @@ public sealed class Parser
|
||||
throw new CompileException(Diagnostic
|
||||
.Error($"Expected identifier, but found {token.GetType().Name}")
|
||||
.WithHelp("Provide a valid identifier name here")
|
||||
.At(token)
|
||||
.At(token, _tokens)
|
||||
.Build());
|
||||
}
|
||||
|
||||
@@ -931,7 +931,7 @@ public sealed class Parser
|
||||
throw new CompileException(Diagnostic
|
||||
.Error($"Expected string literal, but found {token.GetType().Name}")
|
||||
.WithHelp("Provide a valid string literal")
|
||||
.At(token)
|
||||
.At(token, _tokens)
|
||||
.Build());
|
||||
}
|
||||
|
||||
@@ -953,4 +953,4 @@ public sealed class Parser
|
||||
}
|
||||
}
|
||||
|
||||
public record SyntaxTree(List<TopLevelSyntaxNode> TopLevelSyntaxNodes);
|
||||
public record SyntaxTree(List<TopLevelSyntaxNode> TopLevelSyntaxNodes, List<Token> Tokens);
|
||||
Reference in New Issue
Block a user