forked from pvginkel/CSharpSyntax
/
CSharpNamesLexer.cs
61 lines (51 loc) · 1.6 KB
/
CSharpNamesLexer.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Text;
using Antlr.Runtime;
namespace CSharpSyntax.NameParsing
{
partial class CSharpNamesLexer
{
public override void ReportError(RecognitionException e)
{
throw new CSharpSyntaxException("Cannot parse name", e);
}
protected override object RecoverFromMismatchedToken(IIntStream input, int ttype, BitSet follow)
{
throw new MismatchedTokenException(ttype, input);
}
public override object RecoverFromMismatchedSet(IIntStream input, RecognitionException e, BitSet follow)
{
throw e;
}
private void ConsumeIdentifierUnicodeStart()
{
int c = input.LA(1);
if (!IsIdentifierStartUnicode(c))
throw new NoViableAltException();
MatchAny();
do
{
c = input.LA(1);
if (
(c >= '0' && c <= '9') ||
(c >= 'A' && c <= 'Z') ||
(c >= 'a' && c <= 'z') ||
c == '_' ||
IsIdentifierPartUnicode(c))
mIDENTIFIER_PART();
else
return;
}
while (true);
}
private bool IsIdentifierPartUnicode(int c)
{
return Char.IsLetterOrDigit((char)c);
}
private bool IsIdentifierStartUnicode(int c)
{
return Char.IsLetter((char)c);
}
}
}