Documentation
¶
Overview ¶
Package xsx provides tools for parsing so called eXtended S-eXpressions. Extended means the following things compared to https://people.csail.mit.edu/rivest/sexp.html:
Nested structures are delimited by balanced braces '()', '[]' or '{}’ – not only by '()'.
XSX provides a notation for "Meta Values", i.e. XSX that provide some sort of meta information that is not part of the "normal" data.
On the other hand some properties from SEXP were dropped, e.g. typing of the so called "octet strings". Things like that are completely left to the application.
Example ¶
p := NewDefaultScanner(strings.NewReader(` "xyz"foo `)) var tok Token var err error for err = p.Next(&tok, true); err == nil; err = p.Next(&tok, true) { fmt.Printf("%s [%s] %t %t\n", tok.Type, tok.String(), tok.Meta, tok.Quoted) } fmt.Println(err)
Output: Space [ ] false false Atom [xyz] false true Atom [foo] false false Space [ ] false false EOF
Index ¶
- type ExpectModifier
- type Expectation
- func (ex *Expectation) AnyAtom(mod ExpectModifier) bool
- func (ex *Expectation) Atom(s string, mod ExpectModifier) bool
- func (ex *Expectation) Begin(mod ExpectModifier, bs ...rune) bool
- func (ex *Expectation) End() bool
- func (ex *Expectation) Failed() bool
- func (ex *Expectation) Fails() Fails
- func (ex *Expectation) Reset(t *Token) *Expectation
- func (ex *Expectation) Space() bool
- func (ex *Expectation) Void() bool
- type Fails
- type Scanner
- type Syntax
- type Token
- type TokenType
- type Writer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpectModifier ¶ added in v0.8.1
type ExpectModifier int
const ( IsMeta ExpectModifier = (1 << iota) NotMeta IsQuote NotQuote )
type Expectation ¶ added in v0.8.1
type Expectation struct {
// contains filtered or unexported fields
}
Example ¶
var tok Token scn := NewStringDefaultScanner("\\") if err := scn.Next(&tok, false); err != nil { fmt.Println(err) return } ex := *Expect(&tok) switch { case ex.Begin(0, '('): fmt.Println("begin (") case ex.Atom("foo", IsQuote|NotMeta): fmt.Println("found a \"foo\"") default: fmt.Println(ex.Fails()) } fmt.Println("Expectation failed:", ex.Failed())
Output: [token is Void, not Begin] & [token is Void, not Atom] Expectation failed: true
func Expect ¶
func Expect(t *Token) *Expectation
func (*Expectation) AnyAtom ¶ added in v0.8.1
func (ex *Expectation) AnyAtom(mod ExpectModifier) bool
func (*Expectation) Atom ¶ added in v0.8.1
func (ex *Expectation) Atom(s string, mod ExpectModifier) bool
func (*Expectation) Begin ¶ added in v0.8.1
func (ex *Expectation) Begin(mod ExpectModifier, bs ...rune) bool
func (*Expectation) End ¶ added in v0.8.1
func (ex *Expectation) End() bool
func (*Expectation) Failed ¶ added in v0.8.1
func (ex *Expectation) Failed() bool
func (*Expectation) Fails ¶ added in v0.8.1
func (ex *Expectation) Fails() Fails
func (*Expectation) Reset ¶ added in v0.8.1
func (ex *Expectation) Reset(t *Token) *Expectation
func (*Expectation) Space ¶ added in v0.8.1
func (ex *Expectation) Space() bool
func (*Expectation) Void ¶ added in v0.8.1
func (ex *Expectation) Void() bool
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
func NewDefaultScanner ¶ added in v0.8.0
func NewStringDefaultScanner ¶ added in v0.8.0
func NewStringScanner ¶ added in v0.8.0
type Syntax ¶ added in v0.8.0
type Syntax struct {
// contains filtered or unexported fields
}
func DefaultSyntax ¶ added in v0.8.0
func DefaultSyntax() Syntax
func (Syntax) QuoteIf ¶ added in v0.8.0
Example ¶
syn := DefaultSyntax() fmt.Println(syn.QuoteIf("")) fmt.Println(syn.QuoteIf("foo")) fmt.Println(syn.QuoteIf("foo bar")) fmt.Println(syn.QuoteIf("(foo)")) fmt.Println(syn.QuoteIf("\\foo")) fmt.Println(syn.QuoteIf(`a "foo"`))
Output: "" true foo false "foo bar" true "(foo)" true "\foo" true "a ""foo""" true
type Writer ¶ added in v0.8.0
type Writer struct {
// contains filtered or unexported fields
}
Example ¶
syn, _ := NewSyntax("<", ">", '\'', '^') w, _ := NewWriter(os.Stdout, syn) w.Begin(0, false) w.Space("\n\t") w.Atom("foo 'n' bar", true) w.Space("\n\t") w.Atom("4711", false) w.Space("\n") w.End() w.Flush()
Output: < ^'foo ''n'' bar' 4711 >
func NewDefaultWriter ¶ added in v0.8.0
Source Files
¶
Click to show internal directories.
Click to hide internal directories.