Skip to content

Commit

Permalink
WIP Shorthand syntax for frame and label lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhanshuguptagit committed Jun 23, 2024
1 parent 2aceb75 commit b3aa704
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/bean/interpreter.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,21 @@
:FunctionInvocation (apply-f sheet
(eval-sub-ast arg)
(rest args))
:FunctionChain (let [[expr [_ fn-name & fn-args]] args]
:FrameLookup (eval-sub-ast
[:FunctionInvocation
[:Name "frame"]
[:Expression [:CellRef "B" "3"]]])
:FunctionChain (let [[expr [node-type*
[_ name* :as name-node]
& fn-args]] args]
(eval-sub-ast
(concat [:FunctionInvocation fn-name expr] fn-args)))
(case node-type*
:LabelLookup
[:FunctionInvocation
[:Name "get"] expr
[:Expression [:Value [:QuotedString name*]]]]
:FunctionInvocation
(concat [:FunctionInvocation name-node expr] fn-args))))
:Expression (if (util/is-expression? arg)
(let [[left op right] args]
(apply-op (eval-sub-ast op)
Expand Down
11 changes: 8 additions & 3 deletions src/bean/parser/parser.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
MatrixRef = CellRef <':'> CellRef
Operation = '+' | '*' | '=' | '<' | '>'
Expression = Value | CellRef | MatrixRef | FunctionChain | Expression Operation Expression | FunctionInvocation | FunctionDefinition | Name
Expression = (Value | CellRef | MatrixRef | FunctionChain |
Expression Operation Expression | FunctionInvocation |
FunctionDefinition | FrameLookup) / Name
FunctionInvocation = (FunctionDefinition | Name) <'('> [Expression {<' '> Expression}] <')'>
FunctionDefinition = <'{'> Expression <'}'>
FunctionChain = Expression <'.'> FunctionInvocation
FunctionChain = Expression [<'.'> (FunctionInvocation | LabelLookup)]
Name = #'[a-z]+'
Name = #'[a-zA-Z0-9 ]+(?<! )'
FrameLookup = <'$'> Name
LabelLookup = Name
Value = Integer / <'\"'> QuotedString <'\"'>
QuotedString = #'[^\"]+'
Expand Down

0 comments on commit b3aa704

Please sign in to comment.