Skip to content

Commit

Permalink
refactor: move function
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Feb 11, 2024
1 parent 510180b commit 47de42c
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions lib/spitfire.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,47 @@ defmodule Spitfire do
tokens ++ [:eof]
end

def parse_interpolation(parser, tokens) do
args =
for token <- tokens do
case token do
token when is_binary(token) ->
token

{{line, col, _}, {cline, ccol, _}, tokens} ->
meta = [line: line, column: col]

# construct a new parser
ast =
if tokens == [] do
{:__block__, [], []}
else
parser = %{
tokens: tokens ++ [:eof],
current_token: nil,
peek_token: nil,
nestings: [],
errors: [],
literal_encoder: parser.literal_encoder,
stab_depth: 0
}

{ast, _parser} = parse_expression(parser |> next_token() |> next_token() |> eat_eol())
ast
end

{:"::", meta,
[
{{:., meta, [Kernel, :to_string]},
[from_interpolation: true, closing: [line: cline, column: ccol]] ++ meta, [ast]},
{:binary, meta, nil}
]}
end
end

{args, parser}
end

def new(code, opts) do
%{
tokens: tokenize(code, opts),
Expand Down Expand Up @@ -2342,45 +2383,4 @@ defmodule Spitfire do
{:__block__, [], Enum.reverse(exprs)}
end
end

def parse_interpolation(parser, tokens) do
args =
for token <- tokens do
case token do
token when is_binary(token) ->
token

{{line, col, _}, {cline, ccol, _}, tokens} ->
meta = [line: line, column: col]

# construct a new parser
ast =
if tokens == [] do
{:__block__, [], []}
else
parser = %{
tokens: tokens ++ [:eof],
current_token: nil,
peek_token: nil,
nestings: [],
errors: [],
literal_encoder: parser.literal_encoder,
stab_depth: 0
}

{ast, _parser} = parse_expression(parser |> next_token() |> next_token() |> eat_eol())
ast
end

{:"::", meta,
[
{{:., meta, [Kernel, :to_string]},
[from_interpolation: true, closing: [line: cline, column: ccol]] ++ meta, [ast]},
{:binary, meta, nil}
]}
end
end

{args, parser}
end
end

0 comments on commit 47de42c

Please sign in to comment.