Minor fixes to operator system and updated compiler error messages
This commit is contained in:
parent
318f09541a
commit
9ef80535f3
|
@ -838,7 +838,7 @@ proc matchImpl(self: Compiler, name: string, kind: Type): Name =
|
|||
elif impl.len() > 1:
|
||||
var msg = &"multiple matching implementations of '{name}' found:\n"
|
||||
for fn in reversed(impl):
|
||||
msg &= &"- '{fn.name.token.lexeme}' at line {fn.line} of type {self.typeToStr(fn.valueType)}\n"
|
||||
msg &= &"- '{fn.name.token.lexeme}' in '{fn.owner}' at line {fn.line} of type {self.typeToStr(fn.valueType)}\n"
|
||||
self.error(msg)
|
||||
return impl[0]
|
||||
|
||||
|
|
|
@ -530,7 +530,7 @@ proc parseBackticks(self: Lexer) =
|
|||
## parser complaining about syntax
|
||||
## errors
|
||||
while not self.match("`") and not self.done():
|
||||
if self.peek().isAlphaNumeric() or self.symbols.existsSymbol(self.peek()):
|
||||
if self.peek().isAlphaNumeric() or self.symbols.existsSymbol(self.peek()) or self.peek() in ["&", "|"]:
|
||||
discard self.step()
|
||||
continue
|
||||
self.error(&"unexpected character: '{self.peek()}'")
|
||||
|
|
|
@ -121,6 +121,10 @@ proc addOperator(self: OperatorTable, lexeme: string) =
|
|||
var prec = Power
|
||||
if lexeme.len() >= 2 and lexeme[^2..^1] in ["->", "~>", "=>"]:
|
||||
prec = Arrow
|
||||
elif lexeme in ["and", "&"]:
|
||||
prec = Precedence.And
|
||||
elif lexeme in ["or", "|"]:
|
||||
prec = Precedence.Or
|
||||
elif lexeme.endsWith("=") and lexeme[0] notin {'<', '>', '!', '?', '~', '='} or lexeme == "=":
|
||||
prec = Assign
|
||||
elif lexeme[0] in {'$', } or lexeme == "**":
|
||||
|
@ -131,10 +135,6 @@ proc addOperator(self: OperatorTable, lexeme: string) =
|
|||
prec = Addition
|
||||
elif lexeme[0] in {'<', '>', '=', '!'}:
|
||||
prec = Compare
|
||||
elif lexeme == "and":
|
||||
prec = Precedence.And
|
||||
elif lexeme == "or":
|
||||
prec = Precedence.Or
|
||||
self.tokens.add(lexeme)
|
||||
self.precedence[prec].add(lexeme)
|
||||
|
||||
|
@ -144,6 +144,7 @@ proc getPrecedence(self: OperatorTable, lexeme: string): Precedence =
|
|||
for (prec, operators) in self.precedence.pairs():
|
||||
if lexeme in operators:
|
||||
return prec
|
||||
return Precedence.None
|
||||
|
||||
|
||||
proc newParser*: Parser =
|
||||
|
@ -401,7 +402,6 @@ proc makeCall(self: Parser, callee: Expression): CallExpr =
|
|||
argument = self.expression()
|
||||
if argument.kind == binaryExpr and BinaryExpr(argument).operator.lexeme == "=":
|
||||
# TODO: This will explode with slices!
|
||||
echo argument
|
||||
if IdentExpr(BinaryExpr(argument).a) in argNames:
|
||||
self.error("duplicate keyword argument in call")
|
||||
argNames.add(IdentExpr(BinaryExpr(argument).a))
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import std;
|
||||
|
||||
operator `+`(a, b: int): int {
|
||||
#pragma[magic: "AddInt64", pure]
|
||||
}
|
||||
|
@ -8,7 +10,7 @@ operator `+`(a, b: int32): int32 {
|
|||
}
|
||||
|
||||
|
||||
fn sum[T](a, b: T): T {
|
||||
fn sum[T: int | int32](a, b: T): T {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
|
|
10
tests/std.pn
10
tests/std.pn
|
@ -535,6 +535,16 @@ operator `or`*(a, b: bool): bool {
|
|||
}
|
||||
|
||||
|
||||
operator `&`*(a, b: bool): bool {
|
||||
#pragma[magic: "LogicalAnd", pure]
|
||||
}
|
||||
|
||||
|
||||
operator `|`*(a, b: bool): bool {
|
||||
#pragma[magic: "LogicalOr", pure]
|
||||
}
|
||||
|
||||
|
||||
# Assignment operators
|
||||
|
||||
operator `=`*[T: Any](a: var T, b: T) {
|
||||
|
|
Loading…
Reference in New Issue