lark-parser / Lark.js

Live port of Lark's standalone parser to Javascript
MIT License
71 stars 12 forks source link

`isupper` bug #43

Open thekevinscott opened 6 months ago

thekevinscott commented 6 months ago

The javascript definition of isupper is defined here:

function isupper(a) {
  return /^[A-Z_$]*$/.test(a);
}

This is slightly different from the Python implementation, with respect to digits:

'__IGNORE_0'.isupper()
# True
/^[A-Z_$]*$/.test('__IGNORE_0');
// false

The regex should be updated to /^[A-Z0-9_$]*$/

erezsh commented 6 months ago

Okay, thanks for reporting it!

It still isn't right, because in Python '0'.isupper() == False. But you're right that it needs fixing.

thekevinscott commented 6 months ago

Ah, very true. Good catch!

https://docs.python.org/3/library/stdtypes.html#str.isupper

Return True if all cased characters [4] in the string are uppercase and there is at least one cased character, False otherwise.

It sounds like the main edge case is that there must be one cased character.

I opened a PR here that adds test cases that I think covers all the edge cases: https://github.com/lark-parser/Lark.js/pull/45