kvgrammar

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Lexer = lexer.Rules{
	"Root": {
		{
			Name:    "Whitespace",
			Pattern: `\s+`,
		},
		{
			Name:    "DoubleQuotedString",
			Pattern: `"`,
			Action:  lexer.Push("DoubleQuotedString"),
		},
		{
			Name:    "SingleQuotedString",
			Pattern: `'`,
			Action:  lexer.Push("SingleQuotedString"),
		},
		{
			Name:    "JSON",
			Pattern: `{`,
			Action:  lexer.Push("JSON"),
		},
		{
			Name:    "Terminator",
			Pattern: `;`,
		},
		{
			Name:    "Equals",
			Pattern: `=`,
		},
		{
			Name:    "String",
			Pattern: `[^;="'\s]+`,
		},
	},
	"DoubleQuotedString": {
		{
			Name:    "Escaped",
			Pattern: `\\(?:["\\abfnrtv]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})`,
		},
		{
			Name:    "DoubleQuotedStringEnd",
			Pattern: `"`,
			Action:  lexer.Pop(),
		},
		{
			Name:    "DoubleQuotedChars",
			Pattern: `[^"\\]+`,
		},
	},
	"SingleQuotedString": {
		{
			Name:    "SingleQuotedStringEnd",
			Pattern: `'`,
			Action:  lexer.Pop(),
		},
		{
			Name:    "SingleQuotedChars",
			Pattern: `[^']+`,
		},
	},
	"JSON": {
		{
			Name:    "JSONEnd",
			Pattern: `}`,
			Action:  lexer.Pop(),
		},
		{
			Name:    "Whitespace",
			Pattern: `\s+`,
		},
		{
			Name:    "DoubleQuotedString",
			Pattern: `"`,
			Action:  lexer.Push("DoubleQuotedString"),
		},
		{
			Name:    "Colon",
			Pattern: `:`,
		},
		{
			Name:    "Comma",
			Pattern: `,`,
		},
	},
}

Functions

This section is empty.

Types

type DoubleQuoted

type DoubleQuoted struct {
	Start string             `parser:"@DoubleQuotedString"`
	Parts []DoubleQuotedPart `parser:"@@+"`
	End   string             `parser:"@DoubleQuotedStringEnd"`
}

func (*DoubleQuoted) String

func (s *DoubleQuoted) String() string

type DoubleQuotedPart

type DoubleQuotedPart struct {
	Escaped *string `parser:"(@Escaped"`
	String  *string `parser:"|@DoubleQuotedChars)"`
}

type JSON

type JSON struct {
	Start string               `parser:"@JSON"`
	Pairs []TerminatedJSONPair `parser:"@@*"`
	End   string               `parser:"@JSONEnd"`
}

type JSONPair

type JSONPair struct {
	Key   DoubleQuoted `parser:"@@"`
	Colon string       `parser:"@Colon"`
	Value DoubleQuoted `parser:"@@"`
}

type KV

type KV struct {
	Key        Str    `parser:"@@"`
	Equals     string `parser:"@Equals"`
	Value      Str    `parser:"@@?"` // The value can be the empty string.
	Terminator string `parser:"(@Terminator|@EOF)"`
}

type KVs

type KVs struct {
	JSON  JSON `parser:"(@@"`
	Pairs []KV `parser:"|@@+)"`
}

type SingleQuoted

type SingleQuoted struct {
	Start  string `parser:"@SingleQuotedString"`
	String string `parser:"@SingleQuotedChars"`
	End    string `parser:"@SingleQuotedStringEnd"`
}

type Str

type Str struct {
	Literal      string        `parser:"(@String"`
	DoubleQuoted *DoubleQuoted `parser:"| @@"`
	SingleQuoted *SingleQuoted `parser:"| @@)"`
}

func (Str) String

func (s Str) String() string

type TerminatedJSONPair

type TerminatedJSONPair struct {
	Key   DoubleQuoted `parser:"@@"`
	Colon string       `parser:"@Colon"`
	Value DoubleQuoted `parser:"@@"`
	Comma string       `parser:"@Comma?"`
}

Jump to

Keyboard shortcuts

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