json

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TokeniseJsonString = grammar.SimpleTokeniser([]grammar.TokenDef{
	{
		Ptn: `\s+`,
	},
	{
		Name: "null",
		Ptn:  `null`,
	},
	{
		Name: "bool",
		Ptn:  `true|false`,
	},
	{
		Name: "op",
		Ptn:  `[{},:[\]]`,
	},
	{
		Name: "string",
		Ptn:  `"[^"]*"`,
	},
	{
		Name: "number",
		Ptn:  `-?[0-9]+(?:\.[0-9]+)?`,
	},
})

Functions

This section is empty.

Types

type Array

type Array struct {
	grammar.Seq
	Open  grammar.Match `tok:"op,["` // This tells the parser a token of type "op" with value "[" should be used
	Items []Json        `sep:"op,,"` // This tells the parse items should be separater by a token of type "op" with value ","
	Close grammar.Match `tok:"op,]"`
}

Array ::= "[" [ArrayBody] "]"

func (Array) Compile

func (a Array) Compile() []interface{}

type Bool

type Bool struct {
	grammar.Seq
	Value Token `tok:"bool"`
}

Bool ::= <bool token>

func (Bool) Compile

func (b Bool) Compile() bool

type Dict

type Dict struct {
	grammar.Seq
	Open  grammar.Match `tok:"op,{"`
	Items []DictItem    `sep:"op,,"`
	Close grammar.Match `tok:"op,}"`
}

Dict ::= "{" [DictBody] "}"

func (Dict) Compile

func (d Dict) Compile() map[string]interface{}

type DictItem

type DictItem struct {
	grammar.Seq
	Key   String
	Colon grammar.Match `tok:"op,:"`
	Value Json
}

type Json

type Json struct {
	grammar.OneOf // This tells the parser exactly one of the fields below should be populated
	*Number
	*String
	*Null
	*Bool
	*Array
	*Dict
}

Json ::= Number | String | Null | Bool | Array | Dict

func (Json) Compile

func (j Json) Compile() interface{}

type Null

type Null struct {
	grammar.Seq
	Value Token `tok:"null,null"`
}

Null ::= "null"

func (Null) Compile

func (n Null) Compile() interface{}

type Number

type Number struct {
	grammar.Seq
	Value Token `tok:"number"` // This tells the parser that a token of type "number" should be used
}

Number ::= <number token>

func (Number) Compile

func (n Number) Compile() float64

type String

type String struct {
	grammar.Seq
	Value Token `tok:"string"`
}

String ::= <string token>

func (String) Compile

func (s String) Compile() string

type Token

type Token = grammar.SimpleToken

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL