Code cleanup.

This commit is contained in:
Maurice Makaay 2019-07-23 20:09:30 +00:00
parent 5ccb16f38f
commit 68ab1293f2
3 changed files with 20 additions and 20 deletions

View File

@ -22,14 +22,14 @@ test-a:
numactl --physcpubind=+1 bash -c "time ./A < testfile.toml" numactl --physcpubind=+1 bash -c "time ./A < testfile.toml"
profile-a: profile-a:
numactl --physcpubind=+1 bash -c "./A -p 100 < testfile.toml" numactl --physcpubind=+1 bash -c "./A -p 250 < testfile.toml"
test-b: test-b:
numactl --physcpubind=+2 bash -c "time ./B < testfile.toml" numactl --physcpubind=+2 bash -c "time ./B < testfile.toml"
profile-b: profile-b:
numactl --physcpubind=+2 bash -c "./B -p 100 < testfile.toml" numactl --physcpubind=+2 bash -c "./B -p 250 < testfile.toml"
test-sushi: test-sushi:

View File

@ -11,13 +11,13 @@ var (
// Both [tables] and [[arrays of tables]] start with a square open bracket. // Both [tables] and [[arrays of tables]] start with a square open bracket.
detectTable = a.SquareOpen detectTable = a.SquareOpen
whiteSpaceNewlinesAndComments = whitespaceInclNewlines.Or(comment) whitespaceNewlinesAndComments = whitespaceInclNewlines.Or(comment)
) )
func (t *parser) startDocument(p *parse.API) { func (t *parser) startDocument(p *parse.API) {
for { for {
switch { switch {
case p.Accept(whiteSpaceNewlinesAndComments): case p.Accept(whitespaceNewlinesAndComments):
// NOOP // NOOP
case p.Peek(detectTable): case p.Peek(detectTable):
p.Handle(t.startTable) p.Handle(t.startTable)

View File

@ -14,21 +14,21 @@ var (
// Multi-line basic strings are surrounded by three quotation marks on each // Multi-line basic strings are surrounded by three quotation marks on each
// side and allow newlines. // side and allow newlines.
doubleQuote3 = a.Str(`"""`) multiLineBasicStringDelimiter = a.Str(`"""`)
openingMultiLineBasicString = doubleQuote3.Then(newline.Optional()) openingMultiLineBasicString = multiLineBasicStringDelimiter.Then(newline.Optional())
closingMultiLineBasicString = m.Drop(doubleQuote3) closingMultiLineBasicString = m.Drop(multiLineBasicStringDelimiter)
// Multi-line literal strings are surrounded by three single quotes on each side and allow newlines. // Multi-line literal strings are surrounded by three single quotes on each side and allow newlines.
singleQuote3 = a.Str(`'''`) multiLineLiteralStringDelimiter = a.Str(`'''`)
openingMultiLineLiteralString = singleQuote3.Then(newline.Optional()) openingMultiLineLiteralString = multiLineLiteralStringDelimiter.Then(newline.Optional())
closingMultiLineLiteralString = m.Drop(singleQuote3) closingMultiLineLiteralString = m.Drop(multiLineLiteralStringDelimiter)
// Closing character for basic strings. // Opening and closing character for basic strings.
closingDoubleQuote = m.Drop(a.DoubleQuote) basicStringDelimiter = m.Drop(a.DoubleQuote)
// Closing character for literal strings. // Opening and losing character for literal strings.
closingSingleQuote = m.Drop(a.SingleQuote) literalStringDelimiter = m.Drop(a.SingleQuote)
// Control characters as defined by TOML (U+0000 to U+001F, U+007F) // Control characters as defined by TOML (U+0000 to U+001F, U+007F)
@ -67,13 +67,13 @@ func (t *parser) parseString(p *parse.API) (*ast.Value, bool) {
var value string var value string
var ok bool var ok bool
switch { switch {
case p.Peek(doubleQuote3): case p.Peek(openingMultiLineBasicString):
value, ok = t.parseMultiLineBasicString(p) value, ok = t.parseMultiLineBasicString(p)
case p.Peek(a.DoubleQuote): case p.Peek(basicStringDelimiter):
value, ok = t.parseBasicString("string value", p) value, ok = t.parseBasicString("string value", p)
case p.Peek(singleQuote3): case p.Peek(openingMultiLineLiteralString):
value, ok = t.parseMultiLineLiteralString(p) value, ok = t.parseMultiLineLiteralString(p)
case p.Peek(a.SingleQuote): case p.Peek(literalStringDelimiter):
value, ok = t.parseLiteralString("string value", p) value, ok = t.parseLiteralString("string value", p)
default: default:
p.Expected("a string value") p.Expected("a string value")
@ -113,7 +113,7 @@ func (t *parser) parseBasicString(name string, p *parse.API) (string, bool) {
case p.Peek(a.Backslash): case p.Peek(a.Backslash):
p.Error("invalid escape sequence") p.Error("invalid escape sequence")
return sb.String(), false return sb.String(), false
case p.Accept(closingDoubleQuote): case p.Accept(basicStringDelimiter):
return sb.String(), true return sb.String(), true
case p.Peek(a.InvalidRune): case p.Peek(a.InvalidRune):
p.Error("invalid UTF8 rune") p.Error("invalid UTF8 rune")
@ -142,7 +142,7 @@ func (t *parser) parseLiteralString(name string, p *parse.API) (string, bool) {
sb := &strings.Builder{} sb := &strings.Builder{}
for { for {
switch { switch {
case p.Accept(closingSingleQuote): case p.Accept(literalStringDelimiter):
return sb.String(), true return sb.String(), true
case p.Accept(a.Tab): case p.Accept(a.Tab):
sb.WriteString("\t") sb.WriteString("\t")