red icon indicating copy to clipboard operation
red copied to clipboard

[Parse] lax matching of ANY-WORD! values

Open 9214 opened this issue 7 years ago • 4 comments

Expected behavior

>> parse [a 'a]['a 'a]
== false
>> parse [a 'a]['a quote 'a]
== true

Actual behavior

>> parse [a 'a]['a 'a]
== true
>> parse [a 'a]['a quote 'a]
== true

Steps to reproduce the problem

See above.

Red and platform version

Red 0.6.3 for Windows built 6-Oct-2018/7:28:28+05:00 commit #dafc828

9214 avatar Oct 06 '18 18:10 9214

Possibly related: https://github.com/red/red/issues/3483, https://github.com/red/red/issues/3029

9214 avatar Oct 06 '18 18:10 9214

It's even worse. Given parse [<input>][quote <rule>]:

input 	rule 	result
----------------------
word 	word 	true
word 	'word 	true
word 	:word 	true
word 	word: 	true
'word 	word 	true
'word 	'word 	true
'word 	:word 	true
'word 	word: 	true
:word 	word 	true
:word 	'word 	false
:word 	:word 	true
:word 	word: 	true
word: 	word 	true
word: 	'word 	false
word: 	:word 	true
word: 	word: 	true

The problem is that quote <any-word!> does not enforce COMP_STRICT_EQUAL comparator (both types and symbols are checked for equality) and uses the same comparator as plain lit-word! matching: more permissive COMP_STRICT_EQUAL_WORD (only symbols are checked for lit-word! / word! or word! / lit-word! cases, for other pairings it's the same as COMP_STRICT_EQUAL).

And another problem is this: quote <any-word!> simply cannot enforce COMP_STRICT_EQUAL, because that implies case-sensitive comparison reserved for case keyword and /case refinement.


This is what I expect:

  • For normal matching (i.e. parse ... [<any-word!>]). Row - input, column - rule:
normal w 'w :w w:
w x o x x
'w x x x x
:w x x x x
w: x x x x

In fact, only lit-word! match can happen, the rest are special Parse keywords and should be handled by quote.

  • For parse ... [quote <any-word!>]:
quote w 'w :w w:
w o x x x
'w x o x x
:w x x o x
w: x x x o

And this is the current state of affairs:

normal w 'w :w w:
w x o x x
'w x o x x
:w x x x x
w: x x x x
quote w 'w :w w:
w o o o o
'w o o o o
:w o x o o
w: o x o o

9214 avatar Dec 02 '19 14:12 9214

Nice analysis @9214. :+1:

greggirwin avatar Dec 02 '19 20:12 greggirwin

I keep writing ahead word! 'word instead of 'word everywhere because of this :D

hiiamboris avatar May 15 '22 11:05 hiiamboris