Skip to content

Commit 1dbf21c

Browse files
committed
Fix lookahead/lookbehind breaking capture group count (#2)
1 parent 44e6fd5 commit 1dbf21c

File tree

9 files changed

+27
-9
lines changed

9 files changed

+27
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,5 @@ paket-files/
265265

266266
# Python Tools for Visual Studio (PTVS)
267267
__pycache__/
268-
*.pyc
268+
*.pyc
269+
/iroBaseVisitor.cs

Compiler/Compiler.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ public static bool GroupsMatch(string data, int expectedGroups)
2020
//Get groups out, ignoring escape chars.
2121
int realGroups = 0;
2222
bool ignoreNext = false, inCharSet = false;
23-
foreach (var c in data)
23+
for (int i=0; i<data.Length; i++)
2424
{
25+
//Get current character.
26+
char c = data[i];
27+
2528
//Ignore escape chars.
2629
if (c == '\\') { ignoreNext = true; continue; }
2730
if (ignoreNext) { ignoreNext = false; continue; }
@@ -31,7 +34,17 @@ public static bool GroupsMatch(string data, int expectedGroups)
3134
if (c == ']') { inCharSet = false; }
3235
if (inCharSet) { continue; }
3336

34-
if (c == '(') { realGroups++; }
37+
//If there's an open bracket, this might be a group.
38+
if (c == '(')
39+
{
40+
//Is this a lookahead/lookbehind?
41+
if (i<data.Length-1 && data[i+1] == '?')
42+
{
43+
//Yes, ignore.
44+
continue;
45+
}
46+
realGroups++;
47+
}
3548
}
3649

3750
//Return equality.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// <autogenerated />
2+
using System;
3+
using System.Reflection;
4+
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]

obj/Debug/iroBaseListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// </auto-generated>
99
//------------------------------------------------------------------------------
1010

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

1313
// Unreachable code detected
1414
#pragma warning disable 0162

obj/Debug/iroBaseVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// </auto-generated>
99
//------------------------------------------------------------------------------
1010

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

1313
// Unreachable code detected
1414
#pragma warning disable 0162

obj/Debug/iroLexer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// </auto-generated>
99
//------------------------------------------------------------------------------
1010

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

1313
// Unreachable code detected
1414
#pragma warning disable 0162

obj/Debug/iroListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// </auto-generated>
99
//------------------------------------------------------------------------------
1010

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

1313
// Unreachable code detected
1414
#pragma warning disable 0162

obj/Debug/iroParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// </auto-generated>
99
//------------------------------------------------------------------------------
1010

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

1313
// Unreachable code detected
1414
#pragma warning disable 0162

obj/Debug/iroVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// </auto-generated>
99
//------------------------------------------------------------------------------
1010

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

1313
// Unreachable code detected
1414
#pragma warning disable 0162

0 commit comments

Comments
 (0)