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

Add readtoeof #200

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/interp/commands/special_interp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ defmodule Interp.SpecialInterp do
"I" -> {Stack.push(stack, InputHandler.read_input()), environment}
"$" -> {Stack.push(Stack.push(stack, 1), InputHandler.read_input()), environment}
"Î" -> {Stack.push(Stack.push(stack, 0), InputHandler.read_input()), environment}
".|" -> {Stack.push(stack, InputHandler.read_until_eof()), environment}
"|" -> {Stack.push(stack, InputHandler.read_until_newline()), environment}
"#" ->
{element, new_stack, environment} = Stack.pop(stack, environment)
Expand Down
18 changes: 17 additions & 1 deletion lib/reading/input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,20 @@ defmodule Reading.InputHandler do
true -> read_until_newline([String.trim_trailing(input, "\n") | acc])
end
end
end

def read_until_eof() do
result = read_until_eof([]) |> Enum.reverse
global_env = Globals.get()
Globals.set(%{global_env | inputs: global_env.inputs ++ [result]})
result
end

defp read_until_eof(acc) do
input = IO.read(:stdio, :line)
cond do
input == :eof -> acc
input == "\n" -> read_until_eof(["" | acc])
true -> read_until_eof([String.trim_trailing(input, "\n") | acc])
end
end
end
2 changes: 1 addition & 1 deletion lib/reading/reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Reading.Reader do
def ternary_ops, do: regexify ["ǝ", "Š", "‡", ":", "Λ", ".Λ", ".:", ".;"]

def special_ops, do: regexify [")", "r", "©", "¹", "²", "³", "I", "$", "Î", "#", "Ÿ", "ø", "ζ", "ι", "¿",
"ã", "M", ".¿", ".V", "₅", "₆", "|", ".Æ"]
"ã", "M", ".¿", ".V", "₅", "₆", "|", ".|", ".Æ"]

def subprogram_ops, do: regexify ["ʒ", "ε", "Δ", "Σ", "F", "G", "v", "ƒ", "µ", "[", "i", "λ", ".γ", ".¡", ".Δ",
"ÅΔ", "E", ".æ", ".Γ", "Å»", "Å«", "Å€", ".¬", "ÅÏ"]
Expand Down
Loading