sjson

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: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List struct {
	grammar.Seq
	Open  grammar.Match `tok:"op,["`
	Items []SJSON       `sep:"op,,"`
	Close grammar.Match `tok:"op,]"`
}
Example
tokenStream, _ := tokenise(`[1, 2, 3]`)
var json SJSON
grammar.Parse(&json, tokenStream)
grammar.PrettyWrite(os.Stdout, json)
Output:

SJSON {
  List: List {
    Open: {}
    Items: [
      SJSON {
        Number: {number 1}
      }
      SJSON {
        Number: {number 2}
      }
      SJSON {
        Number: {number 3}
      }
    ]
    Close: {}
  }
}

type Object

type Object struct {
	grammar.Seq
	Open  grammar.Match `tok:"op,{"`
	Items []Pair        `sep:"op,,"`
	Close grammar.Match `tok:"op,}"`
}
Example
tokenStream, _ := tokenise(`
    {
        "name": "Bob",
        "score": 999,
        "awards": ["fast", "blob"],
        "penalties": []
    }
    `)
var json SJSON
grammar.Parse(&json, tokenStream)
grammar.PrettyWrite(os.Stdout, json)
Output:

SJSON {
  Object: Object {
    Open: {}
    Items: [
      Pair {
        Key: {string "name"}
        Colon: {}
        Value: SJSON {
          String: {string "Bob"}
        }
      }
      Pair {
        Key: {string "score"}
        Colon: {}
        Value: SJSON {
          Number: {number 999}
        }
      }
      Pair {
        Key: {string "awards"}
        Colon: {}
        Value: SJSON {
          List: List {
            Open: {}
            Items: [
              SJSON {
                String: {string "fast"}
              }
              SJSON {
                String: {string "blob"}
              }
            ]
            Close: {}
          }
        }
      }
      Pair {
        Key: {string "penalties"}
        Colon: {}
        Value: SJSON {
          List: List {
            Open: {}
            Close: {}
          }
        }
      }
    ]
    Close: {}
  }
}

type Pair

type Pair struct {
	grammar.Seq
	Key   Token         `tok:"string"`
	Colon grammar.Match `tok:"op,:"`
	Value SJSON
}

type SJSON

type SJSON struct {
	grammar.OneOf
	Number  *Token `tok:"number"`
	String  *Token `tok:"string"`
	Boolean *Token `tok:"bool"`
	*List
	*Object
}

SJSON stands for Simplified JSON as strings and numbers are simplified.

type Token

type Token = grammar.SimpleToken

Jump to

Keyboard shortcuts

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