-
Notifications
You must be signed in to change notification settings - Fork 213
/
BlockParamsParser.cs
40 lines (32 loc) · 1.23 KB
/
BlockParamsParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using HandlebarsDotNet.Pools;
namespace HandlebarsDotNet.Compiler.Lexer
{
internal class BlockParamsParser : Parser
{
public override Token Parse(ExtendedStringReader reader)
{
var context = reader.GetContext();
var buffer = AccumulateWord(reader);
return !string.IsNullOrEmpty(buffer)
? Token.BlockParams(buffer, context)
: null;
}
private static string AccumulateWord(ExtendedStringReader reader)
{
using(var container = StringBuilderPool.Shared.Use())
{
var buffer = container.Value;
if (reader.Peek() != '|') return null;
reader.Read();
while (reader.Peek() != '|')
{
buffer.Append((char) reader.Read());
}
reader.Read();
var accumulateWord = buffer.ToString().Trim();
if(string.IsNullOrEmpty(accumulateWord)) throw new HandlebarsParserException($"BlockParams expression is not valid", reader.GetContext());
return accumulateWord;
}
}
}
}