Merge pull request #2491 from ReneSac/strongSpacesFix
Apply strongSpaces to keyword operators too. Fix #1894.
This commit is contained in:
commit
a2d3dff690
2 changed files with 25 additions and 7 deletions
|
|
@ -215,24 +215,25 @@ proc getPrecedence(tok: TToken, strongSpaces: bool): int =
|
||||||
if L > 1 and tok.ident.s[L-1] == '>': return considerStrongSpaces(1)
|
if L > 1 and tok.ident.s[L-1] == '>': return considerStrongSpaces(1)
|
||||||
|
|
||||||
template considerAsgn(value: expr) =
|
template considerAsgn(value: expr) =
|
||||||
result = if tok.ident.s[L-1] == '=': 1 else: considerStrongSpaces(value)
|
result = if tok.ident.s[L-1] == '=': 1 else: value
|
||||||
|
|
||||||
case relevantChar
|
case relevantChar
|
||||||
of '$', '^': considerAsgn(10)
|
of '$', '^': considerAsgn(10)
|
||||||
of '*', '%', '/', '\\': considerAsgn(9)
|
of '*', '%', '/', '\\': considerAsgn(9)
|
||||||
of '~': result = considerStrongSpaces(8)
|
of '~': result = 8
|
||||||
of '+', '-', '|': considerAsgn(8)
|
of '+', '-', '|': considerAsgn(8)
|
||||||
of '&': considerAsgn(7)
|
of '&': considerAsgn(7)
|
||||||
of '=', '<', '>', '!': result = considerStrongSpaces(5)
|
of '=', '<', '>', '!': result = 5
|
||||||
of '.': considerAsgn(6)
|
of '.': considerAsgn(6)
|
||||||
of '?': result = considerStrongSpaces(2)
|
of '?': result = 2
|
||||||
else: considerAsgn(2)
|
else: considerAsgn(2)
|
||||||
of tkDiv, tkMod, tkShl, tkShr: result = 9
|
of tkDiv, tkMod, tkShl, tkShr: result = 9
|
||||||
of tkIn, tkNotin, tkIs, tkIsnot, tkNot, tkOf, tkAs: result = 5
|
of tkIn, tkNotin, tkIs, tkIsnot, tkNot, tkOf, tkAs: result = 5
|
||||||
of tkDotDot: result = considerStrongSpaces(6)
|
of tkDotDot: result = 6
|
||||||
of tkAnd: result = 4
|
of tkAnd: result = 4
|
||||||
of tkOr, tkXor, tkPtr, tkRef: result = 3
|
of tkOr, tkXor, tkPtr, tkRef: result = 3
|
||||||
else: result = -10
|
else: return -10
|
||||||
|
result = considerStrongSpaces(result)
|
||||||
|
|
||||||
proc isOperator(tok: TToken): bool =
|
proc isOperator(tok: TToken): bool =
|
||||||
## Determines if the given token is an operator type token.
|
## Determines if the given token is an operator type token.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
discard """
|
discard """
|
||||||
output: '''35
|
output: '''35
|
||||||
|
true
|
||||||
|
true
|
||||||
|
4
|
||||||
|
true
|
||||||
|
1
|
||||||
|
false
|
||||||
77
|
77
|
||||||
(Field0: 1, Field1: 2, Field2: 2)
|
(Field0: 1, Field1: 2, Field2: 2)
|
||||||
ha
|
ha
|
||||||
|
|
@ -14,6 +20,17 @@ all args
|
||||||
|
|
||||||
echo 2+5 * 5
|
echo 2+5 * 5
|
||||||
|
|
||||||
|
# Keyword operators
|
||||||
|
echo 1 + 16 shl 1 == 1 + (16 shl 1)
|
||||||
|
echo 2 and 1 in {0, 30}
|
||||||
|
echo 2+2 * 2 shr 1
|
||||||
|
echo false or 2 and 1 in {0, 30}
|
||||||
|
|
||||||
|
proc `^`(a, b: int): int = a + b div 2
|
||||||
|
echo 19 mod 16 ^ 4 + 2 and 1
|
||||||
|
echo 18 mod 16 ^ 4 > 0
|
||||||
|
|
||||||
|
# echo $foo gotcha
|
||||||
let foo = 77
|
let foo = 77
|
||||||
echo $foo
|
echo $foo
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue