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

Text Escaping #102

Open
justinpombrio opened this issue May 6, 2024 · 0 comments
Open

Text Escaping #102

justinpombrio opened this issue May 6, 2024 · 0 comments
Labels

Comments

@justinpombrio
Copy link
Owner

justinpombrio commented May 6, 2024

Desired Behavior

In a JSON string:

  • " inserts a quote, displayed as ", printed as \", treated as a single char in text navigation.
  • \ opens a menu, \n inserts a newline, displayed as \n, printed as \n, treated as a single char in text navigation.
  • \\ inserts a backslash, displayed as , represented as \\, printed as \\, treated as a single char in text navigation.

Data Structures

  • Each texty construct has a replacement table (one table may be shared by multiple constructs):
    - A string entry has a src and display string, saying that occurrences of src in source text should be treated as a single character, and displayed as display.
    - A regex entry has a src Regex and a display template. The template can use $n to refer to the regex's n'th capture group. Behaves like the (potentially infinite) set of string replacements that stands for.
    - A ban list gives a set of characters that may start escape sequences and cannot be entered on their own.
  • Each Text has:
    • A source string, and an index into it.
    • An optional display string and an index into it. If None, it's implied to be identical to the source string.

Code

  • To navigate right, check if there's a source pattern in the replacement table for this construct. If so, skip that many bytes in the source string and a number of bytes equal to the size of the replacement in the display string.
  • To navigate left, do the same but checking if something in the replacement table matches on the left. This is annoying for Regexes: each Regex will need a compiled version that starts with $ and one that ends with ^.
  • To delete, do the same as navigating left, but modify the string to remove the matches.
  • To insert a single character, call Text.insert_char(), which errors if the character is in the ban list.
  • To insert an escape sequence, call Text.insert_escape_sequence(), which errors if the sequence does not match something in the replacement table. If it does match, it inserts the src&display matches into the src&display strings. (And sets the display string to Some if it was None.)
  • Text.as_str() becomes Text.as_source_str() and Text.as_display_str(). If the display string is None, as_display_str() references the source string (as they're implied to be equal).
  • unwrap_text() returns as_source_str() or as_display_str() depending on the mode.
  • path_to_root() also returns either as_source_str() or as_display_str() depending on the mode. I think.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant