interface TokenValueNode<T extends TokenType> extends TokenNode<T> {
  value: string

We now create another interface, this one being an extension of our base TokenNode, with an additional field called value.

This will be used when we need to capture what a thing references, or what it is called, when we build our token.


If we take our (shortened) DSL of:

new hello

We could pass this as:

  { type: TokenType.VariableDeclaration },
  { type: TokenType.Literal }

But.. when we go forward, we have no idea what this literal is actually called.

When we introduce our TokenValueNode, our result would look like this:

  { type: TokenType.VariableDeclaration },
  { type: TokenType.Literal, value: 'hello' }

Now we know what the literals value is.