diff --git a/parsing.go b/parsing.go index fd74ffa..abc0451 100644 --- a/parsing.go +++ b/parsing.go @@ -105,7 +105,7 @@ func readToken(stream *lexerStream, state lexerState) (ExpressionToken, error, b tokenValue, completed = readUntilFalse(stream, true, false, isNotClosingBracket) kind = VARIABLE - if(!completed) { + if !completed { return ExpressionToken{}, errors.New("Unclosed parameter bracket"), false } @@ -138,7 +138,7 @@ func readToken(stream *lexerStream, state lexerState) (ExpressionToken, error, b if !isNotQuote(character) { tokenValue, completed = readUntilFalse(stream, true, false, isNotQuote) - if(!completed) { + if !completed { return ExpressionToken{}, errors.New("Unclosed string literal"), false } @@ -239,7 +239,7 @@ func readUntilFalse(stream *lexerStream, includeWhitespace bool, breakWhitespace character = stream.readCharacter() // Use backslashes to escape anything - if(character == '\\') { + if character == '\\' { character = stream.readCharacter() tokenBuffer.WriteString(string(character)) diff --git a/parsingFailure_test.go b/parsingFailure_test.go index 6781566..7837ef6 100644 --- a/parsingFailure_test.go +++ b/parsingFailure_test.go @@ -9,8 +9,8 @@ const ( UNEXPECTED_END string = "Unexpected end of expression" INVALID_TOKEN_TRANSITION = "Cannot transition token types" INVALID_TOKEN_KIND = "Invalid token" - UNCLOSED_QUOTES = "Unclosed string literal" - UNCLOSED_BRACKETS = "Unclosed parameter bracket" + UNCLOSED_QUOTES = "Unclosed string literal" + UNCLOSED_BRACKETS = "Unclosed parameter bracket" ) /* diff --git a/parsing_test.go b/parsing_test.go index 28ef7bb..66c9b47 100644 --- a/parsing_test.go +++ b/parsing_test.go @@ -456,34 +456,34 @@ func TestPrefixParsing(test *testing.T) { testCases := []TokenParsingTest{ - TokenParsingTest { + TokenParsingTest{ - Name: "Sign prefix", + Name: "Sign prefix", Input: "-1", - Expected: []ExpressionToken { - ExpressionToken { - Kind: PREFIX, - Value: "-", - }, - ExpressionToken { - Kind: NUMERIC, - Value: 1.0, - }, + Expected: []ExpressionToken{ + ExpressionToken{ + Kind: PREFIX, + Value: "-", + }, + ExpressionToken{ + Kind: NUMERIC, + Value: 1.0, + }, }, }, - TokenParsingTest { + TokenParsingTest{ - Name: "Sign prefix on variable", + Name: "Sign prefix on variable", Input: "-foo", - Expected: []ExpressionToken { - ExpressionToken { - Kind: PREFIX, - Value: "-", - }, - ExpressionToken { - Kind: VARIABLE, - Value: "foo", - }, + Expected: []ExpressionToken{ + ExpressionToken{ + Kind: PREFIX, + Value: "-", + }, + ExpressionToken{ + Kind: VARIABLE, + Value: "foo", + }, }, }, TokenParsingTest{ @@ -524,82 +524,82 @@ func TestPrefixParsing(test *testing.T) { func TestEscapedParameters(test *testing.T) { - testCases := []TokenParsingTest{ - - TokenParsingTest { - - Name: "Single escaped parameter", - Input: "[foo]", - Expected: []ExpressionToken { - ExpressionToken { - Kind: VARIABLE, - Value: "foo", - }, - }, - }, - TokenParsingTest { - - Name: "Single escaped parameter with whitespace", - Input: "[foo bar]", - Expected: []ExpressionToken { - ExpressionToken { - Kind: VARIABLE, - Value: "foo bar", - }, - }, - }, - TokenParsingTest { - - Name: "Single escaped parameter with escaped closing bracket", - Input: "[foo[bar\\]]", - Expected: []ExpressionToken { - ExpressionToken { - Kind: VARIABLE, - Value: "foo[bar]", - }, - }, - }, - TokenParsingTest { - - Name: "Escaped parameters and unescaped parameters", - Input: "[foo] > bar", - Expected: []ExpressionToken { - ExpressionToken { - Kind: VARIABLE, - Value: "foo", - }, - ExpressionToken{ - Kind: COMPARATOR, - Value: ">", - }, - ExpressionToken{ - Kind: VARIABLE, - Value: "bar", - }, - }, - }, - TokenParsingTest { - - Name: "Unescaped parameter with space", - Input: "foo\\ bar > bar", - Expected: []ExpressionToken { - ExpressionToken { - Kind: VARIABLE, - Value: "foo bar", - }, - ExpressionToken{ - Kind: COMPARATOR, - Value: ">", - }, - ExpressionToken{ - Kind: VARIABLE, - Value: "bar", - }, + testCases := []TokenParsingTest{ + + TokenParsingTest{ + + Name: "Single escaped parameter", + Input: "[foo]", + Expected: []ExpressionToken{ + ExpressionToken{ + Kind: VARIABLE, + Value: "foo", }, }, - } + }, + TokenParsingTest{ + + Name: "Single escaped parameter with whitespace", + Input: "[foo bar]", + Expected: []ExpressionToken{ + ExpressionToken{ + Kind: VARIABLE, + Value: "foo bar", + }, + }, + }, + TokenParsingTest{ - runTokenParsingTest(testCases, test) + Name: "Single escaped parameter with escaped closing bracket", + Input: "[foo[bar\\]]", + Expected: []ExpressionToken{ + ExpressionToken{ + Kind: VARIABLE, + Value: "foo[bar]", + }, + }, + }, + TokenParsingTest{ + + Name: "Escaped parameters and unescaped parameters", + Input: "[foo] > bar", + Expected: []ExpressionToken{ + ExpressionToken{ + Kind: VARIABLE, + Value: "foo", + }, + ExpressionToken{ + Kind: COMPARATOR, + Value: ">", + }, + ExpressionToken{ + Kind: VARIABLE, + Value: "bar", + }, + }, + }, + TokenParsingTest{ + + Name: "Unescaped parameter with space", + Input: "foo\\ bar > bar", + Expected: []ExpressionToken{ + ExpressionToken{ + Kind: VARIABLE, + Value: "foo bar", + }, + ExpressionToken{ + Kind: COMPARATOR, + Value: ">", + }, + ExpressionToken{ + Kind: VARIABLE, + Value: "bar", + }, + }, + }, + } + + runTokenParsingTest(testCases, test) } func combineWhitespaceExpressions(testCases []TokenParsingTest) []TokenParsingTest {