Skip to content

Commit

Permalink
Fixed bugs; added operators and preset variables.
Browse files Browse the repository at this point in the history
- Added operators PZ, RF, QP, QR
- Added preset variables CZ, VW, VY, XC, XI, XN, XV, XY
- Bugfix: comparing a Block and non-Block using == does not crash the interpreter
- Bugfix: Pip types hash correctly, meaning that UQ works again
- Edited for coding style
  • Loading branch information
dloscutoff committed Oct 24, 2018
1 parent f3178b2 commit d95a921
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 92 deletions.
20 changes: 18 additions & 2 deletions Documentation/Pre-defined variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,40 @@ This list also includes the "special variables," which have different behavior w

`y` Empty string (modified by `Y` operator)

`z` Lowercase alphabet
`z` Lowercase alphabet a to z

`B` Block that returns its second argument (`{b}`)

`AZ` Uppercase alphabet
`AZ` Uppercase alphabet A to Z

`CZ` Lowercase consonants b to z

`PA` All **P**rintable **A**SCII characters, 32 through 126

`PI` Pi (3.141592653589793)

`VW` Lowercase vowels a to u

`VY` Lowercase vowels a to y

`XA` Pattern matching one (ASCII) letter (<code>\`[A-Za-z]\`</code>)

`XC` Pattern matching one (lowercase ASCII) consonant (<code>\`[bcdfghjklmnpqrstvwxyz]\`</code>)

`XD` Pattern matching one digit (<code>\`\d\`</code>)

`XI` Pattern matching an integer (<code>\`-?\d+\`</code>)

`XL` Pattern matching one lowercase (ASCII) letter (<code>\`[a-z]\`</code>)

`XN` Pattern matching an integer or decimal number (<code>\`-?\d+(?:\.\d+)?\`</code>)

`XU` Pattern matching one uppercase (ASCII) letter (<code>\`[A-Z]\`</code>)

`XV` Pattern matching one (lowercase ASCII) vowel, not including y (<code>\`[aeiou]\`</code>)

`XW` Pattern matching one word character--letter, number, or underscore (<code>\`\w\`</code>)

`XX` Pattern matching any one character (<code>\`.\`</code>)

`XY` Pattern matching one (lowercase ASCII) vowel, including y (<code>\`[aeiouy]\`</code>)
2 changes: 1 addition & 1 deletion Documentation/Precedence table.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Append and push | Binary | Left | `AE` <br> `AL` <br> `PE` <br> `PU` <br> `PB` <
Pop and dequeue | Unary | – | `PO` <br> `DQ` | Pop <br> Dequeue | None <br> None | No <br> No | Yes <br> Yes
High-precedence list operators | Binary | Left | `^` <br> `^@` <br> `@?` <br> `@*` <br> `<>` <br> `J` <br> `JW` <br> `RL` <br> `Z` <br> `ZD` <br> `WV` <br> `UW` <br> `CP` <br> `CG` <br> `ZG` | Split <br> Splitat <br> Find <br> Findall <br> Group <br> Join <br> Joinwrap <br> Repeatlist <br> Zip <br> Zipdefault <br> Weave <br> Unweave <br> Cartesianproduct <br> Coordinategrid <br> Zerogrid | `[]` <br> `[]` <br> None <br> `[]` <br> `[]` <br> `""` <br> None <br> `[]` <br> `[]` <br> `[]` <br> `[]` <br> `[]` <br> `[]` <br> None <br> None | Both <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> Both <br> Both | Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes
Replace-like operators | Ternary | Left | `RA` <br> `TR` | Replaceat <br> Transliterate | None <br> None | No <br> No | Yes <br> Yes
High-precedence list operators | Unary | – | `^` <br> `J` <br> `RV` <br> `Z` <br> `ZD` <br> `WV` <br> `UW` <br> `CP` <br> `CG` <br> `ZG` <br> `EY` | Split <br> Join <br> Reverse <br> Zip <br> Zipdefault <br> Weave <br> Unweave <br> Cartesianproduct <br> Coordinategrid <br> Zerogrid <br> Identitymatrix | None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None | Both <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> Both <br> Both <br> Both | Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes
High-precedence list operators | Unary | – | `^` <br> `J` <br> `RV` <br> `RF` <br> `PZ` <br> `QR` <br> `QP` <br> `Z` <br> `ZD` <br> `WV` <br> `UW` <br> `CP` <br> `CG` <br> `ZG` <br> `EY` | Split <br> Join <br> Reverse <br> Reflect <br> Palindromize <br> Quadreflect <br> Quadpalindromize <br> Zip <br> Zipdefault <br> Weave <br> Unweave <br> Cartesianproduct <br> Coordinategrid <br> Zerogrid <br> Identitymatrix | None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None <br> None | Both <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> No <br> Both <br> Both <br> Both | Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes <br> Yes
Replace | Ternary | Left | `R` | Replace | None | No | No
Low-precedence string/regex operators | Binary | Left | `WR` <br> `~` | Wrap <br> Firstmatch | `""` <br> `""` | Yes <br> Yes | Yes <br> Yes
Concatenate | Binary | Left | `.` | Cat | `""` | Both | Yes
Expand Down
27 changes: 16 additions & 11 deletions Documentation/Regex operations.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@

Regex operations in Pip use the Pattern data type. Patterns are delimited by <code>`</code> (backticks); backticks within the Pattern can be escaped using backslash, as can literal backslashes. Regexes are basically Python flavor with a few add-ons. Any legal Python regex is a legal Pip regex (as long as backticks are escaped) and will behave the same way.
Regex operations in Pip use the Pattern data type. Patterns are delimited by <code>`</code> (backticks); backticks within the Pattern can be escaped using backslash, as can literal backslashes. Regexes are basically Python flavor with a few add-ons. Any legal Python regex is a legal Pip regex (as long as backticks and `&` are escaped) and will behave the same way.

## Differences between Python and Pip

- Pip Patterns are used both as regexes and as regex replacement strings.
- In addition to back-references (e.g. `\1`), Pip replacement Patterns can contain `&`, which corresponds to the entire match (as in sed et al.).
- Many Pip regex operations set special variables similar to the ones in Perl, rather than the Python strategy of returning a match object encapsulating that information.

## Predefined Pattern variables

Some common regexes are available as predefined variables:

Variable | Value | Mnemonic
-------- | ---------- | -----------
`w` | `\s+` | Whitespace
`XA` | `[A-Za-z]` | regeX-Alpha
`XD` | `\d` | regeX-Digit
`XL` | `[a-z]` | regeX-Lowercase
`XU` | `[A-Z]` | regeX-Uppercase
`XW` | `\w` | regeX-Word
`XX` | `.` | regeX-anything
Variable | Value | Mnemonic
-------- | ------------------------- | ----------------
`w` | `\s+` | Whitespace
`XA` | `[A-Za-z]` | regeX Alpha
`XC` | `[bcdfghjklmnpqrstvwxyz]` | regeX Consonant
`XD` | `\d` | regeX Digit
`XI` | `-?\d+` | regeX Integer
`XL` | `[a-z]` | regeX Lowercase
`XN` | `-?\d+(?:\.\d+)?` | regeX Number
`XU` | `[A-Z]` | regeX Uppercase
`XV` | `[aeiou]` | regeX Vowel
`XW` | `\w` | regeX Word
`XX` | `.` | regeX anything
`XY` | `[aeiouy]` | regeX vowel-or-Y

## Regex-building operations

Expand Down
Loading

0 comments on commit d95a921

Please sign in to comment.