tshet-uinh-js
tshet-uinh-js copied to clipboard
Template overload for `.調整`
Badly written 😕
@syimyuzya (Well, first of all, do you think we ever need this? I guess you and Ayaka may find this feature redundant?)
More on the expression syntax for .屬於
:
When I rewrote .屬於
, I intentionally made it only accept whole predicates to avoid too much complexity and difficult design choices in its syntax. Examples be like:
- Should we accept
重紐${'A'}類
? Why or why not? If so, should we also accept${'重紐A'}類
, or重${'紐A'}類
? (:herb: - Should we accept
${() => cond ? '見' : ''}影母
? How about影${() => cond ? '見' : ''}母
? - Should we accept
清${() => cond ? '母' : '韻'}
? - How should we parse
${() => true}影母
? Is it a valid expression (true
&&影母
), or is it invalid? - Should we accept
${() => '去' : '仄'}聲
? (note that仄聲
is not a basic 音韻屬性) If so, should we also accept陽${() => cond ? '' : '聲'}韻
? (:herb:
:joy::joy:
@syimyuzya (Well, first of all, do you think we ever need this? I guess you and Ayaka may find this feature redundant?)
I think it's not redundant at least (except for the template part, maybe that's overkill :see_no_evil:). Not sure how much it's need either, though.
.調整
is currently the only method where users have to write like { 聲: '去' }
but not the more natural '去聲'
(other methods have, for example, from描述
instead of the constructor, 屬於
instead of ===
or [...].includes
), this PR just fills the gap.
except for the template part, maybe that's overkill
The expression syntax for .調整
is quite restricted and much simpler than .屬於
(in particular, no logical operators, parentheses or sub-expressions), so IMO the ordinary string template (.調整(`${'見'}母`)
) should suffice already, and there is not much to benefit from special handling of template arguments.
IMO:
- Should we accept
重紐${'A'}類
? Why or why not? If so, should we also accept${'重紐A'}類
, or重${'紐A'}類
? (🌿
Accept 重紐${'A'}類
but not ${'重紐A'}類
or 重${'紐A'}類
.
- Should we accept
${() => cond ? '見' : ''}影母
? How about影${() => cond ? '見' : ''}母
?
I would probably only accept ${() => cond ? '見影' : '影'}母
if you didn't mention them, but it seems to be reasonable to accept them.
- Should we accept
清${() => cond ? '母' : '韻'}
?
Yes for me. At least, the current implementation of .調整
accepts 清${cond ? '母' : '韻'}
.
- How should we parse
${() => true}影母
? Is it a valid expression (true
&&影母
), or is it invalid?
Should be OK to keep it valid.
- Should we accept
${() => '去' : '仄'}聲
? (note that仄聲
is not a basic 音韻屬性) If so, should we also accept陽${() => cond ? '' : '聲'}韻
? (🌿
I am neutral to ${() => cond ? '去' : '仄'}聲
(in fact it seems that I made it invalid for simplicity in the past 😂😂), but 陽${() => cond ? '' : '聲'}韻
should definitely be rejected.
And please complete the documentation for me, I am too lazy, please forgive me, @syimyuzya
3. Should we accept
${() => cond ? '見' : ''}影母
? How about影${() => cond ? '見' : ''}母
?I would probably only accept
${() => cond ? '見影' : '影'}母
if you didn't mention them, but it seems to be reasonable to accept them.
7. How should we parse
${() => true}影母
? Is it a valid expression (true
&&影母
), or is it invalid?Should be OK to keep it valid.
Note the syntactic ambiguity here: How should we then handle 來母 或 ${() => cond ? '見' : true }影組
? 😂
Be aware that:
- The type of a lazy template argument cannot be predicted until it gets evaluated;
- We can't just let lazy arguments affect the (already parsed) syntax tree, even in this simple case; otherwise it would bring more surprises.