2020-04-30 14:39:51 +04:00
|
|
|
let sepBy1 = (sep, rule) =>
|
|
|
|
seq(
|
|
|
|
rule,
|
|
|
|
repeat(seq(sep, rule)),
|
|
|
|
optional(sep)
|
|
|
|
)
|
|
|
|
|
|
|
|
let sepBy = (sep, rule) => optional(sepBy1(sep, rule))
|
|
|
|
|
|
|
|
let op = (name, left, right, term) =>
|
|
|
|
choice(
|
|
|
|
seq(left, name, right),
|
|
|
|
term,
|
|
|
|
)
|
|
|
|
|
|
|
|
let right_op = (name, left, right) => op(name, left, right, right)
|
|
|
|
let left_op = (name, left, right) => op(name, left, right, left)
|
|
|
|
|
|
|
|
let par = x => seq('(', x, ')')
|
|
|
|
let brackets = x => seq('[', x, ']')
|
|
|
|
|
|
|
|
let ne_injection = (Kind, element) =>
|
|
|
|
choice(
|
|
|
|
seq(
|
|
|
|
Kind,
|
|
|
|
sepBy1(';', element),
|
|
|
|
'end',
|
|
|
|
),
|
|
|
|
seq(
|
|
|
|
Kind,
|
|
|
|
'[',
|
|
|
|
sepBy1(';', element),
|
|
|
|
']',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
let injection = (Kind, element) =>
|
|
|
|
choice(
|
|
|
|
seq(
|
|
|
|
Kind,
|
|
|
|
sepBy(';', element),
|
|
|
|
'end',
|
|
|
|
),
|
|
|
|
seq(
|
|
|
|
Kind,
|
|
|
|
'[',
|
|
|
|
sepBy(';', element),
|
|
|
|
']',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
module.exports = grammar({
|
|
|
|
name: 'PascaLigo',
|
|
|
|
|
|
|
|
word: $ => $.Keyword,
|
|
|
|
extras: $ => [$.ocaml_comment, $.comment, /\s/],
|
|
|
|
|
|
|
|
rules: {
|
2020-07-20 01:04:01 +04:00
|
|
|
Start: $ => sepBy(optional(';'), field("declaration", $._declaration)),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
_declaration: $ =>
|
|
|
|
choice(
|
|
|
|
$.type_decl,
|
|
|
|
$.const_decl,
|
|
|
|
$.fun_decl,
|
|
|
|
$.attr_decl,
|
|
|
|
$.include,
|
|
|
|
),
|
|
|
|
|
|
|
|
attr_decl: $ =>
|
|
|
|
injection("attributes",
|
2020-05-01 22:10:10 +04:00
|
|
|
field("attribute", $.String)
|
|
|
|
),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
type_decl: $ =>
|
|
|
|
seq(
|
|
|
|
"type",
|
2020-07-08 20:31:42 +04:00
|
|
|
field("typeName", $.TypeName),
|
2020-04-30 14:39:51 +04:00
|
|
|
"is",
|
|
|
|
field("typeValue", $._type_expr),
|
|
|
|
),
|
|
|
|
|
|
|
|
_type_expr: $ =>
|
|
|
|
choice(
|
2020-07-20 01:04:01 +04:00
|
|
|
$._fun_type,
|
2020-04-30 14:39:51 +04:00
|
|
|
$.sum_type,
|
|
|
|
$.record_type,
|
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_fun_type: $ =>
|
2020-04-30 14:39:51 +04:00
|
|
|
choice(
|
2020-07-20 01:04:01 +04:00
|
|
|
$.fun_type,
|
|
|
|
$.cartesian
|
|
|
|
),
|
|
|
|
|
|
|
|
fun_type: $ =>
|
|
|
|
seq(
|
2020-04-30 14:39:51 +04:00
|
|
|
field("domain", $.cartesian),
|
2020-07-20 01:04:01 +04:00
|
|
|
'->',
|
|
|
|
field("codomain", $._fun_type),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
cartesian: $ =>
|
2020-05-08 00:09:14 +04:00
|
|
|
sepBy1('*',
|
|
|
|
choice(
|
|
|
|
field("element", $._core_type),
|
2020-07-20 01:04:01 +04:00
|
|
|
par(field("element", $._type_expr)),
|
2020-05-08 00:09:14 +04:00
|
|
|
),
|
|
|
|
),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
_core_type: $ =>
|
|
|
|
choice(
|
2020-07-08 20:31:42 +04:00
|
|
|
$.TypeName,
|
2020-04-30 14:39:51 +04:00
|
|
|
$.invokeBinary,
|
|
|
|
$.invokeUnary,
|
2020-07-20 01:04:01 +04:00
|
|
|
$.michelsonTypeOr,
|
|
|
|
$.michelsonTypeAnd,
|
|
|
|
),
|
|
|
|
|
|
|
|
michelsonTypeOr: $ =>
|
|
|
|
seq(
|
|
|
|
"michelson_or",
|
|
|
|
"(",
|
|
|
|
field("left_type", $._type_expr),
|
|
|
|
",",
|
|
|
|
field("left_type_name", $.String),
|
|
|
|
",",
|
|
|
|
field("right_type", $._type_expr),
|
|
|
|
",",
|
|
|
|
field("right_type_name", $.String),
|
|
|
|
")",
|
|
|
|
),
|
|
|
|
|
|
|
|
michelsonTypeAnd: $ =>
|
|
|
|
seq(
|
|
|
|
"michelson_pair",
|
|
|
|
"(",
|
|
|
|
field("left_type", $._type_expr),
|
|
|
|
",",
|
|
|
|
field("left_type_name", $.String),
|
|
|
|
",",
|
|
|
|
field("right_type", $._type_expr),
|
|
|
|
",",
|
|
|
|
field("right_type_name", $.String),
|
|
|
|
")",
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
invokeBinary: $ =>
|
|
|
|
seq(
|
2020-07-20 01:04:01 +04:00
|
|
|
field("typeConstr", choice('map', 'big_map')),
|
2020-04-30 14:39:51 +04:00
|
|
|
field("arguments", $.type_tuple),
|
|
|
|
),
|
|
|
|
|
|
|
|
invokeUnary: $ =>
|
|
|
|
seq(
|
2020-07-20 01:04:01 +04:00
|
|
|
field("typeConstr", choice('list', 'set', 'option', 'contract')),
|
2020-05-06 22:45:33 +04:00
|
|
|
par(field("arguments", $._type_expr)),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
map: $ => 'map',
|
|
|
|
big_map: $ => 'big_map',
|
|
|
|
list: $ => 'list',
|
|
|
|
set: $ => 'set',
|
|
|
|
|
|
|
|
type_tuple: $ => par(sepBy1(',', field("element", $._type_expr))),
|
|
|
|
|
|
|
|
sum_type: $ =>
|
|
|
|
seq(
|
|
|
|
optional('|'),
|
|
|
|
sepBy1('|', field("variant", $.variant)),
|
|
|
|
),
|
|
|
|
|
|
|
|
variant: $ =>
|
|
|
|
choice(
|
|
|
|
field("constructor", $.constr),
|
|
|
|
seq(
|
|
|
|
field("constructor", $.constr),
|
|
|
|
'of',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("arguments", $._fun_type)
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
constr: $ => $.Name_Capital,
|
|
|
|
|
|
|
|
record_type: $ =>
|
|
|
|
choice(
|
|
|
|
seq('record', sepBy(';', field("field", $.field_decl)), 'end'),
|
|
|
|
seq('record', '[', sepBy(';', field("field", $.field_decl)), ']'),
|
|
|
|
),
|
|
|
|
|
|
|
|
field_decl: $ =>
|
|
|
|
seq(
|
2020-07-08 20:31:42 +04:00
|
|
|
field("fieldName", $.FieldName),
|
2020-04-30 14:39:51 +04:00
|
|
|
':',
|
|
|
|
field("fieldType", $._type_expr),
|
|
|
|
),
|
|
|
|
|
|
|
|
fun_expr: $ =>
|
|
|
|
seq(
|
|
|
|
field("recursive", optional($.recursive)),
|
|
|
|
'function',
|
|
|
|
field("parameters", $.parameters),
|
|
|
|
':',
|
|
|
|
field("type", $._type_expr),
|
|
|
|
'is',
|
|
|
|
field("body", $._expr),
|
|
|
|
),
|
|
|
|
|
|
|
|
fun_decl: $ =>
|
2020-04-30 17:46:39 +04:00
|
|
|
prec.right(0,
|
|
|
|
seq(
|
|
|
|
field("recursive", optional($.recursive)),
|
|
|
|
'function',
|
|
|
|
field("name", $.Name),
|
|
|
|
field("parameters", $.parameters),
|
|
|
|
':',
|
|
|
|
field("type", $._type_expr),
|
|
|
|
'is',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("body", $._let_expr),
|
2020-05-01 22:10:10 +04:00
|
|
|
),
|
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_let_expr: $ =>
|
2020-05-01 22:10:10 +04:00
|
|
|
choice(
|
2020-07-20 01:04:01 +04:00
|
|
|
$.let_expr,
|
|
|
|
$._expr,
|
|
|
|
),
|
|
|
|
|
|
|
|
let_expr: $ =>
|
|
|
|
seq(
|
|
|
|
field("locals", $.block),
|
|
|
|
'with',
|
2020-05-01 22:10:10 +04:00
|
|
|
field("body", $._expr),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
parameters: $ => par(sepBy(';', field("parameter", $.param_decl))),
|
|
|
|
|
|
|
|
param_decl: $ =>
|
|
|
|
seq(
|
2020-07-20 01:04:01 +04:00
|
|
|
field("access", $._access),
|
2020-04-30 14:39:51 +04:00
|
|
|
field("name", $.Name),
|
|
|
|
':',
|
|
|
|
field("type", $._param_type),
|
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_access: $ => choice('var', 'const'),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_param_type: $ => $._fun_type,
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
_statement: $ =>
|
|
|
|
choice(
|
|
|
|
$._instruction,
|
|
|
|
$._open_data_decl,
|
2020-05-01 22:10:10 +04:00
|
|
|
$.attr_decl,
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
_open_data_decl: $ =>
|
|
|
|
choice(
|
2020-05-06 21:26:00 +04:00
|
|
|
$.const_decl,
|
|
|
|
$.var_decl,
|
2020-04-30 17:46:39 +04:00
|
|
|
$.fun_decl,
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
2020-05-06 21:26:00 +04:00
|
|
|
const_decl: $ =>
|
2020-04-30 14:39:51 +04:00
|
|
|
seq(
|
|
|
|
'const',
|
|
|
|
field("name", $.Name),
|
|
|
|
':',
|
|
|
|
field("type", $._type_expr),
|
|
|
|
'=',
|
|
|
|
field("value", $._expr),
|
|
|
|
),
|
|
|
|
|
2020-05-06 21:26:00 +04:00
|
|
|
var_decl: $ =>
|
2020-04-30 14:39:51 +04:00
|
|
|
seq(
|
|
|
|
'var',
|
|
|
|
field("name", $.Name),
|
|
|
|
':',
|
|
|
|
field("type", $._type_expr),
|
|
|
|
':=',
|
|
|
|
field("value", $._expr),
|
|
|
|
),
|
|
|
|
|
|
|
|
_instruction: $ =>
|
|
|
|
choice(
|
|
|
|
$.conditional,
|
|
|
|
$.case_instr,
|
|
|
|
$.assignment,
|
2020-07-20 01:04:01 +04:00
|
|
|
$._loop,
|
2020-04-30 14:39:51 +04:00
|
|
|
$._proc_call,
|
|
|
|
$.skip,
|
|
|
|
$.record_patch,
|
|
|
|
$.map_patch,
|
|
|
|
$.set_patch,
|
|
|
|
$.map_remove,
|
|
|
|
$.set_remove,
|
|
|
|
),
|
|
|
|
|
|
|
|
set_remove: $ =>
|
|
|
|
seq(
|
|
|
|
'remove',
|
|
|
|
field("key", $._expr),
|
|
|
|
'from',
|
|
|
|
'set',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("container", $._path),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
map_remove: $ =>
|
|
|
|
seq(
|
|
|
|
'remove',
|
|
|
|
field("key", $._expr),
|
|
|
|
'from',
|
|
|
|
'map',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("container", $._path),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
set_patch: $ =>
|
|
|
|
seq(
|
|
|
|
'patch',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("container", $._path),
|
2020-04-30 14:39:51 +04:00
|
|
|
'with',
|
|
|
|
ne_injection('set', field("key", $._expr)),
|
|
|
|
),
|
|
|
|
|
|
|
|
map_patch: $ =>
|
|
|
|
seq(
|
|
|
|
'patch',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("container", $._path),
|
2020-04-30 14:39:51 +04:00
|
|
|
'with',
|
|
|
|
ne_injection('map', field("binding", $.binding)),
|
|
|
|
),
|
|
|
|
|
|
|
|
binding: $ =>
|
|
|
|
seq(
|
|
|
|
field("key", $._expr),
|
|
|
|
'->',
|
|
|
|
field("value", $._expr),
|
|
|
|
),
|
|
|
|
|
|
|
|
record_patch: $ =>
|
|
|
|
seq(
|
|
|
|
'patch',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("container", $._path),
|
2020-04-30 14:39:51 +04:00
|
|
|
'with',
|
|
|
|
ne_injection('record', field("binding", $.field_assignment)),
|
|
|
|
),
|
|
|
|
|
|
|
|
_proc_call: $ =>
|
|
|
|
$.fun_call,
|
|
|
|
|
|
|
|
conditional: $ =>
|
|
|
|
seq(
|
|
|
|
'if',
|
|
|
|
field("selector", $._expr),
|
|
|
|
'then',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("then", $._if_clause),
|
2020-04-30 14:39:51 +04:00
|
|
|
optional(';'),
|
|
|
|
'else',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("else", $._if_clause),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_if_clause: $ =>
|
2020-04-30 14:39:51 +04:00
|
|
|
choice(
|
|
|
|
$._instruction,
|
|
|
|
$.clause_block,
|
|
|
|
),
|
|
|
|
|
|
|
|
clause_block: $ =>
|
|
|
|
choice(
|
|
|
|
field("block", $.block),
|
|
|
|
seq('{', sepBy1(';', field("statement", $._statement)), '}')
|
|
|
|
),
|
|
|
|
|
|
|
|
block: $ =>
|
|
|
|
choice(
|
|
|
|
seq(
|
|
|
|
'begin',
|
|
|
|
sepBy(';', field("statement", $._statement)),
|
|
|
|
'end',
|
|
|
|
),
|
|
|
|
seq(
|
|
|
|
'block',
|
|
|
|
'{',
|
|
|
|
sepBy(';', field("statement", $._statement)),
|
|
|
|
'}',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
case_instr: $ =>
|
|
|
|
choice(
|
|
|
|
seq(
|
|
|
|
'case',
|
|
|
|
field("subject", $._expr),
|
|
|
|
'of',
|
|
|
|
optional('|'),
|
|
|
|
sepBy1('|', field("case", $.case_clause_instr)),
|
|
|
|
'end'
|
|
|
|
),
|
|
|
|
seq(
|
|
|
|
'case',
|
|
|
|
$._expr,
|
|
|
|
'of',
|
|
|
|
'[',
|
|
|
|
optional('|'),
|
|
|
|
sepBy1('|', field("case", $.case_clause_instr)),
|
|
|
|
']'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
case_clause_instr: $ =>
|
|
|
|
seq(
|
2020-07-20 01:04:01 +04:00
|
|
|
field("pattern", $._pattern),
|
2020-04-30 14:39:51 +04:00
|
|
|
'->',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("body", $._if_clause),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
assignment: $ =>
|
|
|
|
seq(
|
|
|
|
field("LHS", $._lhs),
|
|
|
|
':=',
|
|
|
|
field("RHS", $._rhs),
|
|
|
|
),
|
|
|
|
|
|
|
|
_rhs: $ => $._expr,
|
2020-07-20 01:04:01 +04:00
|
|
|
_lhs: $ => choice($._path, $.map_lookup),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_loop: $ => choice($.while_loop, $._for_loop),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
while_loop: $ =>
|
|
|
|
seq(
|
|
|
|
'while',
|
|
|
|
field("breaker", $._expr),
|
|
|
|
field("body", $.block),
|
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_for_loop: $ =>
|
2020-04-30 14:39:51 +04:00
|
|
|
choice(
|
2020-07-20 01:04:01 +04:00
|
|
|
$.for_cycle,
|
|
|
|
$.for_box,
|
|
|
|
),
|
|
|
|
|
|
|
|
for_cycle: $ =>
|
|
|
|
seq(
|
|
|
|
'for',
|
|
|
|
field("name", $.Name),
|
|
|
|
':=',
|
|
|
|
field("begin", $._rhs),
|
|
|
|
'to',
|
|
|
|
field("end", $._expr),
|
|
|
|
optional(seq(
|
|
|
|
"step",
|
|
|
|
field("step", $._expr),
|
|
|
|
)),
|
|
|
|
field("body", $.block),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
for_box: $ =>
|
|
|
|
seq(
|
|
|
|
'for',
|
|
|
|
field("key", $.Name),
|
|
|
|
optional(seq('->', field("value", $.Name))),
|
|
|
|
'in',
|
|
|
|
field("kind", $._collection),
|
|
|
|
field("collection", $._expr),
|
|
|
|
field("body", $.block),
|
|
|
|
),
|
|
|
|
|
|
|
|
_collection: $ => choice('map', 'set', 'list'),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
interactive_expr: $ => $._expr,
|
|
|
|
|
|
|
|
_expr: $ =>
|
|
|
|
choice(
|
|
|
|
$.case_expr,
|
|
|
|
$.cond_expr,
|
2020-07-20 01:04:01 +04:00
|
|
|
$._op_expr,
|
2020-04-30 14:39:51 +04:00
|
|
|
$.fun_expr,
|
|
|
|
),
|
|
|
|
|
|
|
|
case_expr: $ =>
|
|
|
|
choice(
|
|
|
|
seq(
|
|
|
|
'case',
|
|
|
|
field("subject", $._expr),
|
|
|
|
'of',
|
|
|
|
optional('|'),
|
|
|
|
sepBy1('|', field("case", $.case_clause_expr)),
|
|
|
|
'end'
|
|
|
|
),
|
|
|
|
seq(
|
|
|
|
'case',
|
|
|
|
field("subject", $._expr),
|
|
|
|
'of',
|
|
|
|
'[',
|
|
|
|
optional('|'),
|
|
|
|
sepBy1('|', field("case", $.case_clause_expr)),
|
|
|
|
']'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
case_clause_expr: $ =>
|
|
|
|
seq(
|
2020-07-20 01:04:01 +04:00
|
|
|
field("pattern", $._pattern),
|
2020-04-30 14:39:51 +04:00
|
|
|
'->',
|
|
|
|
field("body", $._expr),
|
|
|
|
),
|
|
|
|
|
|
|
|
cond_expr: $ =>
|
|
|
|
seq(
|
|
|
|
'if',
|
|
|
|
field("selector", $._expr),
|
|
|
|
'then',
|
|
|
|
field("then", $._expr),
|
|
|
|
optional(';'),
|
|
|
|
'else',
|
|
|
|
field("else", $._expr),
|
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_op_expr: $ =>
|
|
|
|
choice(
|
|
|
|
$._core_expr,
|
|
|
|
$.binop,
|
|
|
|
$.unop,
|
|
|
|
),
|
|
|
|
|
|
|
|
binop: $ =>
|
2020-04-30 14:39:51 +04:00
|
|
|
choice(
|
2020-07-20 01:04:01 +04:00
|
|
|
prec.left (0, seq(field("arg1", $._op_expr), field("op", 'or'), field("arg2", $._op_expr))),
|
|
|
|
prec.left (1, seq(field("arg1", $._op_expr), field("op", 'and'), field("arg2", $._op_expr))),
|
|
|
|
prec.right(2, seq(field("arg1", $._core_expr), field("op", 'contains'), field("arg2", $._op_expr))),
|
|
|
|
prec.left (3, seq(field("arg1", $._op_expr), field("op", $.comparison), field("arg2", $._op_expr))),
|
|
|
|
prec.right(4, seq(field("arg1", $._op_expr), field("op", '^'), field("arg2", $._op_expr))),
|
|
|
|
prec.right(5, seq(field("arg1", $._op_expr), field("op", '#'), field("arg2", $._op_expr))),
|
|
|
|
prec.left (6, seq(field("arg1", $._op_expr), field("op", $.adder), field("arg2", $._op_expr))),
|
|
|
|
prec.left (7, seq(field("arg1", $._op_expr), field("op", $.multiplier), field("arg2", $._op_expr))),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
unop: $ => prec.right(8, seq(field("negate", $.negate), field("arg", $._core_expr))),
|
|
|
|
|
2020-04-30 14:39:51 +04:00
|
|
|
comparison: $ => choice('<', '<=', '>', '>=', '=', '=/='),
|
2020-05-06 16:34:47 +04:00
|
|
|
adder: $ => choice('-', '+'),
|
2020-04-30 14:39:51 +04:00
|
|
|
multiplier: $ => choice('/', '*', 'mod'),
|
2020-05-06 16:34:47 +04:00
|
|
|
negate: $ => choice('-', 'not'),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
_core_expr: $ =>
|
|
|
|
choice(
|
|
|
|
$.Int,
|
|
|
|
$.Nat,
|
|
|
|
$.Tez,
|
|
|
|
$.Name,
|
|
|
|
$.module_field,
|
|
|
|
$.String,
|
|
|
|
$.Bytes,
|
|
|
|
$.False,
|
|
|
|
$.True,
|
|
|
|
$.Unit,
|
|
|
|
$.annot_expr,
|
|
|
|
$.tuple_expr,
|
2020-07-20 01:04:01 +04:00
|
|
|
$._list_expr,
|
2020-04-30 14:39:51 +04:00
|
|
|
$.None,
|
|
|
|
$._fun_call_or_par_or_projection,
|
|
|
|
$._map_expr,
|
|
|
|
$.set_expr,
|
|
|
|
$.record_expr,
|
|
|
|
$.update_record,
|
2020-07-20 01:04:01 +04:00
|
|
|
$._constr_use,
|
2020-04-30 14:39:51 +04:00
|
|
|
$.Some_call,
|
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_constr_use: $ =>
|
|
|
|
choice(
|
|
|
|
$.constr_call,
|
|
|
|
$.constr
|
|
|
|
),
|
|
|
|
|
2020-04-30 14:39:51 +04:00
|
|
|
constr_call: $ =>
|
|
|
|
seq(
|
|
|
|
field("constr", $.constr),
|
2020-07-20 01:04:01 +04:00
|
|
|
field("arguments", $.arguments)
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
Some_call: $ =>
|
|
|
|
seq(
|
|
|
|
field("constr", 'Some'),
|
|
|
|
field("arguments", $.arguments),
|
|
|
|
),
|
|
|
|
|
|
|
|
_fun_call_or_par_or_projection: $ =>
|
|
|
|
choice(
|
|
|
|
$.par_call,
|
|
|
|
$.projection_call,
|
|
|
|
$.fun_call,
|
2020-07-20 01:04:01 +04:00
|
|
|
$._projection,
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
par_call: $ =>
|
|
|
|
prec.right(1, seq(
|
|
|
|
par(field("f", $._expr)),
|
2020-07-20 01:04:01 +04:00
|
|
|
field("arguments", $.arguments),
|
2020-04-30 14:39:51 +04:00
|
|
|
)),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
projection_call: $ => prec(1, seq(
|
2020-04-30 14:39:51 +04:00
|
|
|
field("f", $._projection),
|
2020-07-20 01:04:01 +04:00
|
|
|
field("arguments", $.arguments),
|
|
|
|
)),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
annot_expr: $ =>
|
|
|
|
par(seq(
|
2020-07-20 01:04:01 +04:00
|
|
|
field("subject", $._op_expr),
|
2020-04-30 14:39:51 +04:00
|
|
|
':',
|
|
|
|
field("type", $._type_expr)
|
|
|
|
)),
|
|
|
|
|
2020-05-08 00:09:14 +04:00
|
|
|
set_expr: $ => injection('set', field("element", $._expr)),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
_map_expr: $ =>
|
|
|
|
choice(
|
|
|
|
$.map_lookup,
|
|
|
|
$.map_injection,
|
|
|
|
$.big_map_injection,
|
|
|
|
),
|
|
|
|
|
2020-05-07 00:31:05 +04:00
|
|
|
map_injection: $ => injection('map', field("binding", $.binding)),
|
|
|
|
big_map_injection: $ => injection('big_map', field("binding", $.binding)),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
map_lookup: $ =>
|
|
|
|
seq(
|
2020-07-20 01:04:01 +04:00
|
|
|
field("container", $._path),
|
2020-04-30 14:39:51 +04:00
|
|
|
brackets(field("index", $._expr)),
|
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_path: $ => choice($.Name, $._projection),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_fpath: $ => choice($.FieldName, $._projection),
|
2020-07-08 20:31:42 +04:00
|
|
|
|
2020-04-30 14:39:51 +04:00
|
|
|
module_field: $ =>
|
|
|
|
seq(
|
|
|
|
field("module", $.Name_Capital),
|
|
|
|
'.',
|
|
|
|
field("method", $._module_fun),
|
|
|
|
),
|
|
|
|
|
|
|
|
_module_fun: $ =>
|
|
|
|
choice(
|
|
|
|
$.Name,
|
|
|
|
$.map,
|
|
|
|
$.or,
|
|
|
|
$.and,
|
|
|
|
$.remove,
|
|
|
|
),
|
|
|
|
|
|
|
|
or: $ => 'or',
|
|
|
|
and: $ => 'and',
|
|
|
|
remove: $ => 'remove',
|
|
|
|
|
|
|
|
_projection: $ =>
|
|
|
|
choice(
|
|
|
|
$.data_projection,
|
|
|
|
$.module_projection,
|
|
|
|
),
|
|
|
|
|
|
|
|
data_projection: $ => seq(
|
|
|
|
field("struct", $.Name),
|
|
|
|
'.',
|
2020-07-20 01:04:01 +04:00
|
|
|
sepBy1('.', field("index", $._selection)),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
module_projection: $ =>
|
|
|
|
seq(
|
|
|
|
field("module", $.Name_Capital),
|
|
|
|
'.',
|
|
|
|
field("index", $.Name),
|
|
|
|
'.',
|
2020-07-20 01:04:01 +04:00
|
|
|
sepBy1('.', field("index", $._selection)),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_selection: $ => choice($.FieldName, $.Int),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
record_expr: $ =>
|
|
|
|
choice(
|
|
|
|
seq(
|
|
|
|
'record',
|
|
|
|
sepBy(';', field("assignment", $.field_assignment)),
|
|
|
|
'end',
|
|
|
|
),
|
|
|
|
seq(
|
|
|
|
'record',
|
|
|
|
'[',
|
|
|
|
sepBy(';', field("assignment", $.field_assignment)),
|
|
|
|
']',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
update_record: $ =>
|
|
|
|
seq(
|
2020-07-20 01:04:01 +04:00
|
|
|
field("record", $._path),
|
2020-04-30 14:39:51 +04:00
|
|
|
'with',
|
|
|
|
ne_injection('record', field("assignment", $.field_path_assignment)),
|
|
|
|
),
|
|
|
|
|
|
|
|
field_assignment: $ =>
|
|
|
|
seq(
|
2020-07-08 20:31:42 +04:00
|
|
|
field("name", $.FieldName),
|
2020-04-30 14:39:51 +04:00
|
|
|
'=',
|
|
|
|
field("_rhs", $._expr),
|
|
|
|
),
|
|
|
|
|
|
|
|
field_path_assignment: $ =>
|
|
|
|
seq(
|
2020-07-20 01:04:01 +04:00
|
|
|
field("lhs", $._fpath),
|
2020-04-30 14:39:51 +04:00
|
|
|
'=',
|
|
|
|
field("_rhs", $._expr),
|
|
|
|
),
|
|
|
|
|
|
|
|
fun_call: $ =>
|
|
|
|
seq(
|
|
|
|
field("f", choice($.Name, $.module_field)),
|
|
|
|
field("arguments", $.arguments),
|
|
|
|
),
|
|
|
|
|
|
|
|
tuple_expr: $ => par(sepBy1(',', field("element", $._expr))),
|
|
|
|
arguments: $ => par(sepBy(',', field("argument", $._expr))),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_list_expr: $ => choice($.list_injection, 'nil'),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
list_injection: $ => injection('list', field("element", $._expr)),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_pattern: $ =>
|
2020-05-08 00:09:14 +04:00
|
|
|
choice(
|
2020-07-20 01:04:01 +04:00
|
|
|
$.cons_pattern,
|
|
|
|
$._core_pattern,
|
2020-05-08 00:09:14 +04:00
|
|
|
),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
_core_pattern: $ =>
|
|
|
|
choice(
|
|
|
|
$.Name,
|
|
|
|
'_',
|
|
|
|
$.Int,
|
|
|
|
$.Nat,
|
|
|
|
$.String,
|
2020-07-20 01:04:01 +04:00
|
|
|
$._list_pattern,
|
2020-04-30 14:39:51 +04:00
|
|
|
$.tuple_pattern,
|
|
|
|
$._constr_pattern,
|
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
_list_pattern: $ =>
|
2020-04-30 14:39:51 +04:00
|
|
|
choice(
|
2020-07-20 01:04:01 +04:00
|
|
|
$.list_pattern,
|
2020-04-30 14:39:51 +04:00
|
|
|
'nil',
|
|
|
|
),
|
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
list_pattern: $ => injection("list", field("element", $._pattern)),
|
|
|
|
|
|
|
|
cons_pattern: $ =>
|
2020-04-30 14:39:51 +04:00
|
|
|
seq(
|
|
|
|
field("head", $._core_pattern),
|
|
|
|
'#',
|
2020-07-20 01:04:01 +04:00
|
|
|
field("tail", $._pattern),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
tuple_pattern: $ =>
|
2020-07-20 01:04:01 +04:00
|
|
|
par(sepBy1(',', field("element", $._pattern))),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
|
|
|
_constr_pattern: $ => choice(
|
|
|
|
$.Unit,
|
|
|
|
$.False,
|
|
|
|
$.True,
|
|
|
|
$.None,
|
|
|
|
$.Some_pattern,
|
|
|
|
$.user_constr_pattern,
|
|
|
|
),
|
|
|
|
|
|
|
|
Some_pattern: $ =>
|
|
|
|
seq(
|
|
|
|
field("constr", 'Some'),
|
2020-07-20 01:04:01 +04:00
|
|
|
par(field("arg", $._pattern)),
|
2020-04-30 14:39:51 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
user_constr_pattern: $ =>
|
|
|
|
seq(
|
|
|
|
field("constr", $.constr),
|
|
|
|
optional(field("arguments", $.tuple_pattern)),
|
|
|
|
),
|
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
comment: $ => /\/\/[^\n]*\n/,
|
|
|
|
|
|
|
|
ocaml_comment: $ =>
|
|
|
|
seq(
|
|
|
|
'(*',
|
|
|
|
repeat(choice(
|
|
|
|
$.ocaml_comment,
|
|
|
|
/'([^'\\]|\\[\\"'ntbr ]|\\[0-9][0-9][0-9]|\\x[0-9A-Fa-f][0-9A-Fa-f]|\\o[0-3][0-7][0-7])'/,
|
|
|
|
/"([^\\"]|\\(.|\n))*"/,
|
|
|
|
/[A-Za-z_][a-zA-Z0-9_']*/,
|
|
|
|
/[^('"{*A-Za-z_]+/,
|
|
|
|
'(', "'", '*',
|
|
|
|
)),
|
|
|
|
'*)'
|
|
|
|
),
|
|
|
|
|
2020-05-08 00:09:14 +04:00
|
|
|
include: $ => seq('#include', field("filename", $.String)),
|
2020-04-30 14:39:51 +04:00
|
|
|
|
2020-07-20 01:04:01 +04:00
|
|
|
String: $ => choice(/\"(\\.|[^"])*\"/, /{\|(\\.|[^\|])*\|}/),
|
2020-04-30 14:39:51 +04:00
|
|
|
Int: $ => /-?([1-9][0-9_]*|0)/,
|
|
|
|
Nat: $ => /([1-9][0-9_]*|0)n/,
|
|
|
|
Tez: $ => /([1-9][0-9_]*|0)(\.[0-9_]+)?(tz|tez|mutez)/,
|
|
|
|
Bytes: $ => /0x[0-9a-fA-F]+/,
|
2020-07-08 20:31:42 +04:00
|
|
|
FieldName: $ => /[a-z][a-zA-Z0-9_]*/,
|
|
|
|
TypeName: $ => /[a-z][a-zA-Z0-9_]*/,
|
2020-04-30 14:39:51 +04:00
|
|
|
Name: $ => /[a-z][a-zA-Z0-9_]*/,
|
|
|
|
Name_Capital: $ => /[A-Z][a-zA-Z0-9_]*/,
|
|
|
|
Keyword: $ => /[A-Za-z][a-z]*/,
|
|
|
|
|
|
|
|
False: $ => 'False',
|
|
|
|
True: $ => 'True',
|
|
|
|
Unit: $ => 'Unit',
|
|
|
|
None: $ => 'None',
|
|
|
|
skip: $ => 'skip',
|
2020-06-09 15:56:11 +04:00
|
|
|
recursive: $ => 'recursive',
|
2020-04-30 14:39:51 +04:00
|
|
|
}
|
|
|
|
});
|