aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdlang/symbol.d
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2016-06-16 01:49:06 -0400
committerRalph Amissah <ralph@amissah.com>2019-04-04 14:48:18 -0400
commit8ab7e935913c102fb039110e20b71f698a68c6ee (patch)
tree3472debd16ce656a57150399ce666e248565f011 /src/sdlang/symbol.d
parentstep4.1 as step4 but extract header meta & make on first reading in document (diff)
step5 sdlang used for config files and doc headers
Diffstat (limited to 'src/sdlang/symbol.d')
-rw-r--r--src/sdlang/symbol.d61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/sdlang/symbol.d b/src/sdlang/symbol.d
new file mode 100644
index 0000000..14a74a7
--- /dev/null
+++ b/src/sdlang/symbol.d
@@ -0,0 +1,61 @@
+// SDLang-D
+// Written in the D programming language.
+
+module sdlang.symbol;
+
+import std.algorithm;
+
+static immutable validSymbolNames = [
+ "Error",
+ "EOF",
+ "EOL",
+
+ ":",
+ "=",
+ "{",
+ "}",
+
+ "Ident",
+ "Value",
+];
+
+/// Use this to create a Symbol. Ex: symbol!"Value" or symbol!"="
+/// Invalid names (such as symbol!"FooBar") are rejected at compile-time.
+template symbol(string name)
+{
+ static assert(validSymbolNames.find(name), "Invalid Symbol: '"~name~"'");
+ immutable symbol = _symbol(name);
+}
+
+private Symbol _symbol(string name)
+{
+ return Symbol(name);
+}
+
+/// Symbol is essentially the "type" of a Token.
+/// Token is like an instance of a Symbol.
+///
+/// This only represents terminals. Nonterminal tokens aren't
+/// constructed since the AST is built directly during parsing.
+///
+/// You can't create a Symbol directly. Instead, use the 'symbol'
+/// template.
+struct Symbol
+{
+ private string _name;
+ @property string name()
+ {
+ return _name;
+ }
+
+ @disable this();
+ private this(string name)
+ {
+ this._name = name;
+ }
+
+ string toString()
+ {
+ return _name;
+ }
+}