parser
A program or compiler phase that reads text and builds a structured form from it, such as a syntax tree or a typed object.
In more detail
Inside a compiler, the parser turns tokens into an abstract syntax tree. The same word is used for code that reads external data, such as JSON.parse turning text into a value. Parsing untrusted data also means checking it and rejecting anything that does not fit the expected shape.
Example
function parseWebhook(raw: unknown): WebhookEvent turns unknown input into a trusted type or throwsRelated terms
- lexical scanner — The first compiler phase, which reads source text character by character and groups it into tokens such as keywords, names and symbols.
- AST — A tree of objects that represents the structure of source code, built by the parser and used by every later compiler phase.
- JSON — A simple text format for structured data made of keys, values, lists and nested objects.
- runtime validation — Checking real data with JavaScript code while the program runs, so values from outside are proven correct before they are trusted.
Taught in
- Why TypeScript: Contracts, Erased Types And Soundness — Production TypeScript
- The Compiler Pipeline: tsc, AST And Code Emission — Production TypeScript
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- any Versus unknown: Defensive Typing In Practice — Production TypeScript
- Typeof Guards, Truthiness And Equality Narrowing — Production TypeScript
- The in Operator And Instanceof Narrowing — Production TypeScript
- Custom Type Predicates: Functions Returning is Type — Production TypeScript
- Exhaustive Narrowing With never In Production Handlers — Production TypeScript
- Why Generics: Functions, Identities And Type Variables — Production TypeScript
- The Spine Artifact: Generating Typed Models From OpenAPI — Production TypeScript