grammar: identifiers with modules

This commit is contained in:
Umur Ozkul 2022-06-08 16:09:09 +02:00
parent 2dc204e222
commit b41e32805c

View File

@ -224,31 +224,23 @@ postOperator = indexedValue
indexedValue indexedValue
= collectionElement = collectionElement
/ recordElement
/ atom / atom
collectionElement collectionElement
= head:atom &('['/'('/'.') = head:atom &('['/'('/'.')
tail:( tail:(
_ '[' _nl arg:expression _nl ']' {return {fn: postOperatorToFunction['[]'], args: [arg]}} _ '[' _nl arg:expression _nl ']' {return {fn: postOperatorToFunction['[]'], args: [arg]}}
/ _ '(' _nl args:array_functionArguments _nl ')' {return {fn: postOperatorToFunction['()'], args: args}} / _ '(' _nl args:array_functionArguments _nl ')' {return {fn: postOperatorToFunction['()'], args: args}}
/ '.' arg:$dollarIdentifier {return {fn: postOperatorToFunction['[]'], args: [nodeString(arg)]}} / '.' arg:$dollarIdentifier {return {fn: postOperatorToFunction['[]'], args: [nodeString(arg)]}}
)* )*
{ return tail.reduce(function(result, element) { { return tail.reduce(function(result, element) {
return makeFunctionCall(element.fn, [result, ...element.args]) return makeFunctionCall(element.fn, [result, ...element.args])
}, head)} }, head)}
array_functionArguments array_functionArguments
= head:expression tail:(_ ',' _nl @expression)* = head:expression tail:(_ ',' _nl @expression)*
{ return [head, ...tail]; } { return [head, ...tail]; }
recordElement
= head:dollarIdentifier &'.'
tail:(_ '.' _nl arg:$dollarIdentifier {return {fn: postOperatorToFunction['.'], args: [nodeString(arg)]}})*
{ return tail.reduce(function(result, element) {
return makeFunctionCall(element.fn, [result, ...element.args])
}, head)}
atom atom
= '(' _nl expression:expression _nl ')' {return expression} = '(' _nl expression:expression _nl ')' {return expression}
/ basicValue / basicValue
@ -259,8 +251,18 @@ basicLiteral
= string = string
/ number / number
/ boolean / boolean
/ dollarIdentifierWithModule
/ dollarIdentifier / dollarIdentifier
dollarIdentifierWithModule 'identifier'
= head:moduleIdentifier
tail:('.' _nl @moduleIdentifier)* '.' _nl
final:dollarIdentifier
{ tail.push(final);
return tail.reduce(function(result, element) {
return makeFunctionCall(postOperatorToFunction['[]'], [result, element])
}, head)}
identifier 'identifier' identifier 'identifier'
= ([_a-z]+[_a-z0-9]i*) {return nodeIdentifier(text())} = ([_a-z]+[_a-z0-9]i*) {return nodeIdentifier(text())}
@ -270,6 +272,10 @@ unitIdentifier 'identifier'
dollarIdentifier '$identifier' dollarIdentifier '$identifier'
= ([\$_a-z]+[\$_a-z0-9]i*) {return nodeIdentifier(text())} = ([\$_a-z]+[\$_a-z0-9]i*) {return nodeIdentifier(text())}
moduleIdentifier 'identifier'
= ([A-Z]+[_a-z0-9]i*) {return nodeIdentifier(text())}
string 'string' string 'string'
= characters:("'" @([^'])* "'") {return nodeString(characters.join(''))} = characters:("'" @([^'])* "'") {return nodeString(characters.join(''))}
/ characters:('"' @([^"])* '"') {return nodeString(characters.join(''))} / characters:('"' @([^"])* '"') {return nodeString(characters.join(''))}
@ -338,7 +344,7 @@ recordConstructor 'record'
_ 'whitespace' _ 'whitespace'
= whiteSpaceCharactersOrComment* = whiteSpaceCharactersOrComment*
_nl 'optional whitespace or newline' _nl 'whitespace or newline'
= (whiteSpaceCharactersOrComment / commentOrNewLine)* = (whiteSpaceCharactersOrComment / commentOrNewLine)*
__ 'whitespace' __ 'whitespace'