Skip to content

Commit

Permalink
Merge pull request #169 from StartAutomating/Irregular-Improvement
Browse files Browse the repository at this point in the history
Irregular improvement
  • Loading branch information
StartAutomating authored Oct 29, 2022
2 parents 0bfcfd2 + e037377 commit 9861ccd
Show file tree
Hide file tree
Showing 59 changed files with 232 additions and 117 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/RunIrregularAction.yml

This file was deleted.

16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
## 0.7.5:
## 0.7.6:

* New-RegEx improvements:
* Now supporting new character classes: MarkSpacing, MarkEnclosing, MarkNonEnclosing (Fixes #168)

* More CSharp Patterns:
* ?<CSharp_Class> (Fixes #164)
* ?<CSharp_Identifier> (Fixes #165)

* Improved Patterns:
* ?<ANSI_4BitColor>/?<ANSI_Style>: Handling brightness bit before or after color (Fixes #166)

---

## 0.7.5:

* Added Patterns for Liquid:
* ?<Liquid_Expression> (Fixes #153)
Expand Down
2 changes: 1 addition & 1 deletion Irregular.GitHubWorkflow.PSDevops.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Push-Location $PSScriptRoot

Import-BuildStep -ModuleName Irregular
New-GitHubWorkflow -Name "Test, Tag, Release, and Publish" -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish, BuildModule -On Push, Demand |
New-GitHubWorkflow -Name "Test, Tag, Release, and Publish" -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish, BuildIrregular -On Push, Demand |
Set-Content .\.github\workflows\IrregularTests.yml -Encoding UTF8 -PassThru

New-GitHubWorkflow -Name "Run GitHub Action" -On Push, Demand -Job UseIrregularAction |
Expand Down
2 changes: 1 addition & 1 deletion Irregular.format.ps1xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<!-- Generated with EZOut 1.9.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<!-- Generated with EZOut 1.9.7: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Configuration>
<ViewDefinitions>
<View>
Expand Down
16 changes: 15 additions & 1 deletion Irregular.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.7.5'
ModuleVersion = '0.7.6'
RootModule = 'Irregular.psm1'
Description = 'Regular Expressions made Strangely Simple'
FormatsToProcess = 'Irregular.format.ps1xml'
Expand All @@ -14,6 +14,20 @@
LicenseURI = 'https://github.com/StartAutomating/Irregular/blob/master/LICENSE'
IconURI = 'https://github.com/StartAutomating/Irregular/blob/master/Assets/Irregular_600_Square.png'
ReleaseNotes = @'
## 0.7.6:
* New-RegEx improvements:
* Now supporting new character classes: MarkSpacing, MarkEnclosing, MarkNonEnclosing (Fixes #168)
* More CSharp Patterns:
* ?<CSharp_Class> (Fixes #164)
* ?<CSharp_Identifier> (Fixes #165)
* Improved Patterns:
* ?<ANSI_4BitColor>/?<ANSI_Style>: Handling brightness bit before or after color (Fixes #166)
---
## 0.7.5:
* Added Patterns for Liquid:
Expand Down
2 changes: 1 addition & 1 deletion Irregular.types.ps1xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<!-- Generated with EZOut 1.9.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<!-- Generated with EZOut 1.9.7: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Types>
<Type>
<Name>Irregular.Match.Extract</Name>
Expand Down
3 changes: 3 additions & 0 deletions New-RegEx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
'CombiningMark' ,'\p{Mc}',
'EnclosingMark' , '\p{Me}',
'Mark' , '\p{M}',
'MarkSpacing' , '\p{Mc}',
'MarkNonSpacing' , '\p{Mn}',
'MarkEnclosing' , '\p{Me}',
'Number' , '\p{N}',
'NumberDecimalDigit' , '\p{Nd}',
'NumberLetter' , '\p{Nl}',
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h2>Regular Expressions made Strangely Simple</h2>
<h3>A PowerShell module that helps you understand, use, and build Regular Expressions.</h3>
<h4>
<a href='https://github.com/StartAutomating/Irregular/releases/tag/v0.7.5'>v 0.7.5 </a>
<a href='https://github.com/StartAutomating/Irregular/releases/tag/v0.7.6'>v 0.7.6 </a>
</h4>
<a href='https://www.powershellgallery.com/packages/Irregular/'>
<img src='https://img.shields.io/powershellgallery/dt/Irregular' />
Expand Down Expand Up @@ -32,7 +32,7 @@ Once you understand some basics of that syntax, regular expressions become a lot
3. A Regex can have comments! ( # Like this in .NET ( or like (?#this comment) in ECMAScript ) ).
4. You don't have to do it all in one expression!

Irregular comes with 133 useful [named expressions](SavedPatterns.md), and lets you create more.
Irregular comes with 134 useful [named expressions](SavedPatterns.md), and lets you create more.

To see the expressions that ship with Irregular, run:

Expand Down Expand Up @@ -72,7 +72,7 @@ New-RegEx -StartAnchor StringStart -Pattern @(

Irregular also contains a colorized PowerShell formatter for all Regular Expressions.
This provides syntax highlighting that can make complicated expressions easier to read.
![RegexSyntaxHighlighting](assets/images/RegexSyntaxHighlighting.gif)
![RegexSyntaxHighlighting](assets/RegexSyntaxHighlighting.gif)


#### Building Regular Expressions
Expand Down
2 changes: 1 addition & 1 deletion README.ps1.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ New-RegEx -StartAnchor StringStart -Pattern @(

Irregular also contains a colorized PowerShell formatter for all Regular Expressions.
This provides syntax highlighting that can make complicated expressions easier to read.
![RegexSyntaxHighlighting](assets/images/RegexSyntaxHighlighting.gif)
![RegexSyntaxHighlighting](assets/RegexSyntaxHighlighting.gif)


#### Building Regular Expressions
Expand Down
27 changes: 16 additions & 11 deletions RegEx/ANSI/4BitColor.regex.source.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@ New-RegEx -Description "Matches an ANSI 3 or 4-bit color" |
New-RegEx -Pattern (

New-RegEx -Atomic -Or @(

New-RegEx -Pattern 1 -Optional -Name IsBright |
New-RegEx -LiteralCharacter ';' -Min 0 -Max 1 |
New-RegEx -Pattern '3' -Name IsForegroundColor

New-RegEx -LiteralCharacter ';' -Min 0 -Max 1 -Comment "A 1 and a semicolon indicate a bright color" |
New-RegEx -Pattern '3' -Name IsForegroundColor -Comment "A number that starts with 3 indicates foreground color"
New-RegEx -Name IsBright (
New-RegEx -Pattern '9' -Name IsForegroundColor
)
) -Comment "OR it could be a less common bright foreground color, which starts with 9"

New-RegEx -Pattern 1 -Optional -Name IsBright |
New-RegEx -LiteralCharacter ';' -Min 0 -Max 1 |
New-RegEx -Pattern '4' -Name IsBackgroundColor
New-RegEx -LiteralCharacter ';' -Min 0 -Max 1 -Comment "A 1 and a semicolon indicate a bright color"|
New-RegEx -Pattern '4' -Name IsBackgroundColor -Comment "A number that starts with 3 indicates foreground color"

New-RegEx -Name IsBright (
New-RegEx -Pattern '10' -Name IsBackgroundColor
)
) |
New-RegEx -Pattern '[0-7]' -Name ColorNumber |
) -Comment "OR it could be a less common bright foreground color, which starts with 9"
) |
New-RegEx -Pattern '[0-7]' -Name ColorNumber -Comment "The color number will be between 0 and 7" |
New-RegEx -NoCapture -Optional @(
New-RegEx -LiteralCharacter ';' -Min 0 -Max 1 |
New-RegEx -Pattern 1 -Optional -Name IsBright
) -Comment "Brightness can also come after a color" |
New-RegEx -LiteralCharacter 'm'
) -Name Color | #>
Set-Content -Path (Join-Path $myRoot $myName)
) -Name Color |
Set-Content -Path (Join-Path $myRoot $myName) -PassThru
20 changes: 14 additions & 6 deletions RegEx/ANSI/4BitColor.regex.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Matches an ANSI 3 or 4-bit color
\e # An Escape
\[ # Followed by a bracket
\e # An Escape
\[ # Followed by a bracket
(?<Color>(?>
(?<IsBright>1)?\;{0,1}(?<IsForegroundColor>3) |
(?<IsBright>(?<IsForegroundColor>9)) |
(?<IsBright>1)?\;{0,1}(?<IsBackgroundColor>4) |
(?<IsBright>(?<IsBackgroundColor>10)))(?<ColorNumber>[0-7])m)
(?<IsBright>1)?\;{0,1} # A 1 and a semicolon indicate a bright color
(?<IsForegroundColor>3) # A number that starts with 3 indicates foreground color
|
(?<IsBright>(?<IsForegroundColor>9)) # OR it could be a less common bright foreground color, which starts with 9
|
(?<IsBright>1)?\;{0,1} # A 1 and a semicolon indicate a bright color
(?<IsBackgroundColor>4) # A number that starts with 3 indicates foreground color
|
(?<IsBright>(?<IsBackgroundColor>10)) # OR it could be a less common bright foreground color, which starts with 9
)(?<ColorNumber>[0-7]) # The color number will be between 0 and 7
(?:\;{0,1}(?<IsBright>1)?)? # Brightness can also come after a color
m)
16 changes: 12 additions & 4 deletions RegEx/ANSI/Style.regex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@ m))
\e # An Escape
\[ # Followed by a bracket
(?<Color>(?>
(?<IsBright>1)?\;{0,1}(?<IsForegroundColor>3) |
(?<IsBright>(?<IsForegroundColor>9)) |
(?<IsBright>1)?\;{0,1}(?<IsBackgroundColor>4) |
(?<IsBright>(?<IsBackgroundColor>10)))(?<ColorNumber>[0-7])m)
(?<IsBright>1)?\;{0,1} # A 1 and a semicolon indicate a bright color
(?<IsForegroundColor>3) # A number that starts with 3 indicates foreground color
|
(?<IsBright>(?<IsForegroundColor>9)) # OR it could be a less common bright foreground color, which starts with 9
|
(?<IsBright>1)?\;{0,1} # A 1 and a semicolon indicate a bright color
(?<IsBackgroundColor>4) # A number that starts with 3 indicates foreground color
|
(?<IsBright>(?<IsBackgroundColor>10)) # OR it could be a less common bright foreground color, which starts with 9
)(?<ColorNumber>[0-7]) # The color number will be between 0 and 7
(?:\;{0,1}(?<IsBright>1)?)? # Brightness can also come after a color
m)
)
|
(?<ANSI_DefaultColor>
Expand Down
43 changes: 43 additions & 0 deletions RegEx/CSharp/Class.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path
New-RegEx -Description 'Matches a CSharp class' |
New-RegEx -Name AccessModifier @(
New-Regex -Modifier IgnoreCase -Not
New-RegEx -Atomic -Or @(
New-RegEx -Pattern "protected\s{1,}internal"
New-RegEx -Pattern "protected"
New-RegEx -Pattern "private\s{1,}protected"
New-RegEx -Pattern "internal"
New-RegEx -Pattern "private"
New-RegEx -Pattern "public"
) -Optional
) -Comment "An Optional Access Modifier" |
New-RegEx -CharacterClass Whitespace -Min 1 |
New-RegEx -NoCapture @(
New-RegEx -Modifier IgnoreCase -Not |
New-RegEx -Pattern class |
New-RegEx -CharacterClass Whitespace -Min 1
) -Comment "Followed by 'class'" |
New-RegEx -Name ClassName @(
New-Regex -LiteralCharacter _ -CharacterClass Letter |
New-RegEx -CharacterClass PunctuationConnector, Letter, Digit, MarkNonSpacing -Min 0
) -Comment "Followed by an identifier"|
New-RegEx -Optional -Pattern @(
New-RegEx -CharacterClass Whitespace -Min 1 |
New-RegEx -LiteralCharacter ':' -Name IsInheriting |
New-RegEx -CharacterClass Whitespace -Min 1
) -NoCapture -Comment "Followed by an optional colon" |
New-RegEx -If IsInheriting -Then @(
New-RegEx -NoCapture @(
New-RegEx -CharacterClass Whitespace -Min 0
New-RegEx -Name Inherits @(
New-Regex -LiteralCharacter _ -CharacterClass Letter |
New-RegEx -CharacterClass PunctuationConnector, Letter, Digit, MarkNonSpacing -Min 0
) |
New-RegEx -CharacterClass Whitespace -Min 0 |
New-RegEx -LiteralCharacter ',' -Min 0
) -Min 1
) -Else '' -Description "If a colon was present, followed by a number of identifiers" |
New-RegEx -CharacterClass Whitespace -Min 0 -Comment "Followed by whitespace and balanced curly brackets" |
New-RegEx -Pattern ?<BalancedCurlyBracket> -Name ClassBody |
Set-Content -Path (Join-Path $myRoot $myName) -Encoding UTF8 -PassThru
23 changes: 23 additions & 0 deletions RegEx/CSharp/Class.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Matches a CSharp class
(?<AccessModifier>(?:(?-i) (?>
protected\s{1,}internal |
protected |
private\s{1,}protected |
internal |
private |
public)?)) # An Optional Access Modifier
\s{1,}(?:(?-i)class\s{1,}) # Followed by 'class'
(?<ClassName>[\p{L}_][\p{Pc}\p{L}\d\p{Mn}]{0,}) # Followed by an identifier
(?:\s{1,}(?<IsInheriting>\:)\s{1,})? # Followed by an optional colon
# If a colon was present, followed by a number of identifiers
(?(IsInheriting)((?:(?:\s{0,} (?<Inherits>[\p{L}_][\p{Pc}\p{L}\d\p{Mn}]{0,})\s{0,}\,{0,})){1,}))\s{0,} # Followed by whitespace and balanced curly brackets
(?<ClassBody>(?<BalancedCurlyBracket>
\{ # An open {
(?> # Followed by...
[^\{\}]+| # any number of non-bracket character OR
\{(?<Depth>)| # an open curly bracket (in which case increment depth) OR
\}(?<-Depth>) # a closed curly bracket (in which case decrement depth)
)*?(?(Depth)(?!)) # until depth is 0.
\} # followed by a }
)
)
6 changes: 6 additions & 0 deletions RegEx/CSharp/Identifier.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path
New-RegEx -Description 'Matches a CSharp identifier' |
New-Regex -Comment "Must start with a letter or underscore" -LiteralCharacter _ -CharacterClass Letter |
New-RegEx -CharacterClass PunctuationConnector, Letter, Digit, MarkNonSpacing -Description "Followed by any number of letters, digitis, nonspacing marks, and connector punctation" -Min 0|
Set-Content -Path (Join-Path $myRoot $myName) -Encoding UTF8 -PassThru
4 changes: 4 additions & 0 deletions RegEx/CSharp/Identifier.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Matches a CSharp identifier
[\p{L}_] # Must start with a letter or underscore
# Followed by any number of letters, digitis, nonspacing marks, and connector punctation
[\p{Pc}\p{L}\d\p{Mn}]{0,}
12 changes: 7 additions & 5 deletions RegEx/CSharp/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
This directory contains regular expressions to help parse C#.
This directory contains regular expressions to help parse C# code.


|Name |Description |Source |
|------------------------------------------|------------------------------|------------------------------------|
|[?<CSharp_Namespace>](Namespace.regex.txt)|Matches a CSharp namespace |[source](Namespace.regex.source.ps1)|
|[?<CSharp_Using>](Using.regex.txt) |Matches a CSharp using keyword|
|Name |Description |Source |
|--------------------------------------------|------------------------------|-------------------------------------|
|[?<CSharp_Class>](Class.regex.txt) |Matches a CSharp class |[source](Class.regex.source.ps1) |
|[?<CSharp_Identifier>](Identifier.regex.txt)|Matches a CSharp identifier |[source](Identifier.regex.source.ps1)|
|[?<CSharp_Namespace>](Namespace.regex.txt) |Matches a CSharp namespace |[source](Namespace.regex.source.ps1) |
|[?<CSharp_Using>](Using.regex.txt) |Matches a CSharp using keyword|


2 changes: 1 addition & 1 deletion RegEx/CSharp/README.ps1.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This directory contains regular expressions to help parse C#.
This directory contains regular expressions to help parse C# code.

~~~PipeScript{
Import-Module ../../Irregular.psd1 -Global
Expand Down
2 changes: 1 addition & 1 deletion RegEx/Digits.regex.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Repeated Digits
# Repeated Digits
\d+
8 changes: 4 additions & 4 deletions RegEx/Git/DiffHeader.regex.source.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Write-RegEx -Pattern 'diff' -StartAnchor LineStart -Comment 'diff line start' |
Write-Regex -CharacterClass Whitespace -Comment Whitespace |
Write-RegEx -Name To -CharacterClass NonWhitespace -Repeat -Comment To |
Write-RegEx -Name ExtendedHeader -Until (
Write-RegEx 'index' -StartAnchor LineStart
) -Comment "Until 'index'" |
Write-RegEx 'index' -StartAnchor LineStart |
Write-RegEx -Pattern 'index\s{1}' -StartAnchor LineStart
) -Comment "Until 'index'" <# |
Write-RegEx -Pattern 'index' |
Write-RegEx -CharacterClass Whitespace -Comment 'Index Line Start' |
Write-RegEx -Name FromHash -CharacterClass Word -Repeat -Comment FromHash |
Write-RegEx -LiteralCharacter '.' -Min 2 -Max 2 -Comment DotDot |
Expand All @@ -29,6 +29,6 @@ Write-RegEx -Pattern 'diff' -StartAnchor LineStart -Comment 'diff line start' |
Write-RegEx -LiteralCharacter '+' -Min 3 -Max 3 |
Write-RegEx -CharacterClass Whitespace -Comment PlusLineAndWhitespace |
Write-RegEx -Name ToUnified -CharacterClass NonWhitespace -Repeat -Comment ToUnified |
Write-RegEx -CharacterClass Whitespace |
Write-RegEx -CharacterClass Whitespace #> |
Set-Content -Path (Join-Path $myRoot $myName)

24 changes: 7 additions & 17 deletions RegEx/Git/DiffHeader.regex.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
# Matches Header information from the output of git diff
(?m)^diff # diff line start
\s--git\s # whitespace, then --git, then whitespace
(?<From>\S+) # From
\s # Whitespace
(?<To>\S+) # To
(?<ExtendedHeader>(?:.|\s){0,}?(?=\z|^index)) # Until 'index'
^index\s # Index Line Start
(?<FromHash>\w+) # FromHash
\.{2,2} # DotDot
(?<ToHash>\w+) # ToHash
\s(?<Mode>\w+) # FileMode
(?:.|\s){0,}?(?=\z|^---) # UntilDashLine
\-{3,3}\s # DashLineAndWhitespace
(?<FromUnified>\S+) # FromUnified
\s+\+{3,3}\s # PlusLineAndWhitespace
(?<ToUnified>\S+) # ToUnified
\s
(?m)^diff # diff line start
\s--git\s # whitespace, then --git, then whitespace
(?<From>\S+) # From
\s # Whitespace
(?<To>\S+) # To
(?<ExtendedHeader>(?:.|\s){0,}?(?=\z|^index\s{1})) # Until 'index'

Loading

0 comments on commit 9861ccd

Please sign in to comment.