diff --git a/std/d/ast.d b/std/d/ast.d index bc416c6..78dd849 100644 --- a/std/d/ast.d +++ b/std/d/ast.d @@ -74,6 +74,8 @@ class LabeledStatement : NonEmptyStatementNoCaseNoDefault interface ExpressionStatement : NonEmptyStatementNoCaseNoDefault {} interface DeclarationStatement : NonEmptyStatementNoCaseNoDefault {} +/+ + /** * $(LINK2 http://dlang.org/statement.html#IfStatement) */ @@ -395,3 +397,6 @@ class Inherits : DeclDef //FunctionDeclaration[] functions; } +/ + + ++/ diff --git a/std/d/lexer.d b/std/d/lexer.d index 2e8ae1d..896cf91 100644 --- a/std/d/lexer.d +++ b/std/d/lexer.d @@ -174,7 +174,7 @@ struct Token /** * Checks to see if the token is of the given type. */ - bool opEquals(TokenType type) const { return type == type; } + bool opEquals(TokenType type) const { return this.type == type; } /** * Comparison operator orders tokens by start index. @@ -393,7 +393,6 @@ L_advance: // since this branch at most is taken once per file _empty = true; return; -// pragma(msg, generateCaseTrie( mixin(generateCaseTrie( "=", "TokenType.assign", "@", "TokenType.at", @@ -485,7 +484,7 @@ L_advance: if (!src.canPeek()) { current.type = TokenType.dot; - current.value = getTokenValue(TokenType.dot); + current.value = tokenValue!(TokenType.dot); return; } switch (src.peek()) @@ -501,13 +500,15 @@ L_advance: { current.type = TokenType.vararg; nextCharNonLF(); + current.value = tokenValue!(TokenType.vararg); } - current.value = getTokenValue(current.type); + else + current.value = tokenValue!(TokenType.slice); return; default: nextCharNonLF(); current.type = TokenType.dot; - current.value = getTokenValue(TokenType.dot); + current.value = tokenValue!(TokenType.dot); return; } case '0': .. case '9': @@ -1464,7 +1465,7 @@ L_advance: else { current.type = TokenType.hash; - current.value = getTokenValue(TokenType.hash); + current.value = tokenValue!(TokenType.hash); } } @@ -2705,6 +2706,11 @@ pure string getTokenValue(const TokenType type) return tokenValues[type]; } +template tokenValue(TokenType val) +{ + enum tokenValue = getTokenValue(val); +} + private pure bool isNewline(ubyte ch) { return ch == '\n' || ch == '\r'; @@ -2955,7 +2961,7 @@ string printCaseStatements(K, V)(TrieNode!(K,V) node, string indentString) caseStatement ~= indentString; caseStatement ~= "\t{\n"; caseStatement ~= indentString; - caseStatement ~= "\t\tcurrent.value = getTokenValue(current.type);\n"; + caseStatement ~= "\t\tcurrent.value = tokenValue!("~node.children[k].value~");\n"; caseStatement ~= indentString; caseStatement ~= "\t\tcurrent.type = " ~ node.children[k].value; caseStatement ~= ";\n"; @@ -2975,7 +2981,7 @@ string printCaseStatements(K, V)(TrieNode!(K,V) node, string indentString) caseStatement ~= v.value; caseStatement ~= ";\n"; caseStatement ~= indentString; - caseStatement ~= "\t\tcurrent.value = getTokenValue(current.type);\n"; + caseStatement ~= "\t\tcurrent.value = tokenValue!("~v.value~");\n"; caseStatement ~= indentString; caseStatement ~= "\t\treturn;\n"; caseStatement ~= indentString; @@ -2988,7 +2994,7 @@ string printCaseStatements(K, V)(TrieNode!(K,V) node, string indentString) caseStatement ~= v.value; caseStatement ~= ";\n"; caseStatement ~= indentString; - caseStatement ~= "\tcurrent.value = getTokenValue(current.type);\n"; + caseStatement ~= "\tcurrent.value = tokenValue!("~v.value~");\n"; caseStatement ~= indentString; caseStatement ~= "\treturn;\n"; }