From 2292f0ffb4586933ea7ce0bcbf7984bcbe191b8a Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Wed, 15 Sep 2021 22:24:03 +1000 Subject: [PATCH] Fixed with semicolon space issue --- pkg/yqlib/doc/With.md | 6 +++--- pkg/yqlib/expression_processing_test.go | 5 +++++ pkg/yqlib/expression_tokeniser.go | 2 +- pkg/yqlib/operator_with_test.go | 6 +++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/yqlib/doc/With.md b/pkg/yqlib/doc/With.md index a694c5cd..c5bbce4b 100644 --- a/pkg/yqlib/doc/With.md +++ b/pkg/yqlib/doc/With.md @@ -9,7 +9,7 @@ a: ``` then ```bash -yq eval 'with(.a.deeply.nested ; . = "newValue" | . style="single")' sample.yml +yq eval 'with(.a.deeply.nested; . = "newValue" | . style="single")' sample.yml ``` will output ```yaml @@ -28,7 +28,7 @@ a: ``` then ```bash -yq eval 'with(.a.deeply ; .nested = "newValue" | .other= "newThing")' sample.yml +yq eval 'with(.a.deeply; .nested = "newValue" | .other= "newThing")' sample.yml ``` will output ```yaml @@ -47,7 +47,7 @@ myArray: ``` then ```bash -yq eval 'with(.myArray[] ; .b = .a + " yum")' sample.yml +yq eval 'with(.myArray[]; .b = .a + " yum")' sample.yml ``` will output ```yaml diff --git a/pkg/yqlib/expression_processing_test.go b/pkg/yqlib/expression_processing_test.go index 3c4d510d..b170de00 100644 --- a/pkg/yqlib/expression_processing_test.go +++ b/pkg/yqlib/expression_processing_test.go @@ -15,6 +15,11 @@ var pathTests = []struct { expectedTokens []interface{} expectedPostFix []interface{} }{ + { + "with(.a;.=3)", + append(make([]interface{}, 0), "WITH", "(", "a", "BLOCK", "SELF", "ASSIGN", "3 (int64)", ")"), + append(make([]interface{}, 0), "a", "SELF", "3 (int64)", "ASSIGN", "BLOCK", "WITH"), + }, { "0x12", append(make([]interface{}, 0), "18 (int64)"), diff --git a/pkg/yqlib/expression_tokeniser.go b/pkg/yqlib/expression_tokeniser.go index c2426097..1b23a08d 100644 --- a/pkg/yqlib/expression_tokeniser.go +++ b/pkg/yqlib/expression_tokeniser.go @@ -340,7 +340,7 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte("( |\t|\n|\r)+"), skip) lexer.Add([]byte(`\."[^ "]+"\??`), pathToken(true)) - lexer.Add([]byte(`\.[^ \}\{\:\[\],\|\.\[\(\)=\n]+\??`), pathToken(false)) + lexer.Add([]byte(`\.[^ ;\}\{\:\[\],\|\.\[\(\)=\n]+\??`), pathToken(false)) lexer.Add([]byte(`\.`), selfToken()) lexer.Add([]byte(`\|`), opToken(pipeOpType)) diff --git a/pkg/yqlib/operator_with_test.go b/pkg/yqlib/operator_with_test.go index 06e7f89c..6ade5399 100644 --- a/pkg/yqlib/operator_with_test.go +++ b/pkg/yqlib/operator_with_test.go @@ -6,7 +6,7 @@ var withOperatorScenarios = []expressionScenario{ { description: "Update and style", document: `a: {deeply: {nested: value}}`, - expression: `with(.a.deeply.nested ; . = "newValue" | . style="single")`, + expression: `with(.a.deeply.nested; . = "newValue" | . style="single")`, expected: []string{ "D0, P[], (doc)::a: {deeply: {nested: 'newValue'}}\n", }, @@ -14,7 +14,7 @@ var withOperatorScenarios = []expressionScenario{ { description: "Update multiple deeply nested properties", document: `a: {deeply: {nested: value, other: thing}}`, - expression: `with(.a.deeply ; .nested = "newValue" | .other= "newThing")`, + expression: `with(.a.deeply; .nested = "newValue" | .other= "newThing")`, expected: []string{ "D0, P[], (doc)::a: {deeply: {nested: newValue, other: newThing}}\n", }, @@ -22,7 +22,7 @@ var withOperatorScenarios = []expressionScenario{ { description: "Update array elements relatively", document: `myArray: [{a: apple},{a: banana}]`, - expression: `with(.myArray[] ; .b = .a + " yum")`, + expression: `with(.myArray[]; .b = .a + " yum")`, expected: []string{ "D0, P[], (doc)::myArray: [{a: apple, b: apple yum}, {a: banana, b: banana yum}]\n", },