Testing

Basically exactly the same as our lexer, we can test our parser.

Depending on how you have your code split up, make sure you have access to both our tokenise and toAST functions, then do something like the following:

const DSL = `
new hello = 'world'
print hello
`

const tokens = tokenise(DSL)

console.log({ tokens })

const AST = toAST(tokens)

console.log({ AST })

If everything goes according to plan, it should print our tokens, and then our AST, which should look similar to:

{
  type: 'Program',
  children: [
    {
      type: 'Assignment',
      name: 'hello',
      value: {
        type: 'String',
        value: 'world'
      }
    },
    {
      type: 'Log',
      children: [
        {
          type: 'Literal',
          value: 'hello'
        }
      ]
    }
  ]
}