1 // SDLang-D
2 // Written in the D programming language.
3 
4 module sdlang.symbol;
5 
6 import std.algorithm;
7 
8 static immutable validSymbolNames = [
9 	"Error",
10 	"EOF",
11 	"EOL",
12 
13 	":",
14 	"=",
15 	"{",
16 	"}",
17 
18 	"Ident",
19 	"Value",
20 ];
21 
22 /// Use this to create a Symbol. Ex: symbol!"Value" or symbol!"="
23 /// Invalid names (such as symbol!"FooBar") are rejected at compile-time.
24 template symbol(string name)
25 {
26 	static assert(validSymbolNames.find(name), "Invalid Symbol: '"~name~"'");
27 	immutable symbol = _symbol(name);
28 }
29 
30 private Symbol _symbol(string name)
31 {
32 	return Symbol(name);
33 }
34 
35 /// Symbol is essentially the "type" of a Token.
36 /// Token is like an instance of a Symbol.
37 ///
38 /// This only represents terminals. Nonterminal tokens aren't
39 /// constructed since the AST is built directly during parsing.
40 ///
41 /// You can't create a Symbol directly. Instead, use the `symbol`
42 /// template.
43 struct Symbol
44 {
45 	private string _name;
46 	@property string name()
47 	{
48 		return _name;
49 	}
50 	
51 	@disable this();
52 	private this(string name)
53 	{
54 		this._name = name;
55 	}
56 
57 	string toString()
58 	{
59 		return _name;
60 	}
61 }