You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is part of #967 but could be more broadly useful for when we make changes to expressions.
Here’s some code to collect a dataset of expressions used in Mavo apps on a page:
letallExpressions=newSet();for(letappIdinMavo.all)Mavo.all[appId].root.walk(node=>{if(node.expressions?.length||node.expressions?.size){// Apparently this is a Set in some cases?!letexpressions=[...node.expressions].flatMap(e=>e.parsed.filter(a=>!!a.expression).map(e=>e.expression));expressions=expressions.filter(e=>!/^[a-z$_]\w*$/.test(e));// drop trivial expressions (just an id)expressions.forEach(e=>allExpressions.add(e));}});allExpressions=[...allExpressions];copy(allExpressions);console.log(allExpressions);
Note that this will not take actions expressions into account, but these don't tend to be very syntactically complex anyway.
[
"replace(join(pathsummary, ' '), ' ', ' ', 10)",
"if(absolute, 'absolute')",
"type != v and type != z",
"type != h and type != z",
"type = a",
"largeArc + 0",
"sweep + 0",
"type = c or type = s or type = q",
"type = c or type = q",
"type = c",
"if(absolute, uppercase(type), type)"
]
We should extract the actual ASTs from these expressions (using Mavo.Script.parse(expression)), classify them by general AST structure (i.e. ignoring the specific names, operators, etc).
Here is some code to map an AST to a generalized AST (an AAST? 😅):
This is part of #967 but could be more broadly useful for when we make changes to expressions.
Here’s some code to collect a dataset of expressions used in Mavo apps on a page:
Note that this will not take actions expressions into account, but these don't tend to be very syntactically complex anyway.
Example outputs from various pages:
https://mavo.io/demos
https://mavo.io/demos/todo
https://mavo.io/demos/svgpath/
https://mavo.io/demos/mortgage/
https://mavo.io/demos/logo/
https://mavo.io/demos/eshop/
https://mavo.io/demos/foodie/
https://dmitrysharabin.github.io/mavo-memory-game/
https://dmitrysharabin.github.io/mavo-wordle/
Step 1: Expand dataset
Just like I did above, collect even more examples, and create a combined dataset
It may be useful to store URL with each expression as well.
Step 2: Classify by AST structure
Many of these expressions don't each us anything new.
For example, the following expressions all have the same general AST structure:
…which is:
We should extract the actual ASTs from these expressions (using
Mavo.Script.parse(expression)
), classify them by general AST structure (i.e. ignoring the specific names, operators, etc).Here is some code to map an AST to a generalized AST (an AAST? 😅):
This can be then serialized to JSON and used as a string key.
The text was updated successfully, but these errors were encountered: