Skip to content

Commit

Permalink
Fix lookahead/lookbehind breaking capture group count (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
c272 committed Jul 9, 2021
1 parent 44e6fd5 commit 1dbf21c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,5 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc
/iroBaseVisitor.cs
17 changes: 15 additions & 2 deletions Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public static bool GroupsMatch(string data, int expectedGroups)
//Get groups out, ignoring escape chars.
int realGroups = 0;
bool ignoreNext = false, inCharSet = false;
foreach (var c in data)
for (int i=0; i<data.Length; i++)
{
//Get current character.
char c = data[i];

//Ignore escape chars.
if (c == '\\') { ignoreNext = true; continue; }
if (ignoreNext) { ignoreNext = false; continue; }
Expand All @@ -31,7 +34,17 @@ public static bool GroupsMatch(string data, int expectedGroups)
if (c == ']') { inCharSet = false; }
if (inCharSet) { continue; }

if (c == '(') { realGroups++; }
//If there's an open bracket, this might be a group.
if (c == '(')
{
//Is this a lookahead/lookbehind?
if (i<data.Length-1 && data[i+1] == '?')
{
//Yes, ignore.
continue;
}
realGroups++;
}
}

//Return equality.
Expand Down
4 changes: 4 additions & 0 deletions obj/Debug/.NETFramework,Version=v4.7.1.AssemblyAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
2 changes: 1 addition & 1 deletion obj/Debug/iroBaseListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------

// Generated from C:\Users\Larry\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6
// Generated from C:\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6

// Unreachable code detected
#pragma warning disable 0162
Expand Down
2 changes: 1 addition & 1 deletion obj/Debug/iroBaseVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------

// Generated from C:\Users\Larry\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6
// Generated from C:\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6

// Unreachable code detected
#pragma warning disable 0162
Expand Down
2 changes: 1 addition & 1 deletion obj/Debug/iroLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------

// Generated from C:\Users\Larry\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6
// Generated from C:\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6

// Unreachable code detected
#pragma warning disable 0162
Expand Down
2 changes: 1 addition & 1 deletion obj/Debug/iroListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------

// Generated from C:\Users\Larry\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6
// Generated from C:\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6

// Unreachable code detected
#pragma warning disable 0162
Expand Down
2 changes: 1 addition & 1 deletion obj/Debug/iroParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------

// Generated from C:\Users\Larry\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6
// Generated from C:\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6

// Unreachable code detected
#pragma warning disable 0162
Expand Down
2 changes: 1 addition & 1 deletion obj/Debug/iroVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------

// Generated from C:\Users\Larry\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6
// Generated from C:\Files\Programming\iro4cli\Grammar\iro.g4 by ANTLR 4.6.6

// Unreachable code detected
#pragma warning disable 0162
Expand Down

0 comments on commit 1dbf21c

Please sign in to comment.