diff options
author | Lizzy Hunt <lizzy.hunt@usu.edu> | 2024-03-05 15:36:31 -0700 |
---|---|---|
committer | Lizzy Hunt <lizzy.hunt@usu.edu> | 2024-03-05 15:36:31 -0700 |
commit | 89db6cf917002aab329ad35b89444fe1eab1d1f8 (patch) | |
tree | 66d406cec6cb9e88569f8d515ac34b0d33a51d65 /src/parser/grammar.pegjs | |
parent | 5e9a34e64254000b9922d69697774c430cdeca36 (diff) | |
download | cps-interpreter-89db6cf917002aab329ad35b89444fe1eab1d1f8.tar.gz cps-interpreter-89db6cf917002aab329ad35b89444fe1eab1d1f8.zip |
add naive record construction supportrecord
Diffstat (limited to 'src/parser/grammar.pegjs')
-rw-r--r-- | src/parser/grammar.pegjs | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/src/parser/grammar.pegjs b/src/parser/grammar.pegjs index 0017b18..229c922 100644 --- a/src/parser/grammar.pegjs +++ b/src/parser/grammar.pegjs @@ -17,11 +17,11 @@ SelectExpression _? LPAREN _? - record:Integer + index:Integer _? COMMA _? - val:Value + record:VarStatement _? COMMA _? @@ -31,7 +31,7 @@ SelectExpression _? continuation:ContinuationExpression _? - RPAREN { return { select: { record, val, bind, continuation } }; } + RPAREN { return { select: { index, record, bind, continuation } }; } OffsetExpression = OFFSET @@ -86,9 +86,17 @@ SwitchExpression RPAREN { return { switch: { switchIndex, continuations } }; } ApplicationExpression - = APP _? LPAREN _? fn:(LabelStatement / VarStatement) _? COMMA _? args:ValueList _? RPAREN { - return { application: { fn, args } }; - } + = APP + _? + LPAREN + _? + fn:(LabelStatement / VarStatement) + _? + COMMA + _? + args:ValueList + _? + RPAREN { return { application: { fn, args } }; } FixBinding = LPAREN @@ -169,16 +177,29 @@ PrimitiveOperationExpression }; } -RecordExpressionTuple - = LPAREN +AccessPath + = OffsetPath + / SelectPath + +OffsetPath = OFFP _ offset:Integer { return { offset: offset.int }; } + +SelectPath + = SELP + _? + LPAREN _? - value:Value + index:Integer _? COMMA _? - offset:OffsetStatement + accessPath:AccessPath _? - RPAREN { return { value, offset }; } + RPAREN { return { select: { index, accessPath } }; } + +RecordExpressionTuple + = LPAREN _? value:Value _? COMMA _? accessPath:AccessPath _? RPAREN { + return { value, accessPath }; + } RecordExpressionTupleList = LBRACKET @@ -238,14 +259,6 @@ BoolStatement = BOOL _ bool:Integer { return { bool: bool.int }; } StringStatement = STRING _ string:QuotedString { return string; } -AccessStatement - = OffsetStatement - / SelectStatement - -OffsetStatement = OFFP _ offset:Integer { return offset; } - -SelectStatement = SELP _ offset:Integer { return offset; } - Identifier = name:([A-Za-z] (LETTER / DIGIT / SAFE_SYMBOL)*) { return { name: name[0] + name[1].join('') }; @@ -291,7 +304,8 @@ ComparisonOperation / "||" / "&&" -Integer = digits:("-"? [0-9]+) !"." { return { int: parseInt(digits.join(''), 10) }; } +Integer + = digits:("-"? [0-9]+) !"." { return { int: parseInt(digits.join(''), 10) }; } QuotedString = "'" content:[^']* "'" { return content.join(''); } @@ -299,9 +313,11 @@ QuotedString Real = value:("-"? [0-9]+ ("." [0-9]+)?) { - return { real: parseFloat( - value.map(x => (Array.isArray(x) ? x.join('') : x)).join(''), - ) }; + return { + real: parseFloat( + value.map(x => (Array.isArray(x) ? x.join('') : x)).join(''), + ), + }; } Literal |