Skip to content

Latest commit

 

History

History
288 lines (211 loc) · 5.15 KB

SPEC.md

File metadata and controls

288 lines (211 loc) · 5.15 KB

Specifications of Javascript/Typescript CLPL Parser

Table Of Contents

Constants

These are the constants available:

Version

The current used CLPL parser version

version // ex. '0.1.0'

Methods

These are the methods available:

Parse

Parse the CLPL data into Pairs

  • Arguments
  1. clplData: string - The CLPL data to parse from
parse(clplData)
  • Example
const pairs = parse("name = 'Bob'")

From

Read from file and parse it as CLPL data into Pairs

  • Arguments
  1. path: PathOrFileDescriptor - The file path or file descriptor
  2. callback?: (err: Error | null, pairs?: Pairs) -> void - Callback called on finish
  • Usage
from(path, callback?)
  • Overloads

    • from(path: PathOrFileDescriptor) -> Promise<Pairs>
    • from(path: PathOrFileDescriptor, callback: (err: Error | null, pairs?: Pairs) -> void) -> void
  • Example

const pairs = await from("config.clpl")

FromSync

Read from file synchronously and parse it as CLPL data into Pairs

  • Arguments
  1. path: PathOrFileDescriptor - The file path or file descriptor
  • Usage
fromSync(path)
  • Example
const pairs = fromSync("config.clpl")

Transform

Transform Pairs into an Object or Map

  • Arguments
  1. pairs: Pairs - The pairs to transform from
  2. object?: boolean - Whether to transform to object instead of a map
  3. transformer?: (pair: Pair) -> unknown? - Custom transformer function to transform pair into value
  • Return Map<string, unknown> | Record<string, unknown>

  • Usage

transform(pairs, object?, transformer?)
  • Overloads

    • transform(pairs: Pairs, object: false, transformer?: (pair: Pair) -> unknown?) -> Map<string, unknown>
    • transform(pairs: Pairs, object: true, transformer?: (pair: Pair) -> unknown?) -> Record<string, unknown>
  • Example

const map = transform(pairs, false)

Gen

Generate Pairs from an object

  • Arguments
  1. obj: Map<string, unknown> | Record<string, unknown> - The object for generating to pairs from
  2. generator?: (value: unknown) -> Pair - Custom generator function for generating pair from value
  3. stack?: Set<Map<string, unknown> | Record<string, unknown> | unknown[]> - Set of references to prevent circular references
gen(obj, generator?, stack?)
  • Example
const pairs = gen({ name: "Bob" })

Stringify

Stringify Pairs into clplData

  • Arguments
  1. pairs: Pairs - The pairs to stringify from
  2. indent?: number - The number of indentation of the clplData, 0 for no indentation, max 6
  • Return string

  • Usage

stringify(pairs, indent?)
  • Example
const clplData = stringify(pairs, 2)

Types

These are the types reserved in the parser:

Pairs

Representing a group of Pair's

Map<string, Pair>

Pair

Representing a value from key-value pair

{ annotations: Annotations, block: Block }

Annotations

Representing a group of Annotation's

Map<string, Annotation>

Annotation

Representing an annotation of a value from key-value pair

{ block: Block }

Block

A super type representing type of a value

Type of blocks:

None Block

A block representing none type

{ type: 0 }

Boolean Block

A block representing a boolean (yes or no) type

{ type: 1, value: boolean }

Number Block

A block representing a number type

{ type: 2, value: number }

Text Block

A block representing a text type

{ type: 3, value: string }

List Block

A block representing a list type

{ type: 4, value: Pair[] }

Pairs Block

A block representing a pairs type

{ type: 5, value: Pairs }

BigInt Block

A block representing a bigint type

{ type: 6, value: bigint }

Annotation Block

A super type representing type of an annotation value

Type of annotation blocks:

AnnotationList Block

A block representing a list type for annotations

{ type: 4, value: Annotation[] }

Annotations Block

A block representing a pairs type for annotations

{ type: 5, value: Annotations }