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
I'm sure we can improve error detection and messages for the parser, especially so it better integrates with @ethan-ou 's extensions.
For example, I was playing around with how the weight part of a MC question's answer is parsed. This is more user-friendly:
Weight "(weight)"
= '%' percent:(PercentValue) '%' {
return percent;
}
PercentValue "(percent)"
= percent:(!'%' .)* {
let error = 'a value between -100 and 100'
console.log(percent.length)
if (percent.length == 0) expected(error + ' (did you forget to put a value?)');
// the !'%` shows up as a 0th element in the percent array (of arrays), so we have to joing the 1th elements
const pct = parseFloat(percent.map(innerArray => innerArray[1]).join(""));
console.log(pct)
if (pct >= -100 && pct <= 100) {
return pct;
} else {
expected(error)
}
}
The use of expected() can help a lot.
Also, we can write better tests with Jest, where an error message is expected for different cases. For now, the tests only check for valid parsing.
We could, for example, test for the proper error when a percentage value is missing:
Or is out of range:
~%150.0% here's an answer # feedback
Or is invalid:
~%blah% here's an answer # feedback ~%-17.w% here's an answer # feedback
etc.
The text was updated successfully, but these errors were encountered:
I'm sure we can improve error detection and messages for the parser, especially so it better integrates with @ethan-ou 's extensions.
For example, I was playing around with how the weight part of a MC question's answer is parsed. This is more user-friendly:
The use of
expected()
can help a lot.Also, we can write better tests with Jest, where an error message is expected for different cases. For now, the tests only check for valid parsing.
We could, for example, test for the proper error when a percentage value is missing:
Or is out of range:
~%150.0% here's an answer # feedback
Or is invalid:
~%blah% here's an answer # feedback
~%-17.w% here's an answer # feedback
etc.
The text was updated successfully, but these errors were encountered: