Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ data representation implied by the fact that a value is an atom (e.g. the atom
`2` may be an integer in memory).

Bare words not containing any
[reserved character sequences](./src/language/parsing/atom.ts#L33-L57) are
[reserved character sequences](./src/language/parsing/atom.ts#L33-L55) are
atoms:

```
Expand Down
14 changes: 8 additions & 6 deletions examples/lookup-environment-variable.plz
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{@runtime, context =>
:flow({
:context.arguments.lookup
:flow(
:match({
none: {}
some: :flow({
:context.environment.lookup
some: :flow(
:match({
none: {}
some: :identity
})
})
)(
:context.environment.lookup
)
})
})(variable)
)(
:context.arguments.lookup
)(variable)
}
51 changes: 15 additions & 36 deletions src/end-to-end.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ testCases(endToEnd, code => code)('end-to-end tests', [
],
[':match({ a: A })({ tag: a, value: {} })', either.makeRight('A')],
[':atom.prepend(a)(b)', either.makeRight('ab')],
[':flow({ :atom.append(a), :atom.append(b) })(z)', either.makeRight('zab')],
[':flow(:atom.append(b))(:atom.append(a))(z)', either.makeRight('zab')],
[
`{
// foo: bar
Expand All @@ -159,42 +159,21 @@ testCases(endToEnd, code => code)('end-to-end tests', [
either.makeRight({ tag: 'none', value: {} }),
],
[
`{@runtime, {@apply, :flow, {
{@apply, :object.lookup, environment}
{@apply, :match, {
none: "environment does not exist"
some: {@apply, :flow, {
{@apply, :object.lookup, lookup}
{@apply, :match, {
none: "environment.lookup does not exist"
some: {@apply, :apply, PATH}
}}
}}
}}
}}}`,
output => {
if (either.isLeft(output)) {
assert.fail(output.value.message)
}
assert(typeof output.value === 'object')
assert.deepEqual(output.value['tag'], 'some')
assert.deepEqual(typeof output.value['value'], 'string')
},
],
[
`{@runtime, :flow({
:object.lookup(environment)
:match({
none: "environment does not exist"
some: :flow({
:object.lookup(lookup)
:match({
none: "environment.lookup does not exist"
some: :apply(PATH)
})
`{@runtime, :flow(
:match({
none: "environment does not exist"
some: :flow(
:match({
none: "environment.lookup does not exist"
some: :apply(PATH)
})
)(
:object.lookup(lookup)
)
})
})
})}`,
)(
:object.lookup(environment)
)}`,
output => {
if (either.isLeft(output)) {
assert.fail(output.value.message)
Expand Down
61 changes: 8 additions & 53 deletions src/language/compiling/compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,18 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
{
true1: ['@check', true, ['@lookup', 'identity']],
true2: ['@apply', ['@index', ['@lookup', 'boolean'], ['not']], false],
true3: [
'@apply',
[
'@apply',
['@lookup', 'flow'],
[
['@index', ['@lookup', 'boolean'], ['not']],
['@index', ['@lookup', 'boolean'], ['not']],
],
],
true,
],
false1: ['@check', false, ['@index', ['@lookup', 'boolean'], ['is']]],
false2: [
'@apply',
['@index', ['@lookup', 'boolean'], ['is']],
'not a boolean',
],
false3: [
'@apply',
[
'@apply',
['@lookup', 'flow'],
[
[
'@apply',
['@lookup', 'flow'],
[
['@index', ['@lookup', 'boolean'], ['not']],
['@index', ['@lookup', 'boolean'], ['not']],
],
],
['@index', ['@lookup', 'boolean'], ['not']],
],
],
true,
],
},
success({
true1: 'true',
true2: 'true',
true3: 'true',
false1: 'false',
false2: 'false',
false3: 'false',
}),
],
[
Expand Down Expand Up @@ -116,37 +83,25 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
'@runtime',
[
'@apply',
['@lookup', 'flow'],
[
['@lookup', 'identity'],
['@lookup', 'identity'],
],
['@apply', ['@lookup', 'flow'], ['@lookup', 'identity']],
['@lookup', 'identity'],
],
],
success({
0: '@runtime',
function: {
0: '@apply',
function: { 0: '@lookup', key: 'flow' },
argument: {
0: { 0: '@lookup', key: 'identity' },
1: { 0: '@lookup', key: 'identity' },
function: {
0: '@apply',
function: { 0: '@lookup', key: 'flow' },
argument: { 0: '@lookup', key: 'identity' },
},
argument: { 0: '@lookup', key: 'identity' },
},
}),
],
[
[
'@runtime',
[
'@apply',
['@lookup', 'flow'],
[
['@index', ['@lookup', 'boolean'], ['not']],
['@index', ['@lookup', 'boolean'], ['not']],
],
],
],
['@runtime', ['@index', ['@lookup', 'boolean'], ['not']]],
output => {
assert(either.isLeft(output))
assert(output.value.kind === 'typeMismatch')
Expand Down
8 changes: 3 additions & 5 deletions src/language/parsing/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ const atomComponentsRequiringQuotation = [
singleLineCommentDelimiter,
whitespace,

// Reserved to allow symbols like `=>` to not be conflated with atoms:
literal('='),

// Reserved for future use:
literal('['),
literal(']'),
literal('<'),
literal('>'),
literal('#'),
literal('&'),
literal('|'),
literal('='),
literal(';'),
] as const

Expand Down
50 changes: 0 additions & 50 deletions src/language/runtime/evaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,6 @@ testCases(evaluate, input => `evaluating \`${JSON.stringify(input)}\``)(
[
['Hello, world!', success('Hello, world!')],
[['@check', true, ['@lookup', 'identity']], success('true')],
[
[
'@runtime',
[
'@apply',
['@lookup', 'flow'],
[
[
'@apply',
['@index', ['@lookup', 'object'], ['lookup']],
'environment',
],
[
'@apply',
['@lookup', 'match'],
{
none: 'environment does not exist!',
some: [
'@apply',
['@lookup', 'flow'],
[
[
'@apply',
['@index', ['@lookup', 'object'], ['lookup']],
'lookup',
],
[
'@apply',
['@lookup', 'match'],
{
none: 'environment.lookup does not exist!',
some: ['@apply', ['@lookup', 'apply'], 'PATH'],
},
],
],
],
},
],
],
],
],
output => {
if (either.isLeft(output)) {
assert.fail(output.value.message)
}
assert(typeof output.value === 'object')
assert(output.value['tag'] === 'some')
assert(typeof output.value['value'] === 'string')
},
],
[
['@check', 'not a boolean', ['@index', ['@lookup', 'boolean'], 'is']],
output => assert(either.isLeft(output)),
Expand Down
8 changes: 8 additions & 0 deletions src/language/semantics/prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ export const prelude = makeObjectNode({
integer: makeObjectNode(integer),
atom: makeObjectNode(atom),
object: makeObjectNode(object),

// Aliases:
'>>': globalFunctions.flow,
'|>': globalFunctions.identity,
'+': integer.add,
'-': integer.subtract,
'<': integer.less_than,
'>': integer.greater_than,
})
Loading