diff --git a/lib/interp/commands/special_interp.ex b/lib/interp/commands/special_interp.ex index a2b36ec..8b09334 100644 --- a/lib/interp/commands/special_interp.ex +++ b/lib/interp/commands/special_interp.ex @@ -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) diff --git a/lib/reading/input.ex b/lib/reading/input.ex index a13f36b..a0c4937 100644 --- a/lib/reading/input.ex +++ b/lib/reading/input.ex @@ -53,4 +53,20 @@ defmodule Reading.InputHandler do true -> read_until_newline([String.trim_trailing(input, "\n") | acc]) end end -end \ No newline at end of file + + 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 diff --git a/lib/reading/reader.ex b/lib/reading/reader.ex index e00ee2d..4eb58ce 100644 --- a/lib/reading/reader.ex +++ b/lib/reading/reader.ex @@ -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", ".æ", ".Γ", "Å»", "Å«", "Å€", ".¬", "ÅÏ"]