-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// @flow | ||
|
||
import functionCallLambda from '../functionCallLambda' | ||
|
||
describe('functionCallLambda generator', () => { | ||
it('generates correct code', () => { | ||
const fakeGenerator = ( | ||
{ type } // eslint-disable-line flowtype/require-parameter-type | ||
): string => '[]' | ||
expect( | ||
functionCallLambda(fakeGenerator)({ | ||
type: 'functionCallLambda', | ||
value: { | ||
left: { | ||
type: 'identifier', | ||
value: 'foo' | ||
}, | ||
right: { | ||
type: 'list', | ||
value: [] | ||
} | ||
} | ||
}) | ||
).toEqual('_.foo(function(input) {return []})(input)') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// @flow | ||
|
||
import type { | ||
FunctionCallLambdaNodeType, | ||
GeneratedCodeType, | ||
NodeType | ||
} from '../types' | ||
|
||
export default ( | ||
Generator: NodeType => GeneratedCodeType | ||
): (FunctionCallLambdaNodeType => GeneratedCodeType) => ({ | ||
value | ||
}: FunctionCallLambdaNodeType): GeneratedCodeType => | ||
`_.${value.left.value}(function(input) {return ${Generator( | ||
value.right | ||
)}})(input)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import parser from '../functionCallLambda' | ||
|
||
describe('functionCallLambda parser', () => { | ||
it('parses map \\"foo"', () => { | ||
expect(parser.parse('map \\"foo"').status).toBe(true) | ||
}) | ||
|
||
it('returns correct value', () => { | ||
expect(parser.parse('map \\["a", "b"]').value).toEqual({ | ||
type: 'functionCallLambda', | ||
value: { | ||
left: { | ||
type: 'identifier', | ||
value: 'map' | ||
}, | ||
right: { | ||
type: 'list', | ||
value: [ | ||
{ | ||
type: 'primitive', | ||
value: '"a"' | ||
}, | ||
{ | ||
type: 'primitive', | ||
value: '"b"' | ||
} | ||
] | ||
} | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// @flow | ||
|
||
import Parsimmon from 'parsimmon' | ||
|
||
import type { | ||
FunctionCallLambdaNodeType, | ||
NodeType, | ||
IdentifierNodeType | ||
} from '../types' | ||
|
||
const FunctionCallLambdaParser = Parsimmon.lazy((): mixed => { | ||
const ProgramParser = require('./program').default | ||
const IdentifierParser = require('./identifier').default | ||
return Parsimmon.seq( | ||
IdentifierParser, | ||
Parsimmon.optWhitespace, | ||
Parsimmon.string('\\'), | ||
Parsimmon.optWhitespace, | ||
ProgramParser | ||
).map( | ||
([left, _, __, ___, right]: [ | ||
IdentifierNodeType, | ||
mixed, | ||
mixed, | ||
mixed, | ||
NodeType | ||
]): FunctionCallLambdaNodeType => ({ | ||
type: 'functionCallLambda', | ||
value: { | ||
left, | ||
right | ||
} | ||
}) | ||
) | ||
}) | ||
|
||
export default FunctionCallLambdaParser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters