moonrockz/openrpc/json

Types

Code

pub(all) enum Code {
  Syntax
  DuplicateKey
  LimitExceeded
  InvalidNumber
  InvalidReference
  UnresolvedReference
  WrongType
  MissingField
  UnsupportedVersion
  UnsupportedDialect
  UnsupportedCheck
  InvalidSchema
  ParameterOrder
  MissingBaseUri
  UnavailableResource
  ConflictingIdentifier
  ReferenceCycle
  DuplicateName
  DuplicateErrorCode
  UnknownMethod
  UnknownField
  InvalidValue
  StaleNode
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

Code::equal

fn Code::equal(Code, Code) -> Bool

Source

Code::not_equal

fn Code::not_equal(x : Code, y : Code) -> Bool

Source

Code::to_repr

fn Code::to_repr(Code) -> @moonbitlang/core/debug.Repr

Source

CstDocument

pub struct CstDocument {
  source : String
  source_id : String?
  nodes : Array[Node]
  limits : Limits
} derive(@moonbitlang/core/debug.Debug)

Source

CstDocument::limits

fn CstDocument::limits(self : CstDocument) -> Limits

Source

CstDocument::lower

fn CstDocument::lower(self : CstDocument) -> Result[Value, Array[Diagnostic]]

Source

CstDocument::node_at

fn CstDocument::node_at(self : CstDocument, path : Array[String]) -> NodeId?

The first node at a structured path. Duplicate names have several nodes; SourceMap::locations lists them all.

Source

CstDocument::node_id

fn CstDocument::node_id(self : CstDocument, index : Int) -> NodeId?

Source

CstDocument::nodes

fn CstDocument::nodes(self : CstDocument) -> Array[Node]

Source

CstDocument::path

fn CstDocument::path(self : CstDocument, index : Int) -> Array[String]?

Source

CstDocument::replace_value

fn CstDocument::replace_value(self : CstDocument, node : NodeId, value : Value, limits? : Limits) -> Result[CstDocument, Diagnostic]

Replace the value at node with the compact encoding of value and parse the result. Every code unit outside the value's span is kept, including a member's key and the whitespace around it. The original CST is unchanged.

Source

CstDocument::reproduce

fn CstDocument::reproduce(self : CstDocument) -> String

Source

CstDocument::slice

fn CstDocument::slice(self : CstDocument, span : Span) -> String?

Source

CstDocument::source_id

fn CstDocument::source_id(self : CstDocument) -> String?

Source

CstDocument::source_map

fn CstDocument::source_map(self : CstDocument) -> SourceMap

Source

CstDocument::span_at

fn CstDocument::span_at(self : CstDocument, path : Array[String]) -> Span?

Source

CstDocument::to_repr

fn CstDocument::to_repr(CstDocument) -> @moonbitlang/core/debug.Repr

Source

CstDocument::tokens

fn CstDocument::tokens(self : CstDocument) -> Array[Token]

Tokenize the already-checked source, including every trivia occurrence.

Source

Diagnostic

pub struct Diagnostic {
  code : Code
  message : String
  path : Array[String]
  span : Span?
  related : Array[Span]
} derive(@moonbitlang/core/debug.Debug)

Source

Diagnostic::code

fn Diagnostic::code(self : Diagnostic) -> Code

Source

Diagnostic::message

fn Diagnostic::message(self : Diagnostic) -> String

Source

Diagnostic::new

fn Diagnostic::new(code : Code, message : String, path? : Array[String], span? : Span?, related? : Array[Span]) -> Diagnostic

Source

Diagnostic::path

fn Diagnostic::path(self : Diagnostic) -> Array[String]

Source

Diagnostic::related

fn Diagnostic::related(self : Diagnostic) -> Array[Span]

Source

Diagnostic::span

fn Diagnostic::span(self : Diagnostic) -> Span?

Source

Diagnostic::to_repr

fn Diagnostic::to_repr(Diagnostic) -> @moonbitlang/core/debug.Repr

Source

Format

pub(all) enum Format {
  Compact
  Pretty
} derive(Eq, @moonbitlang/core/debug.Debug)

Output layout. Compact is canonical; Pretty adds two-space indentation and changes nothing else.

Source

Format::equal

fn Format::equal(Format, Format) -> Bool

Source

Format::not_equal

fn Format::not_equal(x : Format, y : Format) -> Bool

Source

Format::to_repr

fn Format::to_repr(Format) -> @moonbitlang/core/debug.Repr

Source

Kind

pub(all) enum Kind {
  Null
  Boolean(Bool)
  String(String)
  Numeric(Number)
  Array(Array[Value])
  Object(Array[(String, Value)])
} derive(@moonbitlang/core/debug.Debug)

Source

Kind::to_repr

fn Kind::to_repr(Kind) -> @moonbitlang/core/debug.Repr

Source

Limits

pub struct Limits {
  max_depth : Int
  max_nodes : Int
  max_source : Int
  max_number : Int
  max_findings : Int
} derive(@moonbitlang/core/debug.Debug)

Source

Limits::max_depth

fn Limits::max_depth(self : Limits) -> Int

Source

Limits::max_findings

fn Limits::max_findings(self : Limits) -> Int

Source

Limits::max_nodes

fn Limits::max_nodes(self : Limits) -> Int

Source

Limits::max_number

fn Limits::max_number(self : Limits) -> Int

Source

Limits::max_source

fn Limits::max_source(self : Limits) -> Int

Source

Limits::new

fn Limits::new(max_depth? : Int, max_nodes? : Int, max_source? : Int, max_number? : Int, max_findings? : Int) -> Limits

Source

Limits::to_repr

fn Limits::to_repr(Limits) -> @moonbitlang/core/debug.Repr

Source

Limits::unlimited

fn Limits::unlimited() -> Limits

Remove policy bounds within the maximum representable String/Array sizes. This does not guarantee available host memory.

Source

Location

pub struct Location {
  source_id : String?
  node_index : Int
  value_span : Span
  key_span : Span?
  // private fields
} derive(@moonbitlang/core/debug.Debug)

Source

Location::key_span

fn Location::key_span(self : Location) -> Span?

Source

Location::node

fn Location::node(self : Location) -> NodeId

The node as a handle that CstDocument::replace_value accepts.

Source

Location::node_index

fn Location::node_index(self : Location) -> Int

Index into the owning CST only. It is not stable across parses or edits.

Source

Location::source_id

fn Location::source_id(self : Location) -> String?

Source

Location::to_repr

fn Location::to_repr(Location) -> @moonbitlang/core/debug.Repr

Source

Location::value_span

fn Location::value_span(self : Location) -> Span

Source

Node

pub struct Node {
  kind : NodeKind
  span : Span
  key : String?
  key_span : Span?
  children : Array[Int]
  scalar : Value?
  parent : Int?
  ordinal : Int
} derive(@moonbitlang/core/debug.Debug)

Source

Node::children

fn Node::children(self : Node) -> Array[Int]

Source

Node::key

fn Node::key(self : Node) -> String?

Source

Node::key_span

fn Node::key_span(self : Node) -> Span?

Source

Node::kind

fn Node::kind(self : Node) -> NodeKind

Source

Node::span

fn Node::span(self : Node) -> Span

Source

Node::to_repr

fn Node::to_repr(Node) -> @moonbitlang/core/debug.Repr

Source

NodeId

pub struct NodeId {
  // private fields
}

A handle to one CST node. It is valid only for a CST with exactly the same source text as the parse that produced it.

Source

NodeId::index

fn NodeId::index(self : NodeId) -> Int

Source

NodeId::to_repr

fn NodeId::to_repr(self : NodeId) -> @moonbitlang/core/debug.Repr

Source

impl Debug for NodeId

Debug::to_repr

fn to_repr(self : NodeId) -> @moonbitlang/core/debug.Repr

Source

NodeKind

pub(all) enum NodeKind {
  Scalar
  ArrayNode
  ObjectNode
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

NodeKind::equal

fn NodeKind::equal(NodeKind, NodeKind) -> Bool

Source

NodeKind::not_equal

fn NodeKind::not_equal(x : NodeKind, y : NodeKind) -> Bool

Source

NodeKind::to_repr

fn NodeKind::to_repr(NodeKind) -> @moonbitlang/core/debug.Repr

Source

Number

pub struct Number {
  token : String
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

Number::equal

fn Number::equal(Number, Number) -> Bool

Source

Number::is_integer

fn Number::is_integer(self : Number) -> Bool

Source

Number::not_equal

fn Number::not_equal(x : Number, y : Number) -> Bool

Source

Number::numeric_compare

fn Number::numeric_compare(self : Number, other : Number) -> Int

Compare mathematical values without converting to binary floating point.

Source

Number::numeric_equal

fn Number::numeric_equal(self : Number, other : Number) -> Bool

Source

Number::numeric_key

fn Number::numeric_key(self : Number) -> String

A key that is equal exactly when the numbers are numerically equal, for hashing many values without pairwise comparison.

Source

Number::parse

fn Number::parse(token : String) -> Result[Number, Diagnostic]

Source

Number::to_repr

fn Number::to_repr(Number) -> @moonbitlang/core/debug.Repr

Source

Number::token

fn Number::token(self : Number) -> String

Source

Position

pub struct Position {
  line : Int
  column : Int
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

Position::column

fn Position::column(self : Position) -> Int

Source

Position::equal

fn Position::equal(Position, Position) -> Bool

Source

Position::line

fn Position::line(self : Position) -> Int

Source

Position::not_equal

fn Position::not_equal(x : Position, y : Position) -> Bool

Source

Position::to_repr

fn Position::to_repr(Position) -> @moonbitlang/core/debug.Repr

Source

SourceMap

pub struct SourceMap {
  cst : CstDocument
  line_starts : Array[Int]
} derive(@moonbitlang/core/debug.Debug)

Source

SourceMap::locations

fn SourceMap::locations(self : SourceMap, path : Array[String]) -> Array[Location]

Return all occurrences. Duplicate object names have no implicit winner.

Source

SourceMap::position

fn SourceMap::position(self : SourceMap, offset : Int) -> Position?

Source

SourceMap::to_repr

fn SourceMap::to_repr(SourceMap) -> @moonbitlang/core/debug.Repr

Source

Span

pub struct Span {
  start : Int
  end : Int
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

Span::end

fn Span::end(self : Span) -> Int

Source

Span::equal

fn Span::equal(Span, Span) -> Bool

Source

Span::new

fn Span::new(start : Int, end : Int) -> Span?

Source

Span::not_equal

fn Span::not_equal(x : Span, y : Span) -> Bool

Source

Span::start

fn Span::start(self : Span) -> Int

Source

Span::to_repr

fn Span::to_repr(Span) -> @moonbitlang/core/debug.Repr

Source

Token

pub struct Token {
  kind : TokenKind
  span : Span
  text : String
} derive(@moonbitlang/core/debug.Debug)

Source

Token::kind

fn Token::kind(self : Token) -> TokenKind

Source

Token::span

fn Token::span(self : Token) -> Span

Source

Token::text

fn Token::text(self : Token) -> String

Source

Token::to_repr

fn Token::to_repr(Token) -> @moonbitlang/core/debug.Repr

Source

TokenKind

pub(all) enum TokenKind {
  Whitespace
  OpenObject
  CloseObject
  OpenArray
  CloseArray
  Colon
  Comma
  StringToken
  NumberToken
  TrueToken
  FalseToken
  NullToken
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

TokenKind::equal

fn TokenKind::equal(TokenKind, TokenKind) -> Bool

Source

TokenKind::not_equal

fn TokenKind::not_equal(x : TokenKind, y : TokenKind) -> Bool

Source

TokenKind::to_repr

fn TokenKind::to_repr(TokenKind) -> @moonbitlang/core/debug.Repr

Source

Value

pub struct Value {
  // private fields
} derive(@moonbitlang/core/debug.Debug)

Source

Value::array

fn Value::array(items : Array[Value]) -> Value

Source

Value::array_item

fn Value::array_item(self : Value, index : Int) -> Value?

Return an immutable array child, or None for a non-array or missing index.

Source

Value::array_length

fn Value::array_length(self : Value) -> Int?

Inspect array size without creating a copied collection view.

Source

Value::boolean

fn Value::boolean(value : Bool) -> Value

Source

Value::equals

fn Value::equals(self : Value, other : Value, numeric? : Bool, limits? : Limits) -> Result[Bool, Diagnostic]

Compare decoded JSON values. Object member order is insignificant. Numeric token spelling is significant unless numeric is selected.

Source

Value::get

fn Value::get(self : Value, name : String) -> Value?

Source

Value::kind

fn Value::kind(self : Value) -> Kind

Source

Value::null

fn Value::null() -> Value

Source

Value::number

fn Value::number(value : Number) -> Value

Source

Value::object

fn Value::object(fields : Array[(String, Value)]) -> Result[Value, Diagnostic]

Source

Value::string

fn Value::string(value : String) -> Value

Source

Value::text

fn Value::text(self : Value) -> String?

Source

Value::to_repr

fn Value::to_repr(Value) -> @moonbitlang/core/debug.Repr

Source

Values

from_core_json

fn from_core_json(value : Json, limits? : Limits) -> Result[Value, Diagnostic]

Capture the representation the caller's core Json still has. Missing original numeric digits cannot be recovered.

Source

parse

fn parse(source : String, source_id? : String?, limits? : Limits) -> Result[CstDocument, Diagnostic]

Source

to_core_json

fn to_core_json(value : Value, limits? : Limits) -> Result[Json, Diagnostic]

Set core numeric repr explicitly. Core arithmetic/equality still use Double.

Source

write

fn write(value : Value, format? : Format, limits? : Limits) -> Result[String, Diagnostic]

Deterministic JSON text: object keys by UTF-16 code units, exact number tokens, array order kept, no final newline. Pretty only adds layout.

Source