Convert some token id functions to templates
This commit is contained in:
parent
8c4a87f563
commit
629c93eca7
|
@ -568,7 +568,7 @@ public struct DLexer(R)
|
|||
Token lexDecimal(LR)(ref LR range)
|
||||
{
|
||||
bool foundDot = range.front == '.';
|
||||
auto type = tok!"intLiteral";
|
||||
IdType type = tok!"intLiteral";
|
||||
if (foundDot)
|
||||
{
|
||||
range.popFront();
|
||||
|
|
|
@ -1654,7 +1654,7 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
|
|||
break;
|
||||
case tok!"enum":
|
||||
if (startsWith(tok!"enum", tok!"identifier", tok!"("))
|
||||
goto _template;
|
||||
goto case tok!"template";
|
||||
node.enumDeclaration = parseEnumDeclaration();
|
||||
if (node.enumDeclaration is null) return null;
|
||||
break;
|
||||
|
@ -1722,7 +1722,6 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
|
|||
case tok!"struct":
|
||||
node.structDeclaration = parseStructDeclaration();
|
||||
break;
|
||||
_template:
|
||||
case tok!"template":
|
||||
node.templateDeclaration = parseTemplateDeclaration();
|
||||
break;
|
||||
|
@ -5736,12 +5735,11 @@ q{(int a, ...)
|
|||
|| peekIs(tok!"(");
|
||||
index--;
|
||||
if (jump)
|
||||
goto lParen;
|
||||
goto case tok!"(";
|
||||
else
|
||||
break loop;
|
||||
|
||||
case tok!"(":
|
||||
lParen:
|
||||
auto newUnary = new UnaryExpression();
|
||||
newUnary.functionCallExpression = parseFunctionCallExpression(node);
|
||||
node = newUnary;
|
||||
|
|
31
stdx/lexer.d
31
stdx/lexer.d
|
@ -42,31 +42,44 @@ string TokenStringRepresentation(IdType, alias staticTokens, alias possibleDefau
|
|||
return null;
|
||||
}
|
||||
|
||||
IdType TokenId(IdType, alias staticTokens, alias dynamicTokens,
|
||||
alias possibleDefaultTokens, string symbol)() @property
|
||||
template TokenId(IdType, alias staticTokens, alias dynamicTokens,
|
||||
alias possibleDefaultTokens, string symbol)
|
||||
{
|
||||
static if (symbol == "")
|
||||
return 0;
|
||||
{
|
||||
enum id = 0;
|
||||
alias id TokenId;
|
||||
}
|
||||
else static if (symbol == "\0")
|
||||
return 1 + staticTokens.length + dynamicTokens.length + possibleDefaultTokens.length;
|
||||
{
|
||||
enum id = 1 + staticTokens.length + dynamicTokens.length + possibleDefaultTokens.length;
|
||||
alias id TokenId;
|
||||
}
|
||||
else
|
||||
{
|
||||
enum i = staticTokens.countUntil(symbol);
|
||||
static if (i >= 0)
|
||||
{
|
||||
enum id = i + 1;
|
||||
alias id TokenId;
|
||||
}
|
||||
else
|
||||
{
|
||||
enum ii = possibleDefaultTokens.countUntil(symbol);
|
||||
static if (ii >= 0)
|
||||
{
|
||||
enum id = ii + staticTokens.length;
|
||||
static assert (id >= 0 && id < IdType.max, "Invalid token: " ~ symbol);
|
||||
alias id TokenId;
|
||||
}
|
||||
else
|
||||
{
|
||||
enum dynamicId = dynamicTokens.countUntil(symbol);
|
||||
enum id = dynamicId >= 0 ? i + staticTokens.length + possibleDefaultTokens.length + dynamicId : -1;
|
||||
static assert (id >= 0 && id < IdType.max, "Invalid token: " ~ symbol);
|
||||
alias id TokenId;
|
||||
}
|
||||
}
|
||||
static assert (id >= 0 && id < IdType.max, "Invalid token: " ~ symbol);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,8 +179,6 @@ mixin template Lexer(R, IDType, Token, alias isSeparating, alias defaultTokenFun
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Token front() @property
|
||||
{
|
||||
return _front;
|
||||
|
@ -188,11 +199,11 @@ mixin template Lexer(R, IDType, Token, alias isSeparating, alias defaultTokenFun
|
|||
post[pseudoTok!t] = fun;
|
||||
}
|
||||
|
||||
static IDType pseudoTok(string symbol)() nothrow pure @property
|
||||
template pseudoTok(string symbol)
|
||||
{
|
||||
static assert (pseudoTokens.countUntil(symbol) >= 0);
|
||||
enum index = cast(IDType) pseudoTokens.countUntil(symbol);
|
||||
return index;
|
||||
alias index pseudoTok;
|
||||
}
|
||||
|
||||
static string escape(string input)
|
||||
|
|
Loading…
Reference in New Issue