-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexpression.ts
24 lines (19 loc) · 1.03 KB
/
expression.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
* Copyright (c) 2017 MolQL contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <[email protected]>
*/
type Expression =
| Expression.Literal
| Expression.Apply
namespace Expression {
export type Literal = string | number | boolean
export type Arguments = Expression[] | { [name: string]: Expression }
export interface Apply { readonly head: Expression, readonly args?: Arguments }
export function Apply(head: Expression, args?: Arguments): Apply { return args ? { head, args } : { head }; }
export function isArgumentsArray(e: Arguments): e is Expression[] { return e instanceof Array; }
export function isArgumentsMap(e: Arguments): e is { [name: string]: Expression } { return !(e instanceof Array); }
export function isLiteral(e: Expression): e is Expression.Literal { return !isApply(e); }
export function isApply(e: Expression): e is Expression.Apply { return !! e && !!(e as Expression.Apply).head && typeof e === 'object'; }
}
export default Expression