From f3178b296833d79b11cc3baeaaf726bc2f99686f Mon Sep 17 00:00:00 2001 From: David Loscutoff Date: Tue, 20 Mar 2018 13:32:36 -0500 Subject: [PATCH] Added SC operator. --- Documentation/Operator list.md | 2 ++ Documentation/Precedence table.md | 2 +- execution.py | 9 +++++++++ operators.py | 1 + pip.py | 2 +- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Documentation/Operator list.md b/Documentation/Operator list.md index 32ba9f2..88fb235 100644 --- a/Documentation/Operator list.md +++ b/Documentation/Operator list.md @@ -248,6 +248,8 @@ Operators are listed in ASCII order. See also the [precedence table](https://git RVa Reverse iterable +SCa Swap case: `Hello, World!` becomes `hELLO, wORLD!` + SEa Secant SGa Sign of number (-1, 0, or 1) diff --git a/Documentation/Precedence table.md b/Documentation/Precedence table.md index 0ba8b76..3b24393 100644 --- a/Documentation/Precedence table.md +++ b/Documentation/Precedence table.md @@ -32,7 +32,7 @@ Regex modifiers | Unary | Remove | Binary | Left | `RM`
`DC` | Remove
Deletechars | `""`
`""` | No
Both | Yes
Yes String repetition | Binary | Left | `X` | Strmul | `""` | Both | Yes Strip and trim | Binary | Left | `\|\|`
`\|>`
`<\|`
`TM` | Strip
Lstrip
Rstrip
Trim | `""`
`""`
`""`
`""` | List
List
List
List | Yes
Yes
Yes
Yes -Strip and trim | Unary | – | `\|\|`
`\|>`
`<\|`
`TM`
`LC`
`UC` | Strip
Lstrip
Rstrip
Trim
Lowercase
Uppercase | None
None
None
None
None
None | List
List
List
List
List
List | Yes
Yes
Yes
Yes
Yes
Yes +Strip and trim | Unary | – | `\|\|`
`\|>`
`<\|`
`TM`
`LC`
`UC`
`SC` | Strip
Lstrip
Rstrip
Trim
Lowercase
Uppercase
Swapcase | None
None
None
None
None
None
None | List
List
List
List
List
List
List | Yes
Yes
Yes
Yes
Yes
Yes
Yes Range and to-base | Binary | Left | `,`
`\,`
`RR`
`TB` | Range
Inclrange
Randrange
Tobase | None
None
`0`
`0` | Both
Both
Both
Both | Yes
Yes
Yes
Yes Range and to-base | Unary | – | `,`
`\,`
`RR`
`TB` | Rangeto
Inclrangeto
Randrangeto
Tobase | None
None
None
None | Both
Both
Both
Both | Yes
Yes
Yes
Yes Low-precedence numeric operators | Binary | Left | `BA`
`BO`
`BX`
`AT`
`CM` | Bitwiseand
Bitwiseor
Bitwisexor
Arctan
Numcmp | `-1`
`0`
`0`
None
`0` | Both
Both
Both
Both
No | Yes
Yes
Yes
Yes
Yes diff --git a/execution.py b/execution.py index bc0f570..c9542ca 100644 --- a/execution.py +++ b/execution.py @@ -2889,6 +2889,15 @@ def SUB(self, lhs, rhs): type(lhs), "and", type(rhs)) return nil + def SWAPCASE(self, rhs): + if type(rhs) is Scalar: + return Scalar(str(rhs).swapcase()) + elif type(rhs) in (Range, Nil): + return rhs + else: + self.err.warn("Unimplemented argtype for SWAPCASE:", type(rhs)) + return nil + def TANGENT(self, rhs): if type(rhs) is Scalar: return Scalar(math.tan(rhs.toNumber())) diff --git a/operators.py b/operators.py index 0e5aa71..f6c67ef 100644 --- a/operators.py +++ b/operators.py @@ -278,6 +278,7 @@ def copy(self): ("TM", "TRIM", None, RVALS | IN_LAMBDA | LIST_EACH), ("LC", "LOWERCASE", None, RVALS | IN_LAMBDA | LIST_EACH), ("UC", "UPPERCASE", None, RVALS | IN_LAMBDA | LIST_EACH), + ("SC", "SWAPCASE", None, RVALS | IN_LAMBDA | LIST_EACH), ], [2, "L", (",", "RANGE", None, RVALS | IN_LAMBDA | RANGE_EACH), diff --git a/pip.py b/pip.py index d04dfef..76bb503 100755 --- a/pip.py +++ b/pip.py @@ -23,7 +23,7 @@ from execution import ProgramState from errors import FatalError -VERSION = "0.18.03.05" +VERSION = "0.18.03.20" def pip(code=None, args=None, interactive=True): if code or args: