Crate ezno_parser

source ·
Expand description

Ezno’s Parser

Contains “string to AST” parser, AST definitions, AST back to text/string form methods and hooks for traversing/visiting AST. Used in the Ezno checker.

This is more of an exercise project and doesn’t offer too much over other great Rust based JS parsers such as swc, rome and boa.

Goals:

  • Keep under 15k lines of code (excluding /tests and /examples folders)
  • Easy to use (see examples folder)
  • Easy to read and is maintainable
  • Useful for analysis and transformations
    • See expression identifiers & source positions
    • Contains visiting implementation
  • Optionally extend the ecmascript language definition
    • TypeScript type annotations, interfaces and enums
    • JSX support
    • Others under feature = "extras"

Non-goals

  • CSTs, close to source operations etc
  • Increase code size or decrease readability for speed improvements
  • Allow new syntax at that would require modifications the lexer at runtime

“Cursors”

  • Allows holes in AST where a cursor exists, allows for LSP to provide suggestions here.

Notable structures

  • ASTNode, a trait that all AST should implement
  • FunctionBase, a abstraction for functions
  • Expression
  • Statements
  • Operators
  • TSXToken
  • TSXKeyword

Re-exports

Modules

Structs

Enums

Traits

  • Defines common methods that would exist on a AST part include position in source, creation from reader and serializing to string from settings.
  • Classes and function functions have two variants depending whether in statement position or expression position
  • A trait which means that self can be pushed to a [TokenSender]
  • Variable field can be used in type annotations but cannot have a value
  • For something to visitable it can visit all nested fields.
  • A visitor over something which is hooked/is SelfVisitable with some Data
  • A visitor over something which is hooked/is SelfVisitable with some Data
  • These are a receiver traits of the visitor
  • These are a receiver traits of the visitor

Functions

Type Definitions