diff --git a/pkg/yqlib/doc/operators/comment-operators.md b/pkg/yqlib/doc/operators/comment-operators.md index 9c5f4aef..9e3b61ec 100644 --- a/pkg/yqlib/doc/operators/comment-operators.md +++ b/pkg/yqlib/doc/operators/comment-operators.md @@ -23,7 +23,7 @@ a: cat ``` then ```bash -yq '.a lineComment="single"' sample.yml +yq '.a line_comment="single"' sample.yml ``` will output ```yaml @@ -38,7 +38,7 @@ b: dog ``` then ```bash -yq '.. lineComment |= .' sample.yml +yq '.. line_comment |= .' sample.yml ``` will output ```yaml @@ -53,7 +53,7 @@ a: cat ``` then ```bash -yq '. headComment="single"' sample.yml +yq '. head_comment="single"' sample.yml ``` will output ```yaml @@ -69,7 +69,7 @@ a: cat ``` then ```bash -yq '. footComment=.a' sample.yml +yq '. foot_comment=.a' sample.yml ``` will output ```yaml @@ -86,7 +86,7 @@ b: dog # leave this ``` then ```bash -yq '.a lineComment=""' sample.yml +yq '.a line_comment=""' sample.yml ``` will output ```yaml @@ -120,7 +120,7 @@ a: cat # meow ``` then ```bash -yq '.a | lineComment' sample.yml +yq '.a | line_comment' sample.yml ``` will output ```yaml @@ -138,7 +138,7 @@ a: cat # meow ``` then ```bash -yq '. | headComment' sample.yml +yq '. | head_comment' sample.yml ``` will output ```yaml @@ -157,7 +157,7 @@ a: cat # meow ``` then ```bash -yq 'headComment' sample.yml +yq 'head_comment' sample.yml ``` will output ```yaml @@ -177,7 +177,7 @@ a: cat # meow ``` then ```bash -yq '. | footComment' sample.yml +yq '. | foot_comment' sample.yml ``` will output ```yaml diff --git a/pkg/yqlib/doc/operators/document-index.md b/pkg/yqlib/doc/operators/document-index.md index 140d1d4d..ffb0936d 100644 --- a/pkg/yqlib/doc/operators/document-index.md +++ b/pkg/yqlib/doc/operators/document-index.md @@ -17,7 +17,7 @@ a: frog ``` then ```bash -yq '.a | documentIndex' sample.yml +yq '.a | document_index' sample.yml ``` will output ```yaml @@ -53,7 +53,7 @@ a: frog ``` then ```bash -yq 'select(documentIndex == 1)' sample.yml +yq 'select(document_index == 1)' sample.yml ``` will output ```yaml @@ -85,7 +85,7 @@ a: frog ``` then ```bash -yq '.a | ({"match": ., "doc": documentIndex})' sample.yml +yq '.a | ({"match": ., "doc": document_index})' sample.yml ``` will output ```yaml diff --git a/pkg/yqlib/doc/operators/file-operators.md b/pkg/yqlib/doc/operators/file-operators.md index d7988509..fdfb9e3d 100644 --- a/pkg/yqlib/doc/operators/file-operators.md +++ b/pkg/yqlib/doc/operators/file-operators.md @@ -37,7 +37,7 @@ a: cat ``` then ```bash -yq 'fileIndex' sample.yml +yq 'file_index' sample.yml ``` will output ```yaml @@ -55,7 +55,7 @@ a: cat ``` then ```bash -yq eval-all 'fileIndex' sample.yml another.yml +yq eval-all 'file_index' sample.yml another.yml ``` will output ```yaml diff --git a/pkg/yqlib/doc/operators/split-into-documents.md b/pkg/yqlib/doc/operators/split-into-documents.md index a9f70d30..a4f22f3d 100644 --- a/pkg/yqlib/doc/operators/split-into-documents.md +++ b/pkg/yqlib/doc/operators/split-into-documents.md @@ -11,7 +11,7 @@ Note that versions prior to 4.18 require the 'eval/e' command to be specified.&# ## Split empty Running ```bash -yq --null-input 'splitDoc' +yq --null-input 'split_doc' ``` will output ```yaml @@ -26,7 +26,7 @@ Given a sample.yml file of: ``` then ```bash -yq '.[] | splitDoc' sample.yml +yq '.[] | split_doc' sample.yml ``` will output ```yaml diff --git a/pkg/yqlib/expression_tokeniser.go b/pkg/yqlib/expression_tokeniser.go index 067f25e1..aae20761 100644 --- a/pkg/yqlib/expression_tokeniser.go +++ b/pkg/yqlib/expression_tokeniser.go @@ -393,8 +393,12 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte(`\/\/`), opToken(alternativeOpType)) lexer.Add([]byte(`documentIndex`), opToken(getDocumentIndexOpType)) + lexer.Add([]byte(`document_index`), opToken(getDocumentIndexOpType)) + lexer.Add([]byte(`di`), opToken(getDocumentIndexOpType)) + lexer.Add([]byte(`splitDoc`), opToken(splitDocumentOpType)) + lexer.Add([]byte(`split_doc`), opToken(splitDocumentOpType)) lexer.Add([]byte(`join`), opToken(joinStringOpType)) lexer.Add([]byte(`sub`), opToken(subStringOpType)) @@ -423,7 +427,10 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte(`anchor`), opAssignableToken(getAnchorOpType, assignAnchorOpType)) lexer.Add([]byte(`alias`), opAssignableToken(getAliasOptype, assignAliasOpType)) lexer.Add([]byte(`filename`), opToken(getFilenameOpType)) + lexer.Add([]byte(`fileIndex`), opToken(getFileIndexOpType)) + lexer.Add([]byte(`file_index`), opToken(getFileIndexOpType)) + lexer.Add([]byte(`fi`), opToken(getFileIndexOpType)) lexer.Add([]byte(`path`), opToken(getPathOpType)) lexer.Add([]byte(`to_entries`), opToken(toEntriesOpType)) @@ -433,10 +440,13 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte(`with`), opToken(withOpType)) lexer.Add([]byte(`lineComment`), opTokenWithPrefs(getCommentOpType, assignCommentOpType, commentOpPreferences{LineComment: true})) + lexer.Add([]byte(`line_comment`), opTokenWithPrefs(getCommentOpType, assignCommentOpType, commentOpPreferences{LineComment: true})) lexer.Add([]byte(`headComment`), opTokenWithPrefs(getCommentOpType, assignCommentOpType, commentOpPreferences{HeadComment: true})) + lexer.Add([]byte(`head_comment`), opTokenWithPrefs(getCommentOpType, assignCommentOpType, commentOpPreferences{HeadComment: true})) lexer.Add([]byte(`footComment`), opTokenWithPrefs(getCommentOpType, assignCommentOpType, commentOpPreferences{FootComment: true})) + lexer.Add([]byte(`foot_comment`), opTokenWithPrefs(getCommentOpType, assignCommentOpType, commentOpPreferences{FootComment: true})) lexer.Add([]byte(`comments\s*=`), assignAllCommentsOp(false)) lexer.Add([]byte(`comments\s*\|=`), assignAllCommentsOp(true)) @@ -519,7 +529,7 @@ func (p *expressionTokeniserImpl) Tokenise(expression string) ([]*token, error) scanner, err := p.lexer.Scanner([]byte(expression)) if err != nil { - return nil, fmt.Errorf("Parsing expression: %w", err) + return nil, fmt.Errorf("parsing expression: %w", err) } var tokens []*token for tok, err, eof := scanner.Next(); !eof; tok, err, eof = scanner.Next() { @@ -530,7 +540,7 @@ func (p *expressionTokeniserImpl) Tokenise(expression string) ([]*token, error) tokens = append(tokens, currentToken) } if err != nil { - return nil, fmt.Errorf("Parsing expression: %w", err) + return nil, fmt.Errorf("parsing expression: %w", err) } } var postProcessedTokens = make([]*token, 0) diff --git a/pkg/yqlib/operator_comments_test.go b/pkg/yqlib/operator_comments_test.go index 223eeb6c..d27b9efd 100644 --- a/pkg/yqlib/operator_comments_test.go +++ b/pkg/yqlib/operator_comments_test.go @@ -8,7 +8,7 @@ var commentOperatorScenarios = []expressionScenario{ { description: "Set line comment", document: `a: cat`, - expression: `.a lineComment="single"`, + expression: `.a line_comment="single"`, expected: []string{ "D0, P[], (doc)::a: cat # single\n", }, @@ -16,7 +16,7 @@ var commentOperatorScenarios = []expressionScenario{ { skipDoc: true, document: "a: cat\nb: dog", - expression: `.a lineComment=.b`, + expression: `.a line_comment=.b`, expected: []string{ "D0, P[], (doc)::a: cat # dog\nb: dog\n", }, @@ -24,7 +24,7 @@ var commentOperatorScenarios = []expressionScenario{ { skipDoc: true, document: "a: cat\n---\na: dog", - expression: `.a lineComment |= documentIndex`, + expression: `.a line_comment |= documentIndex`, expected: []string{ "D0, P[], (doc)::a: cat # 0\n", "D1, P[], (doc)::a: dog # 1\n", @@ -33,7 +33,7 @@ var commentOperatorScenarios = []expressionScenario{ { description: "Use update assign to perform relative updates", document: "a: cat\nb: dog", - expression: `.. lineComment |= .`, + expression: `.. line_comment |= .`, expected: []string{ "D0, P[], (!!map)::a: cat # cat\nb: dog # dog\n", }, @@ -49,7 +49,7 @@ var commentOperatorScenarios = []expressionScenario{ { description: "Set head comment", document: `a: cat`, - expression: `. headComment="single"`, + expression: `. head_comment="single"`, expected: []string{ "D0, P[], (doc)::# single\n\na: cat\n", }, @@ -57,7 +57,7 @@ var commentOperatorScenarios = []expressionScenario{ { description: "Set foot comment, using an expression", document: `a: cat`, - expression: `. footComment=.a`, + expression: `. foot_comment=.a`, expected: []string{ "D0, P[], (doc)::a: cat\n\n# cat\n", }, @@ -65,7 +65,7 @@ var commentOperatorScenarios = []expressionScenario{ { skipDoc: true, document: `a: cat`, - expression: `. footComment=.b.d`, + expression: `. foot_comment=.b.d`, expected: []string{ "D0, P[], (doc)::a: cat\n", }, @@ -73,7 +73,7 @@ var commentOperatorScenarios = []expressionScenario{ { skipDoc: true, document: `a: cat`, - expression: `. footComment|=.b.d`, + expression: `. foot_comment|=.b.d`, expected: []string{ "D0, P[], (doc)::a: cat\n", }, @@ -81,7 +81,7 @@ var commentOperatorScenarios = []expressionScenario{ { description: "Remove comment", document: "a: cat # comment\nb: dog # leave this", - expression: `.a lineComment=""`, + expression: `.a line_comment=""`, expected: []string{ "D0, P[], (doc)::a: cat\nb: dog # leave this\n", }, @@ -98,7 +98,7 @@ var commentOperatorScenarios = []expressionScenario{ { description: "Get line comment", document: "# welcome!\n\na: cat # meow\n\n# have a great day", - expression: `.a | lineComment`, + expression: `.a | line_comment`, expected: []string{ "D0, P[a], (!!str)::meow\n", }, @@ -107,7 +107,7 @@ var commentOperatorScenarios = []expressionScenario{ description: "Get head comment", dontFormatInputForDoc: true, document: "# welcome!\n\na: cat # meow\n\n# have a great day", - expression: `. | headComment`, + expression: `. | head_comment`, expected: []string{ "D0, P[], (!!str)::welcome!\n", }, @@ -116,7 +116,7 @@ var commentOperatorScenarios = []expressionScenario{ description: "Head comment with document split", dontFormatInputForDoc: true, document: "# welcome!\n---\n# bob\na: cat # meow\n\n# have a great day", - expression: `headComment`, + expression: `head_comment`, expected: []string{ "D0, P[], (!!str)::welcome!\nbob\n", }, @@ -125,7 +125,7 @@ var commentOperatorScenarios = []expressionScenario{ description: "Get foot comment", dontFormatInputForDoc: true, document: "# welcome!\n\na: cat # meow\n\n# have a great day\n# no really", - expression: `. | footComment`, + expression: `. | foot_comment`, expected: []string{ "D0, P[], (!!str)::have a great day\nno really\n", }, diff --git a/pkg/yqlib/operator_document_index_test.go b/pkg/yqlib/operator_document_index_test.go index 23195505..e0d82686 100644 --- a/pkg/yqlib/operator_document_index_test.go +++ b/pkg/yqlib/operator_document_index_test.go @@ -8,7 +8,7 @@ var documentIndexScenarios = []expressionScenario{ { description: "Retrieve a document index", document: "a: cat\n---\na: frog\n", - expression: `.a | documentIndex`, + expression: `.a | document_index`, expected: []string{ "D0, P[a], (!!int)::0\n", "D1, P[a], (!!int)::1\n", @@ -26,7 +26,7 @@ var documentIndexScenarios = []expressionScenario{ { description: "Filter by document index", document: "a: cat\n---\na: frog\n", - expression: `select(documentIndex == 1)`, + expression: `select(document_index == 1)`, expected: []string{ "D1, P[], (doc)::a: frog\n", }, @@ -42,7 +42,7 @@ var documentIndexScenarios = []expressionScenario{ { description: "Print Document Index with matches", document: "a: cat\n---\na: frog\n", - expression: `.a | ({"match": ., "doc": documentIndex})`, + expression: `.a | ({"match": ., "doc": document_index})`, expected: []string{ "D0, P[], (!!map)::match: cat\ndoc: 0\n", "D0, P[], (!!map)::match: frog\ndoc: 1\n", diff --git a/pkg/yqlib/operator_file_test.go b/pkg/yqlib/operator_file_test.go index 875d4187..3ad72248 100644 --- a/pkg/yqlib/operator_file_test.go +++ b/pkg/yqlib/operator_file_test.go @@ -16,7 +16,7 @@ var fileOperatorScenarios = []expressionScenario{ { description: "Get file index", document: `{a: cat}`, - expression: `fileIndex`, + expression: `file_index`, expected: []string{ "D0, P[], (!!int)::0\n", }, @@ -25,7 +25,7 @@ var fileOperatorScenarios = []expressionScenario{ description: "Get file indices of multiple documents", document: `{a: cat}`, document2: `{a: cat}`, - expression: `fileIndex`, + expression: `file_index`, expected: []string{ "D0, P[], (!!int)::0\n", "D0, P[], (!!int)::1\n", diff --git a/pkg/yqlib/operator_split_document_test.go b/pkg/yqlib/operator_split_document_test.go index ca490512..a2c4f906 100644 --- a/pkg/yqlib/operator_split_document_test.go +++ b/pkg/yqlib/operator_split_document_test.go @@ -8,7 +8,7 @@ var splitDocOperatorScenarios = []expressionScenario{ { description: "Split empty", document: ``, - expression: `splitDoc`, + expression: `split_doc`, expected: []string{ "D0, P[], (!!null)::\n", }, @@ -16,7 +16,7 @@ var splitDocOperatorScenarios = []expressionScenario{ { description: "Split array", document: `[{a: cat}, {b: dog}]`, - expression: `.[] | splitDoc`, + expression: `.[] | split_doc`, expected: []string{ "D0, P[0], (!!map)::{a: cat}\n", "D1, P[1], (!!map)::{b: dog}\n",