From b41e32805cc9865a2027740b1f9b7da9e20fede1 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Wed, 8 Jun 2022 16:09:09 +0200 Subject: [PATCH] grammar: identifiers with modules --- .../Reducer_Peggy_GeneratedParser.peggy | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy index 8c853ff4..897cf536 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy @@ -224,31 +224,23 @@ postOperator = indexedValue indexedValue = collectionElement - / recordElement / atom - collectionElement - = head:atom &('['/'('/'.') - tail:( - _ '[' _nl arg:expression _nl ']' {return {fn: postOperatorToFunction['[]'], args: [arg]}} - / _ '(' _nl args:array_functionArguments _nl ')' {return {fn: postOperatorToFunction['()'], args: args}} - / '.' arg:$dollarIdentifier {return {fn: postOperatorToFunction['[]'], args: [nodeString(arg)]}} - )* - { return tail.reduce(function(result, element) { - return makeFunctionCall(element.fn, [result, ...element.args]) - }, head)} +collectionElement + = head:atom &('['/'('/'.') + tail:( + _ '[' _nl arg:expression _nl ']' {return {fn: postOperatorToFunction['[]'], args: [arg]}} + / _ '(' _nl args:array_functionArguments _nl ')' {return {fn: postOperatorToFunction['()'], args: args}} + / '.' arg:$dollarIdentifier {return {fn: postOperatorToFunction['[]'], args: [nodeString(arg)]}} + )* + { return tail.reduce(function(result, element) { + return makeFunctionCall(element.fn, [result, ...element.args]) + }, head)} array_functionArguments = head:expression tail:(_ ',' _nl @expression)* { 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 = '(' _nl expression:expression _nl ')' {return expression} / basicValue @@ -259,8 +251,18 @@ basicLiteral = string / number / boolean + / dollarIdentifierWithModule / 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' = ([_a-z]+[_a-z0-9]i*) {return nodeIdentifier(text())} @@ -270,6 +272,10 @@ unitIdentifier 'identifier' dollarIdentifier '$identifier' = ([\$_a-z]+[\$_a-z0-9]i*) {return nodeIdentifier(text())} +moduleIdentifier 'identifier' + = ([A-Z]+[_a-z0-9]i*) {return nodeIdentifier(text())} + + string 'string' = characters:("'" @([^'])* "'") {return nodeString(characters.join(''))} / characters:('"' @([^"])* '"') {return nodeString(characters.join(''))} @@ -338,7 +344,7 @@ recordConstructor 'record' _ 'whitespace' = whiteSpaceCharactersOrComment* -_nl 'optional whitespace or newline' +_nl 'whitespace or newline' = (whiteSpaceCharactersOrComment / commentOrNewLine)* __ 'whitespace'