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 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
Click to show internal directories.
Click to hide internal directories.