Teacher tool: field value validator added #9867
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A validator that checks the field values of a block has been added to our validator library. Field values are a specific type of input for a block. The easiest type that I can demonstrate is the different operators that are associated with the
math_arithmetic
block. In this case, the field value type is "OP" or, I'm guessing, the shorthand for operation. Some others that I've seen inblocklycompiler.ts
are:TEXT, EXPRESSION, VAR, BOOL, NAME, VALUE
and more. The "OP" field value for themath_arithmetic
block can beADD, MINUS, MULTIPLY, DIVIDE
and more.You'll see that the validation I made for
logic_compare
is looking for something very specific. Thelogic_compare
blocks in the following program don't pass because the one that has theEQ
"OP" type doesn't have twomath_number
blocks, and the other that has two numbers has a different "OP" type.Edit: And to show that it can pass lol
One thing to note about this approach is that if we want to support any type of field value, we need to know that field value's name and possible values it can be before we can create the validator for it. @riknoll chatted with me and let me know that this will require quite a bit of work because all of our custom blocks have field value names that are going to be tricky to find. He recommended a way for me to find the different field values, which isn't hard, just tedious. I'm planning on making a table in OneNote that will have the relationship between a block, it's field value names, and the variations that a specific field value can have. For now, I'm planning to build this table as I go, but we might reach a time when we'll want to just fill the table as earnestly as possible.