Following Phobos style guide more closely
This commit is contained in:
parent
bd4f5cd85a
commit
fe7a6bf4b0
|
@ -182,7 +182,10 @@ string[] opkwds = [
|
||||||
null, // Comment
|
null, // Comment
|
||||||
null, // Identifier
|
null, // Identifier
|
||||||
null, // ScriptLine
|
null, // ScriptLine
|
||||||
|
"__argTypes",
|
||||||
|
"__thread",
|
||||||
"__traits",
|
"__traits",
|
||||||
|
"__overloadset",
|
||||||
"__parameters",
|
"__parameters",
|
||||||
"__vector",
|
"__vector",
|
||||||
null, // Whitespace
|
null, // Whitespace
|
||||||
|
@ -213,7 +216,7 @@ immutable string opKwdValues =
|
||||||
~ "newnothrownulloverridepurerefreturnstructsuperswitchtemplatethistruetry"
|
~ "newnothrownulloverridepurerefreturnstructsuperswitchtemplatethistruetry"
|
||||||
~ "typedeftypeidtypeofunionunittestversionvolatilewhilewith__traits"
|
~ "typedeftypeidtypeofunionunittestversionvolatilewhilewith__traits"
|
||||||
~ "__vector__parameters__DATE__EOF__TIME__TIMESTAMP__VENDOR__VERSION__"
|
~ "__vector__parameters__DATE__EOF__TIME__TIMESTAMP__VENDOR__VERSION__"
|
||||||
~ "FILE__LINE__";
|
~ "FILE__LINE__overloadset__argTypes__thread";
|
||||||
|
|
||||||
void main(string[] args)
|
void main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@ html { background-color: #fdf6e3; color: #002b36; }
|
||||||
writeSpan("type", t.value);
|
writeSpan("type", t.value);
|
||||||
else if (isKeyword(t.type))
|
else if (isKeyword(t.type))
|
||||||
writeSpan("kwrd", t.value);
|
writeSpan("kwrd", t.value);
|
||||||
else if (t.type == TokenType.Comment)
|
else if (t.type == TokenType.comment)
|
||||||
writeSpan("com", t.value);
|
writeSpan("com", t.value);
|
||||||
else if (isStringLiteral(t.type))
|
else if (isStringLiteral(t.type))
|
||||||
writeSpan("str", t.value);
|
writeSpan("str", t.value);
|
||||||
|
|
22
langutils.d
22
langutils.d
|
@ -22,25 +22,25 @@ pure nothrow string getTypeFromToken(const Token t)
|
||||||
switch (t.type)
|
switch (t.type)
|
||||||
{
|
{
|
||||||
|
|
||||||
case TokenType.DoubleLiteral:
|
case TokenType.doubleLiteral:
|
||||||
return "double";
|
return "double";
|
||||||
case TokenType.FloatLiteral:
|
case TokenType.floatLiteral:
|
||||||
return "float";
|
return "float";
|
||||||
case TokenType.IntLiteral:
|
case TokenType.intLiteral:
|
||||||
return "int";
|
return "int";
|
||||||
case TokenType.RealLiteral:
|
case TokenType.realLiteral:
|
||||||
return "real";
|
return "real";
|
||||||
case TokenType.UnsignedIntLiteral:
|
case TokenType.uintLiteral:
|
||||||
return "uint";
|
return "uint";
|
||||||
case TokenType.UnsignedLongLiteral:
|
case TokenType.ulongLiteral:
|
||||||
return "ulong";
|
return "ulong";
|
||||||
case TokenType.LongLiteral:
|
case TokenType.longLiteral:
|
||||||
return "long";
|
return "long";
|
||||||
case TokenType.DStringLiteral:
|
case TokenType.dstringLiteral:
|
||||||
return "dstring";
|
return "dstring";
|
||||||
case TokenType.StringLiteral:
|
case TokenType.stringLiteral:
|
||||||
return "string";
|
return "string";
|
||||||
case TokenType.WStringLiteral:
|
case TokenType.wstringLiteral:
|
||||||
return "wstring";
|
return "wstring";
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
@ -55,5 +55,5 @@ pure bool isDocComment(ref const Token t)
|
||||||
|
|
||||||
pure nothrow bool isIdentifierOrType(const TokenType t)
|
pure nothrow bool isIdentifierOrType(const TokenType t)
|
||||||
{
|
{
|
||||||
return isType(t) || t == TokenType.Identifier;
|
return isType(t) || t == TokenType.identifier;
|
||||||
}
|
}
|
||||||
|
|
16
main.d
16
main.d
|
@ -33,13 +33,13 @@ pure nothrow bool isLineOfCode(TokenType t)
|
||||||
{
|
{
|
||||||
switch(t)
|
switch(t)
|
||||||
{
|
{
|
||||||
case TokenType.Semicolon:
|
case TokenType.semicolon:
|
||||||
case TokenType.While:
|
case TokenType.while_:
|
||||||
case TokenType.If:
|
case TokenType.if_:
|
||||||
case TokenType.For:
|
case TokenType.for_:
|
||||||
case TokenType.Foreach:
|
case TokenType.foreach_:
|
||||||
case TokenType.Foreach_reverse:
|
case TokenType.foreach_reverse_:
|
||||||
case TokenType.Case:
|
case TokenType.case_:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -180,7 +180,7 @@ int main(string[] args)
|
||||||
{
|
{
|
||||||
File f = args.length == 1 ? stdin : File(args[1]);
|
File f = args.length == 1 ? stdin : File(args[1]);
|
||||||
highlighter.highlight((cast(ubyte[]) f.byLine(KeepTerminator.yes).join()).byToken(
|
highlighter.highlight((cast(ubyte[]) f.byLine(KeepTerminator.yes).join()).byToken(
|
||||||
"", IterationStyle.Everything, TokenStyle.Source));
|
"", IterationStyle.everything, TokenStyle.source));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
272
parser.d
272
parser.d
|
@ -92,7 +92,7 @@ body
|
||||||
*/
|
*/
|
||||||
Balanced betweenBalancedBraces(TokenBuffer tokens)
|
Balanced betweenBalancedBraces(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
return betweenBalanced(tokens, TokenType.LBrace, TokenType.RBrace);
|
return betweenBalanced(tokens, TokenType.lBrace, TokenType.rBrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ Balanced betweenBalancedBraces(TokenBuffer tokens)
|
||||||
*/
|
*/
|
||||||
Balanced betweenBalancedParens(TokenBuffer tokens)
|
Balanced betweenBalancedParens(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
return betweenBalanced(tokens, TokenType.LParen, TokenType.RParen);
|
return betweenBalanced(tokens, TokenType.lParen, TokenType.rParen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ Balanced betweenBalancedParens(TokenBuffer tokens)
|
||||||
*/
|
*/
|
||||||
Balanced betweenBalancedBrackets(TokenBuffer tokens)
|
Balanced betweenBalancedBrackets(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
return betweenBalanced(tokens, TokenType.LBracket, TokenType.RBracket);
|
return betweenBalanced(tokens, TokenType.lBracket, TokenType.rBracket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void skipBalanced(alias openToken, alias closeToken)(TokenBuffer tokens)
|
void skipBalanced(alias openToken, alias closeToken)(TokenBuffer tokens)
|
||||||
|
@ -136,17 +136,17 @@ body
|
||||||
|
|
||||||
void skipParens(TokenBuffer tokens)
|
void skipParens(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
skipBalanced!(TokenType.LParen, TokenType.RParen)(tokens);
|
skipBalanced!(TokenType.lParen, TokenType.rParen)(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
void skipBrackets(TokenBuffer tokens)
|
void skipBrackets(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
skipBalanced!(TokenType.LBracket, TokenType.RBracket)(tokens);
|
skipBalanced!(TokenType.lBracket, TokenType.rBracket)(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
void skipBraces(TokenBuffer tokens)
|
void skipBraces(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
skipBalanced!(TokenType.LBrace, TokenType.RBrace)(tokens);
|
skipBalanced!(TokenType.lBrace, TokenType.rBrace)(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,7 +170,7 @@ body
|
||||||
int depth = 1;
|
int depth = 1;
|
||||||
foreach (t; betweenBalanced(tokens, open, close))
|
foreach (t; betweenBalanced(tokens, open, close))
|
||||||
{
|
{
|
||||||
if (t == TokenType.Comma)
|
if (t == TokenType.comma)
|
||||||
app.put(", ");
|
app.put(", ");
|
||||||
else
|
else
|
||||||
app.put(t.value);
|
app.put(t.value);
|
||||||
|
@ -184,7 +184,7 @@ body
|
||||||
*/
|
*/
|
||||||
string parenContent(TokenBuffer tokens)
|
string parenContent(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
return "(" ~ content(tokens, TokenType.LParen, TokenType.RParen) ~ ")";
|
return "(" ~ content(tokens, TokenType.lParen, TokenType.rParen) ~ ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ string parenContent(TokenBuffer tokens)
|
||||||
*/
|
*/
|
||||||
string bracketContent(TokenBuffer tokens)
|
string bracketContent(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
return "[" ~ content(tokens, TokenType.LBracket, TokenType.RBracket) ~ "]";
|
return "[" ~ content(tokens, TokenType.lBracket, TokenType.rBracket) ~ "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,10 +204,10 @@ string bracketContent(TokenBuffer tokens)
|
||||||
*/
|
*/
|
||||||
void skipBlockStatement(TokenBuffer tokens)
|
void skipBlockStatement(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
if (tokens.front == TokenType.LBrace)
|
if (tokens.front == TokenType.lBrace)
|
||||||
skipBraces(tokens);
|
skipBraces(tokens);
|
||||||
else
|
else
|
||||||
skipPastNext(tokens, TokenType.Semicolon);
|
skipPastNext(tokens, TokenType.semicolon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -220,11 +220,11 @@ void skipPastNext(TokenBuffer tokens, TokenType type)
|
||||||
{
|
{
|
||||||
while (!tokens.empty)
|
while (!tokens.empty)
|
||||||
{
|
{
|
||||||
if (tokens.front.type == TokenType.LBrace)
|
if (tokens.front.type == TokenType.lBrace)
|
||||||
skipBraces(tokens);
|
skipBraces(tokens);
|
||||||
else if (tokens.front.type == TokenType.LParen)
|
else if (tokens.front.type == TokenType.lParen)
|
||||||
skipParens(tokens);
|
skipParens(tokens);
|
||||||
else if (tokens.front.type == TokenType.LBracket)
|
else if (tokens.front.type == TokenType.lBracket)
|
||||||
skipBrackets(tokens);
|
skipBrackets(tokens);
|
||||||
else if (tokens.front.type == type)
|
else if (tokens.front.type == type)
|
||||||
{
|
{
|
||||||
|
@ -244,13 +244,13 @@ string parseTypeDeclaration(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
switch (tokens.front.type)
|
switch (tokens.front.type)
|
||||||
{
|
{
|
||||||
case TokenType.LBracket:
|
case TokenType.lBracket:
|
||||||
type ~= bracketContent(tokens);
|
type ~= bracketContent(tokens);
|
||||||
break;
|
break;
|
||||||
case TokenType.Not:
|
case TokenType.not:
|
||||||
type ~= tokens.front.value;
|
type ~= tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (tokens.front == TokenType.LParen)
|
if (tokens.front == TokenType.lParen)
|
||||||
type ~= parenContent(tokens);
|
type ~= parenContent(tokens);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -258,12 +258,12 @@ string parseTypeDeclaration(TokenBuffer tokens)
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TokenType.Star:
|
case TokenType.star:
|
||||||
case TokenType.BitAnd:
|
case TokenType.bitAnd:
|
||||||
type ~= tokens.front.value;
|
type ~= tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
break;
|
break;
|
||||||
case TokenType.Function:
|
case TokenType.function_:
|
||||||
type ~= " " ~ tokens.front.value;
|
type ~= " " ~ tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
type ~= parenContent(tokens);
|
type ~= parenContent(tokens);
|
||||||
|
@ -303,32 +303,32 @@ Module parseModule(TokenBuffer tokens, string protection = "public", string[] at
|
||||||
{
|
{
|
||||||
switch(tokens.front.type)
|
switch(tokens.front.type)
|
||||||
{
|
{
|
||||||
case TokenType.Pragma:
|
case TokenType.pragma_:
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (tokens.front == TokenType.LParen)
|
if (tokens.front == TokenType.lParen)
|
||||||
skipParens(tokens);
|
skipParens(tokens);
|
||||||
break;
|
break;
|
||||||
case TokenType.Mixin:
|
case TokenType.mixin_:
|
||||||
case TokenType.Assert:
|
case TokenType.assert_:
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
tokens.skipBlockStatement();
|
tokens.skipBlockStatement();
|
||||||
break;
|
break;
|
||||||
case TokenType.Alias:
|
case TokenType.alias_:
|
||||||
Alias a = parseAlias(tokens,
|
Alias a = parseAlias(tokens,
|
||||||
localProtection.empty() ? protection : localProtection,
|
localProtection.empty() ? protection : localProtection,
|
||||||
attributes);
|
attributes);
|
||||||
mod.aliases ~= a;
|
mod.aliases ~= a;
|
||||||
break;
|
break;
|
||||||
case TokenType.Import:
|
case TokenType.import_:
|
||||||
mod.imports ~= parseImports(tokens);
|
mod.imports ~= parseImports(tokens);
|
||||||
resetLocals();
|
resetLocals();
|
||||||
break;
|
break;
|
||||||
case TokenType.Version:
|
case TokenType.version_:
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (tokens.front == TokenType.LParen)
|
if (tokens.front == TokenType.lParen)
|
||||||
{
|
{
|
||||||
tokens.betweenBalancedParens();
|
tokens.betweenBalancedParens();
|
||||||
if (tokens.front == TokenType.LBrace)
|
if (tokens.front == TokenType.lBrace)
|
||||||
{
|
{
|
||||||
auto braceContent = tokens.betweenBalancedBraces();
|
auto braceContent = tokens.betweenBalancedBraces();
|
||||||
mod.merge(parseModule(braceContent,
|
mod.merge(parseModule(braceContent,
|
||||||
|
@ -336,48 +336,48 @@ Module parseModule(TokenBuffer tokens, string protection = "public", string[] at
|
||||||
attributes));
|
attributes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (tokens.front == TokenType.Assign)
|
else if (tokens.front == TokenType.assign)
|
||||||
tokens.skipBlockStatement();
|
tokens.skipBlockStatement();
|
||||||
break;
|
break;
|
||||||
case TokenType.Deprecated:
|
case TokenType.deprecated_:
|
||||||
case TokenType.Nothrow:
|
case TokenType.nothrow_:
|
||||||
case TokenType.Override:
|
case TokenType.override_:
|
||||||
case TokenType.Synchronized:
|
case TokenType.synchronized_:
|
||||||
case TokenType.Abstract:
|
case TokenType.abstract_:
|
||||||
case TokenType.Final:
|
case TokenType.final_:
|
||||||
case TokenType.Gshared:
|
case TokenType.gshared:
|
||||||
case TokenType.Static:
|
case TokenType.static_:
|
||||||
localAttributes ~= tokens.front.value;
|
localAttributes ~= tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
break;
|
break;
|
||||||
case TokenType.Const:
|
case TokenType.const_:
|
||||||
case TokenType.Immutable:
|
case TokenType.immutable_:
|
||||||
case TokenType.Inout:
|
case TokenType.inout_:
|
||||||
case TokenType.Pure:
|
case TokenType.pure_:
|
||||||
case TokenType.Scope:
|
case TokenType.scope_:
|
||||||
case TokenType.Shared:
|
case TokenType.shared_:
|
||||||
auto tmp = tokens.front.value;
|
auto tmp = tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (tokens.front == TokenType.LParen)
|
if (tokens.front == TokenType.lParen)
|
||||||
type = tmp ~ tokens.parenContent();
|
type = tmp ~ tokens.parenContent();
|
||||||
else if (tokens.front == TokenType.Colon)
|
else if (tokens.front == TokenType.colon)
|
||||||
{
|
{
|
||||||
index++;
|
index++;
|
||||||
attributes ~= tmp;
|
attributes ~= tmp;
|
||||||
}
|
}
|
||||||
localAttributes ~= tmp;
|
localAttributes ~= tmp;
|
||||||
break;
|
break;
|
||||||
case TokenType.Align:
|
case TokenType.align_:
|
||||||
case TokenType.Extern:
|
case TokenType.extern_:
|
||||||
string attribute = tokens.front.value;
|
string attribute = tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (tokens.front == TokenType.LParen)
|
if (tokens.front == TokenType.lParen)
|
||||||
attribute ~= parenContent(tokens);
|
attribute ~= parenContent(tokens);
|
||||||
if (tokens.front == TokenType.LBrace)
|
if (tokens.front == TokenType.lBrace)
|
||||||
mod.merge(parseModule(tokens.betweenBalancedBraces(),
|
mod.merge(parseModule(tokens.betweenBalancedBraces(),
|
||||||
localProtection.empty() ? protection : localProtection,
|
localProtection.empty() ? protection : localProtection,
|
||||||
attributes ~ attribute));
|
attributes ~ attribute));
|
||||||
else if (tokens.front == TokenType.Colon)
|
else if (tokens.front == TokenType.colon)
|
||||||
{
|
{
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
attributes ~= attribute;
|
attributes ~= attribute;
|
||||||
|
@ -385,23 +385,23 @@ Module parseModule(TokenBuffer tokens, string protection = "public", string[] at
|
||||||
else
|
else
|
||||||
localAttributes ~= attribute;
|
localAttributes ~= attribute;
|
||||||
break;
|
break;
|
||||||
case TokenType.Export: .. case TokenType.Public:
|
case TokenType.export_: .. case TokenType.public_:
|
||||||
string p = tokens.front.value;
|
string p = tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (tokens.front == TokenType.Colon)
|
if (tokens.front == TokenType.colon)
|
||||||
{
|
{
|
||||||
protection = p;
|
protection = p;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
}
|
}
|
||||||
else if (tokens.front == TokenType.LBrace)
|
else if (tokens.front == TokenType.lBrace)
|
||||||
mod.merge(parseModule(tokens.betweenBalancedBraces(),
|
mod.merge(parseModule(tokens.betweenBalancedBraces(),
|
||||||
p, attributes ~ localAttributes));
|
p, attributes ~ localAttributes));
|
||||||
else
|
else
|
||||||
localProtection = p;
|
localProtection = p;
|
||||||
break;
|
break;
|
||||||
case TokenType.Module:
|
case TokenType.module_:
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
while (!tokens.empty && tokens.front != TokenType.Semicolon)
|
while (!tokens.empty && tokens.front != TokenType.semicolon)
|
||||||
{
|
{
|
||||||
mod.name ~= tokens.front.value;
|
mod.name ~= tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
|
@ -409,48 +409,48 @@ Module parseModule(TokenBuffer tokens, string protection = "public", string[] at
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
resetLocals();
|
resetLocals();
|
||||||
break;
|
break;
|
||||||
case TokenType.Union:
|
case TokenType.union_:
|
||||||
mod.unions ~= parseUnion(tokens,
|
mod.unions ~= parseUnion(tokens,
|
||||||
localProtection.empty() ? protection : localProtection,
|
localProtection.empty() ? protection : localProtection,
|
||||||
localAttributes ~ attributes);
|
localAttributes ~ attributes);
|
||||||
resetLocals();
|
resetLocals();
|
||||||
break;
|
break;
|
||||||
case TokenType.Class:
|
case TokenType.class_:
|
||||||
mod.classes ~= parseClass(tokens,
|
mod.classes ~= parseClass(tokens,
|
||||||
localProtection.empty() ? protection : localProtection,
|
localProtection.empty() ? protection : localProtection,
|
||||||
localAttributes ~ attributes);
|
localAttributes ~ attributes);
|
||||||
resetLocals();
|
resetLocals();
|
||||||
break;
|
break;
|
||||||
case TokenType.Interface:
|
case TokenType.interface_:
|
||||||
mod.interfaces ~= parseInterface(tokens,
|
mod.interfaces ~= parseInterface(tokens,
|
||||||
localProtection.empty() ? protection : localProtection,
|
localProtection.empty() ? protection : localProtection,
|
||||||
localAttributes ~ attributes);
|
localAttributes ~ attributes);
|
||||||
resetLocals();
|
resetLocals();
|
||||||
break;
|
break;
|
||||||
case TokenType.Struct:
|
case TokenType.struct_:
|
||||||
mod.structs ~= parseStruct(tokens,
|
mod.structs ~= parseStruct(tokens,
|
||||||
localProtection.empty() ? protection : localProtection,
|
localProtection.empty() ? protection : localProtection,
|
||||||
localAttributes ~ attributes);
|
localAttributes ~ attributes);
|
||||||
resetLocals();
|
resetLocals();
|
||||||
break;
|
break;
|
||||||
case TokenType.Enum:
|
case TokenType.enum_:
|
||||||
mod.enums ~= parseEnum(tokens,
|
mod.enums ~= parseEnum(tokens,
|
||||||
localProtection.empty() ? protection : localProtection,
|
localProtection.empty() ? protection : localProtection,
|
||||||
localAttributes ~ attributes);
|
localAttributes ~ attributes);
|
||||||
resetLocals();
|
resetLocals();
|
||||||
break;
|
break;
|
||||||
case TokenType.Template:
|
case TokenType.template_:
|
||||||
tokens.popFront(); // template
|
tokens.popFront(); // template
|
||||||
tokens.popFront(); // name
|
tokens.popFront(); // name
|
||||||
if (tokens.front == TokenType.LParen)
|
if (tokens.front == TokenType.lParen)
|
||||||
tokens.betweenBalancedParens(); // params
|
tokens.betweenBalancedParens(); // params
|
||||||
if (tokens.front == TokenType.LBrace)
|
if (tokens.front == TokenType.lBrace)
|
||||||
tokens.betweenBalancedBraces(); // body
|
tokens.betweenBalancedBraces(); // body
|
||||||
resetLocals();
|
resetLocals();
|
||||||
break;
|
break;
|
||||||
case TokenType.Bool: .. case TokenType.WString:
|
case TokenType.bool_: .. case TokenType.wstring_:
|
||||||
case TokenType.Auto:
|
case TokenType.auto_:
|
||||||
case TokenType.Identifier:
|
case TokenType.identifier:
|
||||||
if (type.empty())
|
if (type.empty())
|
||||||
{
|
{
|
||||||
type = tokens.parseTypeDeclaration();
|
type = tokens.parseTypeDeclaration();
|
||||||
|
@ -460,7 +460,7 @@ Module parseModule(TokenBuffer tokens, string protection = "public", string[] at
|
||||||
name = tokens.front.value;
|
name = tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (tokens.empty) break;
|
if (tokens.empty) break;
|
||||||
if (tokens.front == TokenType.LParen)
|
if (tokens.front == TokenType.lParen)
|
||||||
{
|
{
|
||||||
mod.functions ~= parseFunction(tokens, type, name,
|
mod.functions ~= parseFunction(tokens, type, name,
|
||||||
tokens.front.lineNumber,
|
tokens.front.lineNumber,
|
||||||
|
@ -480,24 +480,24 @@ Module parseModule(TokenBuffer tokens, string protection = "public", string[] at
|
||||||
resetLocals();
|
resetLocals();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TokenType.Unittest:
|
case TokenType.unittest_:
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (!tokens.empty() && tokens.front == TokenType.LBrace)
|
if (!tokens.empty() && tokens.front == TokenType.lBrace)
|
||||||
tokens.skipBlockStatement();
|
tokens.skipBlockStatement();
|
||||||
resetLocals();
|
resetLocals();
|
||||||
break;
|
break;
|
||||||
case TokenType.Tilde:
|
case TokenType.tilde:
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (tokens.front == TokenType.This)
|
if (tokens.front == TokenType.this_)
|
||||||
{
|
{
|
||||||
name = "~";
|
name = "~";
|
||||||
goto case;
|
goto case;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TokenType.This:
|
case TokenType.this_:
|
||||||
name ~= tokens.front.value;
|
name ~= tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (!tokens.empty && tokens.front == TokenType.LParen)
|
if (!tokens.empty && tokens.front == TokenType.lParen)
|
||||||
{
|
{
|
||||||
mod.functions ~= parseFunction(tokens, "", name,
|
mod.functions ~= parseFunction(tokens, "", name,
|
||||||
tokens.peek(-1).lineNumber,
|
tokens.peek(-1).lineNumber,
|
||||||
|
@ -522,7 +522,7 @@ Module parseModule(TokenBuffer tokens, string protection = "public", string[] at
|
||||||
*/
|
*/
|
||||||
string[] parseImports(TokenBuffer tokens)
|
string[] parseImports(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
assert(tokens.front == TokenType.Import);
|
assert(tokens.front == TokenType.import_);
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
auto app = appender!(string[])();
|
auto app = appender!(string[])();
|
||||||
string im;
|
string im;
|
||||||
|
@ -530,17 +530,17 @@ string[] parseImports(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
switch(tokens.front.type)
|
switch(tokens.front.type)
|
||||||
{
|
{
|
||||||
case TokenType.Comma:
|
case TokenType.comma:
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
app.put(im);
|
app.put(im);
|
||||||
im = "";
|
im = "";
|
||||||
break;
|
break;
|
||||||
case TokenType.Assign:
|
case TokenType.assign:
|
||||||
case TokenType.Semicolon:
|
case TokenType.semicolon:
|
||||||
app.put(im);
|
app.put(im);
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
return app.data;
|
return app.data;
|
||||||
case TokenType.Colon:
|
case TokenType.colon:
|
||||||
app.put(im);
|
app.put(im);
|
||||||
tokens.skipBlockStatement();
|
tokens.skipBlockStatement();
|
||||||
return app.data;
|
return app.data;
|
||||||
|
@ -560,7 +560,7 @@ string[] parseImports(TokenBuffer tokens)
|
||||||
Enum parseEnum(TokenBuffer tokens, string protection, string[] attributes)
|
Enum parseEnum(TokenBuffer tokens, string protection, string[] attributes)
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assert (tokens.front == TokenType.Enum);
|
assert (tokens.front == TokenType.enum_);
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -570,12 +570,12 @@ body
|
||||||
string enumType;
|
string enumType;
|
||||||
e.protection = protection;
|
e.protection = protection;
|
||||||
|
|
||||||
if (tokens.front == TokenType.LBrace)
|
if (tokens.front == TokenType.lBrace)
|
||||||
goto enumBody;
|
goto enumBody;
|
||||||
|
|
||||||
if (isIdentifierOrType(tokens.front.type))
|
if (isIdentifierOrType(tokens.front.type))
|
||||||
{
|
{
|
||||||
if (tokens.canPeek() && tokens.peek() == TokenType.Identifier)
|
if (tokens.canPeek() && tokens.peek() == TokenType.identifier)
|
||||||
{
|
{
|
||||||
// enum long l = 4;
|
// enum long l = 4;
|
||||||
EnumMember m;
|
EnumMember m;
|
||||||
|
@ -587,7 +587,7 @@ body
|
||||||
tokens.skipBlockStatement();
|
tokens.skipBlockStatement();
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
else if (tokens.canPeek() && tokens.peek() == TokenType.Assign)
|
else if (tokens.canPeek() && tokens.peek() == TokenType.assign)
|
||||||
{
|
{
|
||||||
// enum m = "abcd";
|
// enum m = "abcd";
|
||||||
e.name = tokens.front.value;
|
e.name = tokens.front.value;
|
||||||
|
@ -607,7 +607,7 @@ body
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokens.front == TokenType.Colon)
|
if (tokens.front == TokenType.colon)
|
||||||
{
|
{
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (!isIdentifierOrType(tokens.front.type))
|
if (!isIdentifierOrType(tokens.front.type))
|
||||||
|
@ -647,7 +647,7 @@ enumBody:
|
||||||
// m.type = enumType == null ? "int" : enumType;
|
// m.type = enumType == null ? "int" : enumType;
|
||||||
// }
|
// }
|
||||||
// e.members ~= m;
|
// e.members ~= m;
|
||||||
// skipPastNext(r, TokenType.Comma, i);
|
// skipPastNext(r, TokenType.comma, i);
|
||||||
// }
|
// }
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
@ -660,7 +660,7 @@ Function parseFunction(TokenBuffer tokens, string type,
|
||||||
string name, uint line, string protection, string[] attributes)
|
string name, uint line, string protection, string[] attributes)
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assert (tokens.front == TokenType.LParen);
|
assert (tokens.front == TokenType.lParen);
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -671,7 +671,7 @@ body
|
||||||
f.attributes.insertInPlace(f.attributes.length, attributes);
|
f.attributes.insertInPlace(f.attributes.length, attributes);
|
||||||
|
|
||||||
Variable[] vars1 = parseParameters(tokens);
|
Variable[] vars1 = parseParameters(tokens);
|
||||||
if (!tokens.empty && tokens.front == TokenType.LParen)
|
if (!tokens.empty && tokens.front == TokenType.lParen)
|
||||||
{
|
{
|
||||||
f.templateParameters.insertInPlace(f.templateParameters.length,
|
f.templateParameters.insertInPlace(f.templateParameters.length,
|
||||||
map!("a.type")(vars1));
|
map!("a.type")(vars1));
|
||||||
|
@ -685,12 +685,12 @@ body
|
||||||
{
|
{
|
||||||
switch (tokens.front.type)
|
switch (tokens.front.type)
|
||||||
{
|
{
|
||||||
case TokenType.Immutable:
|
case TokenType.immutable_:
|
||||||
case TokenType.Const:
|
case TokenType.const_:
|
||||||
case TokenType.Pure:
|
case TokenType.pure_:
|
||||||
case TokenType.Nothrow:
|
case TokenType.nothrow_:
|
||||||
case TokenType.Final:
|
case TokenType.final_:
|
||||||
case TokenType.Override:
|
case TokenType.override_:
|
||||||
f.attributes ~= tokens.front.value;
|
f.attributes ~= tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
break;
|
break;
|
||||||
|
@ -699,28 +699,28 @@ body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tokens.empty && tokens.front == TokenType.If)
|
if (!tokens.empty && tokens.front == TokenType.if_)
|
||||||
f.constraint = parseConstraint(tokens);
|
f.constraint = parseConstraint(tokens);
|
||||||
|
|
||||||
while (!tokens.empty &&
|
while (!tokens.empty &&
|
||||||
(tokens.front == TokenType.In || tokens.front == TokenType.Out
|
(tokens.front == TokenType.in_ || tokens.front == TokenType.out_
|
||||||
|| tokens.front == TokenType.Body))
|
|| tokens.front == TokenType.body_))
|
||||||
{
|
{
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (!tokens.empty && tokens.front == TokenType.LParen
|
if (!tokens.empty && tokens.front == TokenType.lParen
|
||||||
&& tokens.peek(-1) == TokenType.Out)
|
&& tokens.peek(-1) == TokenType.out_)
|
||||||
{
|
{
|
||||||
tokens.skipParens();
|
tokens.skipParens();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tokens.empty && tokens.front == TokenType.LBrace)
|
if (!tokens.empty && tokens.front == TokenType.lBrace)
|
||||||
tokens.skipBlockStatement();
|
tokens.skipBlockStatement();
|
||||||
}
|
}
|
||||||
if (!tokens.empty)
|
if (!tokens.empty)
|
||||||
return f;
|
return f;
|
||||||
if (tokens.front == TokenType.LBrace)
|
if (tokens.front == TokenType.lBrace)
|
||||||
tokens.skipBlockStatement();
|
tokens.skipBlockStatement();
|
||||||
else if (tokens.front == TokenType.Semicolon)
|
else if (tokens.front == TokenType.semicolon)
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
@ -728,17 +728,17 @@ body
|
||||||
string parseConstraint(TokenBuffer tokens)
|
string parseConstraint(TokenBuffer tokens)
|
||||||
{
|
{
|
||||||
auto appender = appender!(string)();
|
auto appender = appender!(string)();
|
||||||
assert(tokens.front == TokenType.If);
|
assert(tokens.front == TokenType.if_);
|
||||||
appender.put(tokens.front.value);
|
appender.put(tokens.front.value);
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
assert(tokens.front == TokenType.LParen);
|
assert(tokens.front == TokenType.lParen);
|
||||||
return "if " ~ tokens.parenContent();
|
return "if " ~ tokens.parenContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
Variable[] parseParameters(TokenBuffer tokens)
|
Variable[] parseParameters(TokenBuffer tokens)
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assert (tokens.front == TokenType.LParen);
|
assert (tokens.front == TokenType.lParen);
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -750,30 +750,30 @@ body
|
||||||
{
|
{
|
||||||
switch(r.front.type)
|
switch(r.front.type)
|
||||||
{
|
{
|
||||||
case TokenType.Alias:
|
case TokenType.alias_:
|
||||||
case TokenType.In:
|
case TokenType.in_:
|
||||||
case TokenType.Out:
|
case TokenType.out_:
|
||||||
case TokenType.Ref:
|
case TokenType.ref_:
|
||||||
case TokenType.Scope:
|
case TokenType.scope_:
|
||||||
case TokenType.Lazy:
|
case TokenType.lazy_:
|
||||||
case TokenType.Const:
|
case TokenType.const_:
|
||||||
case TokenType.Immutable:
|
case TokenType.immutable_:
|
||||||
case TokenType.Shared:
|
case TokenType.shared_:
|
||||||
case TokenType.Inout:
|
case TokenType.inout_:
|
||||||
auto tmp = r.front.value;
|
auto tmp = r.front.value;
|
||||||
r.popFront();
|
r.popFront();
|
||||||
if (r.front == TokenType.LParen)
|
if (r.front == TokenType.lParen)
|
||||||
v.type ~= tmp ~ parenContent(r);
|
v.type ~= tmp ~ parenContent(r);
|
||||||
else
|
else
|
||||||
v.attributes ~= tmp;
|
v.attributes ~= tmp;
|
||||||
break;
|
break;
|
||||||
case TokenType.Colon:
|
case TokenType.colon:
|
||||||
i++;
|
i++;
|
||||||
r.skipPastNext(TokenType.Comma);
|
r.skipPastNext(TokenType.comma);
|
||||||
appender.put(v);
|
appender.put(v);
|
||||||
v = new Variable;
|
v = new Variable;
|
||||||
break;
|
break;
|
||||||
case TokenType.Comma:
|
case TokenType.comma:
|
||||||
++i;
|
++i;
|
||||||
appender.put(v);
|
appender.put(v);
|
||||||
v = new Variable;
|
v = new Variable;
|
||||||
|
@ -791,12 +791,12 @@ body
|
||||||
v.name = r.front.value;
|
v.name = r.front.value;
|
||||||
r.popFront();
|
r.popFront();
|
||||||
appender.put(v);
|
appender.put(v);
|
||||||
if (!r.empty && r.front == TokenType.Vararg)
|
if (!r.empty && r.front == TokenType.vararg)
|
||||||
{
|
{
|
||||||
v.type ~= " ...";
|
v.type ~= " ...";
|
||||||
}
|
}
|
||||||
v = new Variable;
|
v = new Variable;
|
||||||
r.skipPastNext(TokenType.Comma);
|
r.skipPastNext(TokenType.comma);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -807,7 +807,7 @@ body
|
||||||
string[] parseBaseClassList(TokenBuffer tokens)
|
string[] parseBaseClassList(TokenBuffer tokens)
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assert(tokens.front == TokenType.Colon);
|
assert(tokens.front == TokenType.colon);
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -815,11 +815,11 @@ body
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
while (!tokens.empty)
|
while (!tokens.empty)
|
||||||
{
|
{
|
||||||
if (tokens.front == TokenType.Identifier)
|
if (tokens.front == TokenType.identifier)
|
||||||
{
|
{
|
||||||
string base = parseTypeDeclaration(tokens);
|
string base = parseTypeDeclaration(tokens);
|
||||||
appender.put(base);
|
appender.put(base);
|
||||||
if (tokens.front == TokenType.Comma)
|
if (tokens.front == TokenType.comma)
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
@ -850,18 +850,18 @@ Struct parseStructOrUnion(TokenBuffer tokens, string protection,
|
||||||
s.protection = protection;
|
s.protection = protection;
|
||||||
s.name = tokens.front.value;
|
s.name = tokens.front.value;
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
if (tokens.front == TokenType.LParen)
|
if (tokens.front == TokenType.lParen)
|
||||||
s.templateParameters.insertInPlace(s.templateParameters.length,
|
s.templateParameters.insertInPlace(s.templateParameters.length,
|
||||||
map!("a.type")(parseParameters(tokens)));
|
map!("a.type")(parseParameters(tokens)));
|
||||||
|
|
||||||
if (tokens.empty) return s;
|
if (tokens.empty) return s;
|
||||||
|
|
||||||
if (tokens.front == TokenType.If)
|
if (tokens.front == TokenType.if_)
|
||||||
s.constraint = parseConstraint(tokens);
|
s.constraint = parseConstraint(tokens);
|
||||||
|
|
||||||
if (tokens.empty) return s;
|
if (tokens.empty) return s;
|
||||||
|
|
||||||
if (tokens.front == TokenType.LBrace)
|
if (tokens.front == TokenType.lBrace)
|
||||||
parseStructBody(tokens, s);
|
parseStructBody(tokens, s);
|
||||||
else
|
else
|
||||||
tokens.skipBlockStatement();
|
tokens.skipBlockStatement();
|
||||||
|
@ -872,7 +872,7 @@ Struct parseStruct(TokenBuffer tokens, string protection,
|
||||||
string[] attributes)
|
string[] attributes)
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assert(tokens.front == TokenType.Struct);
|
assert(tokens.front == TokenType.struct_);
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -882,7 +882,7 @@ body
|
||||||
Struct parseUnion(TokenBuffer tokens, string protection, string[] attributes)
|
Struct parseUnion(TokenBuffer tokens, string protection, string[] attributes)
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assert(tokens.front == TokenType.Union);
|
assert(tokens.front == TokenType.union_);
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -898,23 +898,23 @@ Inherits parseInherits(TokenBuffer tokens, string protection, string[] attribute
|
||||||
tokens.popFront();
|
tokens.popFront();
|
||||||
i.protection = protection;
|
i.protection = protection;
|
||||||
i.attributes.insertInPlace(i.attributes.length, attributes);
|
i.attributes.insertInPlace(i.attributes.length, attributes);
|
||||||
if (tokens.front == TokenType.LParen)
|
if (tokens.front == TokenType.lParen)
|
||||||
i.templateParameters.insertInPlace(i.templateParameters.length,
|
i.templateParameters.insertInPlace(i.templateParameters.length,
|
||||||
map!("a.type")(parseParameters(tokens)));
|
map!("a.type")(parseParameters(tokens)));
|
||||||
|
|
||||||
if (tokens.empty) return i;
|
if (tokens.empty) return i;
|
||||||
|
|
||||||
if (tokens.front == TokenType.If)
|
if (tokens.front == TokenType.if_)
|
||||||
i.constraint = parseConstraint(tokens);
|
i.constraint = parseConstraint(tokens);
|
||||||
|
|
||||||
if (tokens.empty) return i;
|
if (tokens.empty) return i;
|
||||||
|
|
||||||
if (tokens.front == TokenType.Colon)
|
if (tokens.front == TokenType.colon)
|
||||||
i.baseClasses = parseBaseClassList(tokens);
|
i.baseClasses = parseBaseClassList(tokens);
|
||||||
|
|
||||||
if (tokens.empty) return i;
|
if (tokens.empty) return i;
|
||||||
|
|
||||||
if (tokens.front == TokenType.LBrace)
|
if (tokens.front == TokenType.lBrace)
|
||||||
parseStructBody(tokens, i);
|
parseStructBody(tokens, i);
|
||||||
else
|
else
|
||||||
tokens.skipBlockStatement();
|
tokens.skipBlockStatement();
|
||||||
|
@ -924,7 +924,7 @@ Inherits parseInherits(TokenBuffer tokens, string protection, string[] attribute
|
||||||
Inherits parseInterface(TokenBuffer tokens, string protection, string[] attributes)
|
Inherits parseInterface(TokenBuffer tokens, string protection, string[] attributes)
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assert (tokens.front == TokenType.Interface);
|
assert (tokens.front == TokenType.interface_);
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -936,7 +936,7 @@ body
|
||||||
Inherits parseClass(TokenBuffer tokens, string protection, string[] attributes)
|
Inherits parseClass(TokenBuffer tokens, string protection, string[] attributes)
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assert(tokens.front == TokenType.Class);
|
assert(tokens.front == TokenType.class_);
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -954,7 +954,7 @@ body
|
||||||
Alias parseAlias(TokenBuffer tokens, string protection, string[] attributes)
|
Alias parseAlias(TokenBuffer tokens, string protection, string[] attributes)
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assert(tokens.front == TokenType.Alias);
|
assert(tokens.front == TokenType.alias_);
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -963,7 +963,7 @@ body
|
||||||
a.aliasedType = parseTypeDeclaration(tokens);
|
a.aliasedType = parseTypeDeclaration(tokens);
|
||||||
a.attributes = attributes;
|
a.attributes = attributes;
|
||||||
a.protection = protection;
|
a.protection = protection;
|
||||||
if (tokens.front == TokenType.Identifier)
|
if (tokens.front == TokenType.identifier)
|
||||||
{
|
{
|
||||||
a.name = tokens.front.value;
|
a.name = tokens.front.value;
|
||||||
a.line = tokens.front.lineNumber;
|
a.line = tokens.front.lineNumber;
|
||||||
|
|
1018
std/d/lexer.d
1018
std/d/lexer.d
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue