simplify error messages

This commit is contained in:
Umur Ozkul 2022-05-20 17:56:26 +02:00
parent a314cd46fb
commit a17ea3f5a1
2 changed files with 755 additions and 610 deletions

View File

@ -98,15 +98,16 @@ statement
/ defunStatement / defunStatement
letStatement letStatement
= variable:identifier _ '=' _nl value:zeroOMoreArgumentsBlockOrExpression = variable:identifier _ assignmentOp _nl value:zeroOMoreArgumentsBlockOrExpression
{ return nodeLetStatment(variable, value) } { return nodeLetStatment(variable, value) }
defunStatement defunStatement
= variable:identifier '(' _nl args:array_parameters _nl ')' _ '=' _nl body:innerBlockOrExpression = variable:identifier '(' _nl args:array_parameters _nl ')' _ assignmentOp _nl body:innerBlockOrExpression
{ var value = nodeLambda(args, body) { var value = nodeLambda(args, body)
return nodeLetStatment(variable, value) } return nodeLetStatment(variable, value) }
assignmentOp "assignment" = '='
array_parameters array_parameters
= head:dollarIdentifier tail:(_ ',' _nl @dollarIdentifier)* = head:dollarIdentifier tail:(_ ',' _nl @dollarIdentifier)*
{ return [head, ...tail]; } { return [head, ...tail]; }
@ -124,52 +125,68 @@ ternary
{ return nodeTernary(condition, trueExpression, falseExpression) } { return nodeTernary(condition, trueExpression, falseExpression) }
logicalAdditive logicalAdditive
= head:logicalMultiplicative tail:(_ operator:'||' _nl arg:logicalMultiplicative {return {operator: operator, right: arg}})* = head:logicalMultiplicative tail:(_ operator:logicalAdditiveOp _nl arg:logicalMultiplicative {return {operator: operator, right: arg}})*
{ return tail.reduce(function(result, element) { { return tail.reduce(function(result, element) {
return makeFunctionCall(toFunction[element.operator], [result, element.right]) return makeFunctionCall(toFunction[element.operator], [result, element.right])
}, head)} }, head)}
logicalAdditiveOp "operator" = '||'
// start binary operators // start binary operators
logicalMultiplicative logicalMultiplicative
= head:equality tail:(_ operator:'&&' _nl arg:equality {return {operator: operator, right: arg}})* = head:equality tail:(_ operator:logicalMultiplicativeOp _nl arg:equality {return {operator: operator, right: arg}})*
{ return tail.reduce(function(result, element) { { return tail.reduce(function(result, element) {
return makeFunctionCall(toFunction[element.operator], [result, element.right]) return makeFunctionCall(toFunction[element.operator], [result, element.right])
}, head)} }, head)}
logicalMultiplicativeOp "operator" = '&&'
equality equality
= left:relational _ operator:('=='/'!=') _nl right:relational = left:relational _ operator:equalityOp _nl right:relational
{ return makeFunctionCall(toFunction[operator], [left, right])} { return makeFunctionCall(toFunction[operator], [left, right])}
/ relational / relational
equalityOp "operator" = '=='/'!='
relational relational
= left:additive _ operator:('<='/'<'/'>='/'>') _nl right:additive = left:additive _ operator:relationalOp _nl right:additive
{ return makeFunctionCall(toFunction[operator], [left, right])} { return makeFunctionCall(toFunction[operator], [left, right])}
/ additive / additive
relationalOp "operator" = '<='/'<'/'>='/'>'
additive additive
= head:multiplicative tail:(_ operator:('+' / '-' / '.+' / '.-') _nl arg:multiplicative {return {operator: operator, right: arg}})* = head:multiplicative tail:(_ operator:additiveOp _nl arg:multiplicative {return {operator: operator, right: arg}})*
{ return tail.reduce(function(result, element) { { return tail.reduce(function(result, element) {
return makeFunctionCall(toFunction[element.operator], [result, element.right]) return makeFunctionCall(toFunction[element.operator], [result, element.right])
}, head)} }, head)}
additiveOp "operator" = '+' / '-' / '.+' / '.-'
multiplicative multiplicative
= head:power tail:(_ operator:('*' / '/' / '.*' / './') _nl arg:power {return {operator: operator, right: arg}})* = head:power tail:(_ operator:multiplicativeOp _nl arg:power {return {operator: operator, right: arg}})*
{ return tail.reduce(function(result, element) { { return tail.reduce(function(result, element) {
return makeFunctionCall(toFunction[element.operator], [result, element.right]) return makeFunctionCall(toFunction[element.operator], [result, element.right])
}, head)} }, head)}
multiplicativeOp "operator" = '*' / '/' / '.*' / './'
power power
= head:credibleInterval tail:(_ operator:('^' / '.^') _nl arg:credibleInterval {return {operator: operator, right: arg}})* = head:credibleInterval tail:(_ operator:powerOp _nl arg:credibleInterval {return {operator: operator, right: arg}})*
{ return tail.reduce(function(result, element) { { return tail.reduce(function(result, element) {
return makeFunctionCall(toFunction[element.operator], [result, element.right]) return makeFunctionCall(toFunction[element.operator], [result, element.right])
}, head)} }, head)}
powerOp "operator" = '^' / '.^'
credibleInterval credibleInterval
= head:chainFunctionCall tail:(__ operator:('to') __nl arg:chainFunctionCall {return {operator: operator, right: arg}})* = head:chainFunctionCall tail:(__ operator:credibleIntervalOp __nl arg:chainFunctionCall {return {operator: operator, right: arg}})*
{ return tail.reduce(function(result, element) { { return tail.reduce(function(result, element) {
return makeFunctionCall(toFunction[element.operator], [result, element.right]) return makeFunctionCall(toFunction[element.operator], [result, element.right])
}, head)} }, head)}
credibleIntervalOp "operator" = 'to'
chainFunctionCall chainFunctionCall
= head:unary tail:(_ ('->'/'|>') _nl chained:chainedFunction {return chained})* = head:unary tail:(_ ('->'/'|>') _nl chained:chainedFunction {return chained})*
{ return tail.reduce(function(result, element) { { return tail.reduce(function(result, element) {
@ -191,7 +208,7 @@ unary
{ return makeFunctionCall(unaryToFunction[unaryOperator], [right])} { return makeFunctionCall(unaryToFunction[unaryOperator], [right])}
/ postOperator / postOperator
unaryOperator unaryOperator "unary operator"
= ('-' / '.-' / '!' ) = ('-' / '.-' / '!' )
postOperator = indexedValue postOperator = indexedValue
@ -296,7 +313,7 @@ recordConstructor 'record'
= key:expression _ ':' _nl value:expression = key:expression _ ':' _nl value:expression
{ return nodeKeyValue(key, value)} { return nodeKeyValue(key, value)}
_ 'optional whitespace' _ 'whitespace'
= whiteSpaceCharactersOrComment* = whiteSpaceCharactersOrComment*
_nl 'optional whitespace or newline' _nl 'optional whitespace or newline'