-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Statements: Parsing & dependency management #1
Conversation
src/bean/grid.cljs
Outdated
(->> updated-addrs | ||
(deps/immediate-dependents sheet) | ||
(deps/resolve-dependents sheet))))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would passing updated-addrs
to resolve-dependents
directly take care of getting the immediate dependents?
src/bean/interpreter.cljs
Outdated
(defn eval-statements [scratch] | ||
(comment | ||
eval scratch | ||
generate bindings names -> ast)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove.
src/bean/deps.cljs
Outdated
#{}))) | ||
|
||
(defn resolve-dependents [{:keys [depgraph]} deps] | ||
"Iterate over the dependents and return a set of resolved dependents. :ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could break this into two resolve-binding-dependents
, then this could just be called dependents
.
3555e5a
to
41e0fad
Compare
ad8b1b3
to
5236a35
Compare
8327dfe
to
3054cd3
Compare
3054cd3
to
98757c8
Compare
68e24d3
to
e0675ca
Compare
98757c8
to
63802fc
Compare
63802fc
to
286ca7b
Compare
To add content to statemnents, we annotate the AST with the source using instaparse's built-in functionality.
286ca7b
to
eded98d
Compare
@@ -0,0 +1,46 @@ | |||
(ns bean.ui.scratch | |||
(:require [bean.scratch :as scratch] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename scratch ns to code
.
(map ast->deps args)) | ||
:FunctionDefinition (ast->deps arg) | ||
:Name (if (#{"x" "y" "z"} arg) #{} #{(->named-dep arg)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this check to a formal-parameter?
in interpreter.
(let [updated-dependent-set (disj (get depgraph parent) child)] | ||
(if (empty? updated-dependent-set) | ||
(dissoc depgraph parent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to dissoc parents with no children?
@@ -134,7 +110,7 @@ | |||
(spill grid)))) | |||
|
|||
(defn parse-grid [grid] | |||
(util/map-on-matrix content->cell grid)) | |||
(util/map-on-matrix value/from-cell grid)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name seems incorrect, it's more like to-cell
. This is the input to the interpreter, the interpreter returns a value
. See ast-result
.
:representation (str "Undefined reference: \"" name "\"")}) | ||
|
||
(defn named-ref-error [named error] | ||
(str "name: " named ". " error)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to self: Look at named-ref-error
usage.
[bean.deps :refer [make-depgraph update-depgraph]] | ||
[clojure.test :refer [deftest testing is]])) | ||
|
||
(deftest depgraph-update-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test for named deps.
(let [evaled-grid (grid/eval-sheet [["1" "2" "=A1+B1"] | ||
["=C1" "" ""]])] | ||
(let [evaled-grid (grid/eval-sheet | ||
(grid/new-sheet [["1" "2" "=A1+B1"] ["=C1" "" ""]] ""))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split grid into two lines if the linter allows. It's easier to read.
(name (or (get-in @sheet [:ui :scratch-evaluation-state]) | ||
:evaluated))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should put scratch-evaluation-state
evaluated
by default instead of defaulting here.
{:grid parsed-grid | ||
:bindings {} | ||
:depgraph (make-depgraph parsed-grid)}) | ||
(defn new-sheet [content-grid code] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can make code default to ""
unless supplied.
eval-sheet | ||
{:grid grid* | ||
:depgraph (cond-> depgraph | ||
content-changed? (update-depgraph |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe can skip content-changed?
for simplicity.
This PR adds statement parsing & some dependency management. Statement evaluation will be added in a follow-up PR.