Stream: show and tell

Topic: Parsing TypeScript source code into an AST!


view this post on Zulip Austin Davis (Sep 14 2025 at 20:17):

Hey all, I have been working on my own custom TypeScript compiler, and it's written entirely in Roc. I still haven't implemented a type-checker for it, but I've written a tokenizer and parser for most of the syntax, and it's really coming along great!

Here is an example output from the CLI:

Running program…

────────────────────────────────────────────────────────────────────────────────
🚀 TypeScript/JavaScript Parser
Enter code to parse (press Enter):
const fun = () => "FUN"

📝 Input Code:
const fun = () => "FUN"


🔍 Tokens:
ConstKeyword, WhitespaceTrivia(1), IdentifierToken(fun), WhitespaceTrivia(1), EqualsToken, WhitespaceTrivia(1), OpenParenToken, CloseParenToken, WhitespaceTrivia(1), EqualsGreaterThanToken, WhitespaceTrivia(1), StringLiteralToken("FUN"), EndOfFileToken

🌳 Parsing AST...

✨ Abstract Syntax Tree:
Program {
  sourceType: Module,
  body: [
  VariableDeclaration {
    kind: Const,
    declarations: [
    VariableDeclarator {
      id: Identifier { name: "fun" },
      init:       ArrowFunctionExpression {
        params: [0 items],
        body: StringLiteral { value: ""FUN"" },
        async: Bool.false,
        generator: Bool.false
      }
    },
    ]
  },
  ]
}

view this post on Zulip Richard Feldman (Sep 14 2025 at 20:21):

whoooooa, that's super cool!!! :heart_eyes:

view this post on Zulip Austin Davis (Sep 14 2025 at 20:25):

Thanks! Building this out in Roc has been a blast!


Last updated: Oct 20 2025 at 12:16 UTC