-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax.peg
25 lines (21 loc) · 1.31 KB
/
syntax.peg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
start := bindings=binding* $
_ := '\s*'
identifier := identifier='[A-Za-z]\w*'
identifier_variable := identifier='[a-z]\w*'
type_var_mono := identifier='[A-Z]\w*'
type_var_poly := identifier='[a-z]\w*'
type_var := type_var_mono | type_var_poly
type_function_type_head := type_var | '\(' _ type=type _ '\)'
function_type := param=type_function_type_head _ '->' _ exp=function_type | type_function_type_head
type := function_type | '\(' _ type=type _ '\)' | type_var
binding := _ name=identifier_variable _ '=' _ exp=expression _ '\.' _
expression := additive | '\(' _ exp=expression _ '\)'
additive := left=additive _ '\+' _ right=multiplicative | left=additive _ '-' _ right=multiplicative | multiplicative
multiplicative := left=multiplicative _ '\*' _ right=lambda_expression | left=multiplicative _ '/' _ right=lambda_expression | lambda_expression
lambda_expression := abstraction | application | identifier | num
abstraction := param=identifier_variable _ ':' _ paramT=type _ '\.' _ body=expression
application := head=application '\s+' arg=expression_argument | expression_head
expression_argument := '\(' _ exp=expression _ '\)' | identifier | num
expression_head := '\(' _ exp=expression _ '\)' | identifier
num := lexeme='((-?[1-9][0-9]*)|(0))(\.[0-9]+)?' _ '#' _ type=type_var
.value = number { return parseFloat(this.lexeme); }