Skip to content

Latest commit

 

History

History
265 lines (204 loc) · 5.42 KB

AST.md

File metadata and controls

265 lines (204 loc) · 5.42 KB

AST for YAML

See details: ../src/ast.ts

Node

interface Node {
    type: string;
    loc: SourceLocation;
    range: [number, number];
}

All nodes have type, range, loc and parent properties according to ESLint - The AST specification.

Content Nodes

YAMLMapping

interface YAMLMapping extends Node {
    type: "YAMLMapping"
    style: "block" | "flow"
    pairs: YAMLPair[]
    parent: YAMLDocument | YAMLPair | YAMLSequence | YAMLWithMeta
}

This is mappings.

YAMLPair

interface YAMLPair extends Node {
    type: "YAMLPair"
    key: YAMLMapping | YAMLSequence | YAMLScalar | YAMLAlias | YAMLWithMeta | null
    value: YAMLMapping | YAMLSequence | YAMLScalar | YAMLAlias | YAMLWithMeta | null
    parent: YAMLMapping
}

This is key: value pairs.

YAMLSequence

interface YAMLSequence extends Node {
    type: "YAMLSequence"
    style: "block" | "flow"
    entries: (YAMLMapping | YAMLSequence | YAMLScalar | YAMLAlias | YAMLWithMeta)[]
    parent: YAMLDocument | YAMLPair | YAMLSequence | YAMLWithMeta
}

This is sequences.

YAMLScalar

interface YAMLScalar extends Node {
    type: "YAMLScalar"
    style: "plain" | "double-quoted" | "single-quoted" | "literal" | "folded"
    value: string | number | boolean | null
    parent: YAMLDocument | YAMLPair | YAMLSequence | YAMLWithMeta
}

This is scalars.

YAMLPlainScalar

interface YAMLPlainScalar extends YAMLScalar {
    style: "plain"
    strValue: string
    raw: string
}

This is plain style scalars (unquoted scalars).

YAMLDoubleQuotedScalar

interface YAMLDoubleQuotedScalar extends YAMLScalar {
    style: "double-quoted"
    strValue: string
    value: string
    raw: string
}

This is double-quoted style scalars.

YAMLSingleQuotedScalar

interface YAMLSingleQuotedScalar extends YAMLScalar {
    style: "single-quoted"
    strValue: string
    value: string
    raw: string
}

This is single-quoted style scalars.

YAMLBlockLiteralScalar

interface YAMLBlockLiteralScalar extends YAMLScalar {
    style: "literal"
    chomping: "clip" | "keep" | "strip"
    indent: null | number
    value: string
}

This is literal style scalars.

e.g.

|
foo
bar
  • chomping
    • "clip" ... The chomping indicator is not specified.
    • "strip" ... The - chomping indicator is specified.
    • "keep" ... The + chomping indicator is specified.
  • indent ... The specified indentation indicator. It is null if not specified.

YAMLBlockFoldedScalar

interface YAMLBlockFoldedScalar extends YAMLScalar {
    style: "folded"
    chomping: "clip" | "keep" | "strip"
    indent: null | number
    value: string
}

This is folded style scalars.

e.g.

>
foo
bar

YAMLAlias

interface YAMLAlias extends Node {
    type: "YAMLAlias"
    name: string
    parent: YAMLDocument | YAMLPair | YAMLSequence | YAMLWithMeta
}

This is aliases.

Tag and Anchor

YAMLWithMeta

interface YAMLWithMeta extends Node {
    type: "YAMLWithMeta"
    anchor: YAMLAnchor | null
    tag: YAMLTag | null
    value: YAMLMapping | YAMLSequence | YAMLScalar | YAMLAlias | null
    parent: YAMLDocument | YAMLPair | YAMLSequence
}

If it has a tag or anchor, the content node will be wrapped in this node.

YAMLAnchor

interface YAMLAnchor extends Node {
    type: "YAMLAnchor"
    name: string
    parent: YAMLWithMeta
}

YAMLTag

interface YAMLTag extends Node {
    type: "YAMLTag"
    tag: string
    parent: YAMLWithMeta
}

Document

YAMLDocument

interface YAMLDocument extends Node {
    type: "YAMLDocument"
    directives: YAMLDirective[]
    content: YAMLMapping | YAMLSequence | YAMLScalar | YAMLAlias | YAMLWithMeta | null
    parent: YAMLProgram
    anchors: { [key: string]: YAMLAnchor[] }
    // YAML version
    version: string
}

YAMLDirective

interface YAMLDirective extends Node {
    type: "YAMLDirective"
    value: string
    parent: YAMLDocument
}

This is directives. In the following example, %YAML 1.2 is represented by this node.

%YAML 1.2
---
"foo"

Program

extend interface Program {
    body: YAMLDocument[]
}

The body of the Program node generated by this parser is an array of YAMLDocument.