Skip to content

Commit 54de6d1

Browse files
committed
placeholder as object
1 parent 5f830ce commit 54de6d1

20 files changed

+133
-52
lines changed

src/SimpleStateMachine.StructuralSearch.Tests/Mock/EmptyParsingContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public class EmptyParsingContext : IParsingContext
44
{
5-
public bool TryGetPlaceholder(string name, out string value)
5+
public bool TryGetPlaceholder(string name, out Placeholder value)
66
{
77
throw new System.NotImplementedException();
88
}
@@ -12,9 +12,9 @@ public void AddPlaceholder(string name, string value)
1212
throw new System.NotImplementedException();
1313
}
1414

15-
public string GetPlaceholder(string name)
15+
public Placeholder GetPlaceholder(string name)
1616
{
17-
return name;
17+
return new Placeholder(this, name, string.Empty);
1818
}
1919
}
2020
}

src/SimpleStateMachine.StructuralSearch.Tests/PlaceholderParserTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public void TemplateParsingShouldBeSuccess(string template, string source, strin
2121
var parsingContext = new ParsingContext();
2222
var templateParser = StructuralSearch.ParseFindTemplate(template);
2323
var res = templateParser.Parse(parsingContext, source);
24-
var value = parsingContext.GetPlaceholder("test");
24+
var placeholder = parsingContext.GetPlaceholder("test");
2525

26-
Assert.Equal(value, result);
26+
Assert.Equal(placeholder.Value, result);
2727
}
2828

2929
[Theory]

src/SimpleStateMachine.StructuralSearch/IParsingContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{
33
public interface IParsingContext
44
{
5-
bool TryGetPlaceholder(string name, out string value);
5+
bool TryGetPlaceholder(string name, out Placeholder value);
66

77
void AddPlaceholder(string name, string value);
88

9-
string GetPlaceholder(string name);
9+
Placeholder GetPlaceholder(string name);
1010
}
1111
}

src/SimpleStateMachine.StructuralSearch/Parsers/PlaceholderParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public PlaceholderParser(string name)
1616

1717
public string Name { get; }
1818

19-
public override Parser<char, string> BuildParser(Func<Parser<char, string>> next,
20-
Func<Parser<char, string>> nextNext)
19+
public override Parser<char, string> BuildParser(Func<Parser<char, string>?> next,
20+
Func<Parser<char, string>?> nextNext)
2121
{
2222
var _next = next();
2323
var _nextNext = nextNext() ?? Parser<char>.End.ThenReturn(string.Empty);
@@ -60,9 +60,9 @@ public override bool TryParse(ref ParseState<char> state, ref PooledList<Expecte
6060
bool res;
6161

6262
// No use look-ahead if placeholder is already defined
63-
if (_context.TryGetPlaceholder(Name, out var value))
63+
if (_context.TryGetPlaceholder(Name, out var placeholder))
6464
{
65-
res = Parser.String(value).TryParse(ref state, ref expected, out result);
65+
res = Parser.String(placeholder.Value).TryParse(ref state, ref expected, out result);
6666
}
6767
else
6868
{

src/SimpleStateMachine.StructuralSearch/ParsingContext.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ namespace SimpleStateMachine.StructuralSearch
44
{
55
public class ParsingContext : IParsingContext
66
{
7-
public Dictionary<string, string> Placeholders { get; } = new();
7+
public Dictionary<string, Placeholder> Placeholders { get; } = new();
88

9-
public bool TryGetPlaceholder(string name, out string value)
9+
public bool TryGetPlaceholder(string name, out Placeholder value)
1010
{
1111
return Placeholders.TryGetValue(name, out value);
1212
}
1313

1414
public void AddPlaceholder(string name, string value)
1515
{
16-
Placeholders[name] = value;
16+
Placeholders[name] = new Placeholder(this, name, value);
1717
}
1818

19-
public string GetPlaceholder(string name)
19+
public Placeholder GetPlaceholder(string name)
2020
{
2121
return Placeholders[name];
2222
}

src/SimpleStateMachine.StructuralSearch/Placeholder.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SimpleStateMachine.StructuralSearch
2+
{
3+
public class Column
4+
{
5+
public readonly int Start;
6+
public readonly int End;
7+
}
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace SimpleStateMachine.StructuralSearch
2+
{
3+
public class FileProperty
4+
{
5+
public readonly string Path;
6+
public readonly string Data;
7+
public readonly string Name;
8+
public readonly string Directory;
9+
public readonly int Lenght;
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SimpleStateMachine.StructuralSearch
2+
{
3+
public class LineProperty
4+
{
5+
public readonly int Start;
6+
public readonly int End;
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SimpleStateMachine.StructuralSearch
2+
{
3+
public class OffsetProperty
4+
{
5+
public readonly int Start;
6+
public readonly int End;
7+
}
8+
}

0 commit comments

Comments
 (0)