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

[Feature] LexicalMap #266

Closed
dishmint opened this issue Mar 15, 2023 · 6 comments · Fixed by #275
Closed

[Feature] LexicalMap #266

dishmint opened this issue Mar 15, 2023 · 6 comments · Fixed by #275
Assignees

Comments

@dishmint
Copy link
Owner

Apply a StringReplace of a certain function on lexical patterns

LexicalMap[f, expr, lp]

LexicalMap[ToUpperCase, "This is cool", TextType["Adjective"] | TextType["Verb"]]

(* expected output *)
"This IS COOL"
@dishmint dishmint self-assigned this Mar 16, 2023
@dishmint
Copy link
Owner Author

And of course with a levelspec: LexicalMap[f, expr, lp, pos]

@dishmint
Copy link
Owner Author

Wait, level spec doesn't make any sense, expr is a string..

@dishmint
Copy link
Owner Author

Simple enough to implement.

@dishmint
Copy link
Owner Author

dishmint commented Jun 10, 2023

This already works with StringReplace, though I like the design of Map.

LexicalMap[ToUpperCase, "This is cool", TextType["Adjective"|"Verb"]]

vs

StringReplace["This is cool", LexicalPattern[match:TextType["Adjective"|"Verb"] :> ToUpperCase[match]]]

@dishmint
Copy link
Owner Author

I've implemented it, but some longstanding behavior has reared its head. Note what gets replaced around "is cool" the spacing is inconsistent. an adjective text type should match just the text type and the spaces, but only bind to the word.

Image

@dishmint
Copy link
Owner Author

Maybe setting the MatchTrim option in the StringReplace UpValue?

dishmint added a commit that referenced this issue Jun 11, 2023
dishmint added a commit that referenced this issue Jun 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant