1 module workspaced.dparseext;
2 
3 import std.algorithm;
4 import std.array;
5 import std.string;
6 
7 import dparse.ast;
8 import dparse.lexer;
9 import dparse.parser;
10 import dparse.rollback_allocator;
11 import dsymbol.builtin.names;
12 import dsymbol.modulecache : ASTAllocator, ModuleCache;
13 
14 string makeString(in IdentifierOrTemplateChain c)
15 {
16 	return c.identifiersOrTemplateInstances.map!(a => a.identifier.text).join(".");
17 }
18 
19 string astToString(T, Args...)(in T ast, Args args)
20 {
21 	import dparse.formatter : Formatter;
22 
23 	if (!ast)
24 		return null;
25 
26 	auto app = appender!string();
27 	auto formatter = new Formatter!(typeof(app))(app);
28 	formatter.format(ast, args);
29 	return app.data;
30 }
31 
32 string paramsToString(Dec)(const Dec dec)
33 {
34 	import dparse.formatter : Formatter;
35 
36 	auto app = appender!string();
37 	auto formatter = new Formatter!(typeof(app))(app);
38 
39 	static if (is(Dec == FunctionDeclaration) || is(Dec == Constructor))
40 	{
41 		formatter.format(dec.parameters);
42 	}
43 	else static if (is(Dec == TemplateDeclaration))
44 	{
45 		formatter.format(dec.templateParameters);
46 	}
47 
48 	return app.data;
49 }
50 
51 /// Other tokens
52 private enum dynamicTokens = [
53 		"specialTokenSequence", "comment", "identifier", "scriptLine", "whitespace",
54 		"doubleLiteral", "floatLiteral", "idoubleLiteral", "ifloatLiteral",
55 		"intLiteral", "longLiteral", "realLiteral", "irealLiteral", "uintLiteral",
56 		"ulongLiteral", "characterLiteral", "dstringLiteral", "stringLiteral",
57 		"wstringLiteral"
58 	];
59 
60 string tokenText(const Token token)
61 {
62 	switch (token.type)
63 	{
64 		static foreach (T; dynamicTokens)
65 		{
66 	case tok!T:
67 		}
68 		return token.text;
69 	default:
70 		return str(token.type);
71 	}
72 }