parsers/lang/custom_type

Experimental

Parses type declaration of the Gleam language.

Given this source code:

pub type A {
  B(c: String)
}

This AST is produced:

XCustomType(
  name: "A",
  constructors: [
    RecordConstructor(
      name: "B",
      arguments: [
        RecordConstructorArg(
          label: "c",
          ast: Constructor(module: None, name: "String", arguments: []),
        ),
      ],
    ),
  ],
  parameters: [],
  doc: None,
)

Types

pub type Ast =
  List(AstNode)
pub type AstNode {
  NodeIgnoredCode(it: IgnoredCode)
  NodeXCustomType(it: XCustomType)
}

Constructors

  • NodeIgnoredCode(it: IgnoredCode)
  • NodeXCustomType(it: XCustomType)
pub type IgnoredCode {
  IgnoredCode(content: String)
}

Constructors

  • IgnoredCode(content: String)
pub type RecordConstructor {
  RecordConstructor(
    name: String,
    arguments: List(RecordConstructorArg),
  )
}

Constructors

  • RecordConstructor(
      name: String,
      arguments: List(RecordConstructorArg),
    )
pub type RecordConstructorArg {
  RecordConstructorArg(label: String, ast: TypeAst)
}

Constructors

  • RecordConstructorArg(label: String, ast: TypeAst)
pub type TypeAst {
  Constructor(
    module: Option(String),
    name: String,
    arguments: List(TypeAst),
  )
  Fn(arguments: List(TypeAst), return_: TypeAst)
  Var(name: String)
  Tuple(elems: List(TypeAst))
  Hole(name: String)
}

Constructors

  • Constructor(
      module: Option(String),
      name: String,
      arguments: List(TypeAst),
    )
  • Fn(arguments: List(TypeAst), return_: TypeAst)
  • Var(name: String)
  • Tuple(elems: List(TypeAst))
  • Hole(name: String)
pub type XCustomType {
  XCustomType(
    name: String,
    constructors: List(RecordConstructor),
    parameters: List(String),
    doc: Option(String),
  )
}

Constructors

  • XCustomType(
      name: String,
      constructors: List(RecordConstructor),
      parameters: List(String),
      doc: Option(String),
    )

Functions

pub fn ast_parser() -> fn(Stream(String)) ->
  Result(ParseSuccess(String, List(AstNode)), ParseError(String))
pub fn filter_custom_types(ast: List(AstNode)) -> List(
  XCustomType,
)
pub fn record_constructor_argument_parser() -> fn(Stream(String)) ->
  Result(
    ParseSuccess(String, RecordConstructorArg),
    ParseError(String),
  )
pub fn record_constructor_parser() -> fn(Stream(String)) ->
  Result(
    ParseSuccess(String, RecordConstructor),
    ParseError(String),
  )
Search Document