Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LexRaku confuses an object attribute named y with the y/// operator #238

Open
pryrt opened this issue Apr 13, 2024 · 1 comment
Open

LexRaku confuses an object attribute named y with the y/// operator #238

pryrt opened this issue Apr 13, 2024 · 1 comment
Labels
raku Caused by the raku lexer

Comments

@pryrt
Copy link

pryrt commented Apr 13, 2024

the Raku lexer is confused by an object attribute of y or tr. In certain syntax, LexRaku interprets it as the y/// or tr/// operator, not the attribute of the object instance obj.

verified using: SciTE 5.4.3 Scintilla:5.4.3 Lexilla:5.3.1:
image

code to lex(from https://uzluisf.gitlab.io/raku-by-example/classes-and-objects):

class Point2D {
    has Str $!id = 'P2'; # private attr. with default value
    has Numeric $.x;     # attr. with read-only accesor
    has Numeric $.y;     # same as above
}

# Initializing an object instance. Private attributes
# cannot be initialized during object construction.
my $p1 = Point2D.new(x => 3, y => 4);

say "x: ", $p1.x; # invoking the read-only accessor
say "y: ", $p1.y; # same as above

# An attribute with a read-only accesor cannot be modified
# from outside the class. To do so, add the `is rw` trait 
# to make it read-write. For example: `has Numeric $.x is rw;`

# this semicolon ends the y/// operation;

say "ok";

(to maintain compatiblity with Perl, Raku still has y/// as an alias of the tr/// operator . I confirmed that .tr behaves identically to .y in the examples above)

@nyamatongwe nyamatongwe added the raku Caused by the raku lexer label Apr 13, 2024
@nyamatongwe
Copy link
Member

For say "y: ", $p1.y;, it is checking the next character ';' with IsValidRegOrQAdjacent which allows most punctuation including ; to be the delimiter and then switching to style SCE_RAKU_REGEX. So y;dol;wne; is a valid translation to the lexer.

Even space is valid to IsValidRegOrQAdjacent so y is treated as the start of a translation but is then stopped early inside ProcessValidRegQlangStart.

It is possible that the set of valid delimiters for y and tr operators is more constrained than for rx and IsValidRegOrQAdjacent or its caller should check that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
raku Caused by the raku lexer
Projects
None yet
Development

No branches or pull requests

2 participants