diff --git a/docs/index.md b/docs/index.md index cf488843..86a04e8d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -62,7 +62,6 @@ returned. In any other case, a list of each requested element is returned. - ### Functions #### `join` @@ -90,19 +89,19 @@ separator. Input: ``` -["Hello", "World!"] | map \{"word": $} +["Hello", "World!"] | map $ => {"word": $} ``` Output: ```json -[ - { "word": "Hello"}, - { "word": "World!"}, -] +[{"word": "Hello"}, {"word": "World!"}] ``` +Alternatively, you can also use this syntax: `["Hello", "World!"] | map \ {"word": $}` + ### Chaining filters + You can combine two filters by using the pipe syntax, e. q. `.foo | .bar` The first filter (`.foo`) will receive the input and transform it; the second diff --git a/src/parsers/__tests__/functionCallLambda.test.js b/src/parsers/__tests__/functionCallLambda.test.js index 83c43060..c97bf38e 100644 --- a/src/parsers/__tests__/functionCallLambda.test.js +++ b/src/parsers/__tests__/functionCallLambda.test.js @@ -4,6 +4,21 @@ describe('functionCallLambda parser', () => { it('parses map \\"foo"', () => { expect(parser.parse('map \\"foo"').status).toBe(true) }) + it('parses map \\ "foo"', () => { + expect(parser.parse('map \\ "foo"').status).toBe(true) + }) + + it('parses map $ => "foo"', () => { + expect(parser.parse('map $ => "foo"').status).toBe(true) + }) + + it('parses map $ =>"foo"', () => { + expect(parser.parse('map $ =>"foo"').status).toBe(true) + }) + + it('parses map $=>"foo"', () => { + expect(parser.parse('map $=>"foo"').status).toBe(true) + }) it('returns correct value', () => { expect(parser.parse('map \\["a", "b"]').value).toEqual({ diff --git a/src/parsers/functionCallLambda.js b/src/parsers/functionCallLambda.js index c9cbc43d..29fd078f 100644 --- a/src/parsers/functionCallLambda.js +++ b/src/parsers/functionCallLambda.js @@ -14,7 +14,7 @@ const FunctionCallLambdaParser = Parsimmon.lazy((): mixed => { return Parsimmon.seq( IdentifierParser, Parsimmon.optWhitespace, - Parsimmon.string('\\'), + Parsimmon.alt(Parsimmon.regexp(/\$\s*=>\s*/), Parsimmon.string('\\')), Parsimmon.optWhitespace, ProgramParser ).map(