Skip to content

Instantly share code, notes, and snippets.

@aartaka
Last active September 30, 2024 19:55
Show Gist options
  • Save aartaka/dc3dfad2499ffddb638b0ca3d9700417 to your computer and use it in GitHub Desktop.
Save aartaka/dc3dfad2499ffddb638b0ca3d9700417 to your computer and use it in GitHub Desktop.
Read a line of chars with escape sequences like \n, \t, \a, \b, \r
[-][Initial memory layout:
[0][case flag(0)][char]
After some iterations:
[processed ...][0][case flag][char]]
>>,----- -----
[main read loop
<+> set case flag
backslash (92)
----- ----- ----- ----- ----- ----- ----- -----
----- ----- ----- ----- ----- ----- ----- ----- --
[unless backslash restore and copy
[<<+>>-]
<< ++ +++++ +++++ +++++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++ +++++ +++++ +++++ +++++
>-> kill flag and go back to empty char
]
<[if backslash
>, read escaped char
\a (bell)
----- ----- ----- ----- ----- -----
----- ----- ----- ----- ----- -----
----- ----- ----- ----- ----- -----
----- --
[- \b (backspace)
[----- ----- -- \n (newline)
[---- \r (carriage return)
[-- \t (horizontal tab)
[default case:
<-> kill flag
[<<+>>-] copy the char
restore the char as it was
<< + +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++ >>
]
case \t: kill flag and insert tab
<[-<+++++ ++++>]>
]
case \r: kill flag and insert return
<[-<+++++ +++++ +++>]>
]
case \n: kill flag and insert newline
<[-<+++++ +++++>]>
]
case \b: kill flag and insert backspace
<[-<+++++ +++++ ++>]>
]
case \a: kill flag and insert bell
<[-<+++++ ++>] also skip the last move
]
>>,----- -----] loop until newline
<<<[<]> back to line start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment