Extended S-Expressions for Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Marcus 0f6d6a7264 Experiment with writing go objec graphs - not hierarchies only 3 weeks ago
doc Experiment with writing go objec graphs - not hierarchies only 3 weeks ago
gem Experiment with writing go objec graphs - not hierarchies only 3 weeks ago
table working pretty printer – only a qnd impl 11 months ago
util WiP 1 year ago
xso Experiment with writing go objec graphs - not hierarchies only 3 weeks ago
.gitignore Experiment with writing go objec graphs - not hierarchies only 3 weeks ago
LICENSE → github 1 year ago
Makefile Fixed error in test data gen for scanner benchmark 2 months ago
README.md Experiment with writing go objec graphs - not hierarchies only 3 weeks ago
VERSION Fixed error in test data gen for scanner benchmark 2 months ago
autocover.sh generate coverage badge in README w/o external service 8 months ago
coverage.html Experiment with writing go objec graphs - not hierarchies only 3 weeks ago
doc.go - significantly improved scanner perfromance 11 months ago
go.mod . 10 months ago
go.sum . 10 months ago
parser.go - significantly improved scanner perfromance 11 months ago
parser_test.go - significantly improved scanner perfromance 11 months ago
pcompact.go working pretty printer – only a qnd impl 11 months ago
pcompact_test.go working pretty printer – only a qnd impl 11 months ago
pnewline.go working pretty printer – only a qnd impl 11 months ago
ppretty.go working pretty printer – only a qnd impl 11 months ago
ppretty_test.go working pretty printer – only a qnd impl 11 months ago
printer.go working pretty printer – only a qnd impl 11 months ago
pull.go working pretty printer – only a qnd impl 11 months ago
pull_test.go compiles 11 months ago
scanner.go API change and fix Scanner.Read() to also scan small messages 1 month ago
scanner_test.go - significantly improved scanner perfromance 11 months ago
scanspeed_test.go Fixed error in test data gen for scanner benchmark 2 months ago
scanws_test.go - significantly improved scanner perfromance 11 months ago
version.go Fixed error in test data gen for scanner benchmark 2 months ago
write.go working pretty printer – only a qnd impl 11 months ago
write_test.go working pretty printer – only a qnd impl 11 months ago

README.md

XSX-Logo – eXtended S-eXpressions

Test Coverage Go Report Card GoDoc

import "git.fractalqb.de/fractalqb/xsx"


Package XSX provides tools for parsing something I call eXtended S-eXpressions. Extended means the following things compared to SEXP S-expressions:

  1. Nested structures are delimited by balanced braces ‘()’, ‘[]’ or ‘{}’ – not only by ‘()’.

  2. XSX provides a notation for “Meta Values”, i.e. XSXs 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.

Somewhat more formal description

Frist of all, XSX is not about datatypes, in this it is comparable to e.g. XML (No! don’t leave… its much simpler). Instead its building block is the atom, i.e. nothing else than a sequence of characters, aka a ‘string’. Atoms come as quoted atoms and as unquoted atoms. One needs to quote an atom when the atom’s string contains characters that have a special meaning in XSX: ()[]{}\ and white-space.

Regexp style definition of Atom

atom     := nq-atom | q-atom
nq-atom  := ([^()[]{}"]|\s)+
q-atom   := "([^"\]|(\")|(\\))+"
XSX      := atom

I.e. x is an atom and foo, bar and baz are atoms. An atom that contains a ‘“’ or ‘\’ would be "quote: \" and backslash: \\ in a quoted atom". Also "(" is an atom but ( is not an atom. We need ‘(’ for other things!

Sequences now BNF Style

Each atom is an XSX and from XSX’es one can build sequences:

XSX  ::= atom | seq1 | seq2 | seq3
seq1 ::= '(' ws* ')' | '(' ws* xsxs ws* ')'
seq2 ::= '[' ws* ']' | '[' ws* xsxs ws* ']'
seq3 ::= '{' ws* '}' | '{' ws* xsxs ws* '}'
xsxs ::= XSX | XSX ws* xsxs
ws   ::= '\t' | '\n' | '\v' | '\f' | '\r' | ' ' | 0x85 | 0xA0

Out-Of-Band Information with Meta XSXs

You can prefix each XSX with a backslash to make that expression a meta-expression. A meta-expression is not considered to be a XSX, i.e. you cannot create meta-meta-expressions or meta-meta-meta-expressions… hmm… and not even meta-meta-meta-meta-expressions! I think it became clear?

E.g. \4711 is a meta-atom and \{foo 1 bar false baz 3.1415} is a meta-sequence. What meta means is completely up to the application. Imagine e.g. (div hiho) and (div \{class green} hiho) to be a translation from <div>hiho</div> and <div class="green">hiho</div>.

Rationale

None! … despite the fact that I found it to be fun – and useful in some situations.

Because XSX syntax so simple it is easy to use the PullParser as a tokenizer to build customized parsers for proprietary data files. E.g. see the table sub-package. On the other hand the low level parser and scanner API is inspired by the expat streaming parser that allows one to push some data into the paring machinery and it will fire appropriate callbacks when tokes are detected.

So, if you are looking for something that’s even simpler than JSON or YAML you might give it a try… Happy coding!