From 19d049d84a652d1f3dbd557cca1360a0c079466a Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sat, 24 Feb 2024 11:53:06 -0500 Subject: [PATCH] refactor: superficial stuff --- lib/spitfire.ex | 102 ++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/spitfire.ex b/lib/spitfire.ex index 1698f5d..641def0 100644 --- a/lib/spitfire.ex +++ b/lib/spitfire.ex @@ -299,7 +299,7 @@ defmodule Spitfire do nil -> {left, parser} - ^do_block when parser.nestings != 0 -> + ^do_block when parser.nesting != 0 -> {left, next_token(parser)} _ -> @@ -319,9 +319,9 @@ defmodule Spitfire do else orig_meta = current_meta(parser) parser = parser |> next_token() |> eat_eol() - old_nestings = parser.nestings + old_nesting = parser.nesting - parser = Map.put(parser, :nestings, 0) + parser = Map.put(parser, :nesting, 0) {expression, parser} = parse_expression(parser, @lowest, false, false, true) @@ -332,7 +332,7 @@ defmodule Spitfire do peek_token(parser) == :")" || (peek_token(parser) == :eol && peek_token(next_token(parser)) == :")") -> parser = parser - |> Map.put(:nestings, old_nestings) + |> Map.put(:nesting, old_nesting) |> next_token() |> eat_eol() @@ -416,7 +416,7 @@ defmodule Spitfire do if peek_token(parser) == :")" do parser = parser - |> Map.put(:nestings, old_nestings) + |> Map.put(:nesting, old_nesting) |> next_token() exprs = [expression | exprs] @@ -437,7 +437,7 @@ defmodule Spitfire do parser = parser |> put_error({meta, "missing closing parentheses"}) - |> Map.put(:nestings, old_nestings) + |> Map.put(:nesting, old_nesting) {{:__error__, meta, ["missing closing parentheses"]}, next_token(parser)} end @@ -448,7 +448,7 @@ defmodule Spitfire do parser = parser |> put_error({meta, "missing closing parentheses"}) - |> Map.put(:nestings, old_nestings) + |> Map.put(:nesting, old_nesting) {{:__error__, meta, ["missing closing parentheses"]}, next_token(parser)} end @@ -678,8 +678,8 @@ defmodule Spitfire do parser = eat_at(parser, :eol, 1) - old_nestings = parser.nestings - parser = Map.put(parser, :nestings, 0) + old_nesting = parser.nesting + parser = Map.put(parser, :nesting, 0) {exprs, parser} = while2 Map.get(parser, :stab_state) == nil and peek_token(parser) not in [:eof, :end, :")", :block_identifier] <- @@ -712,7 +712,7 @@ defmodule Spitfire do ast = {token, meta, [lhs, rhs]} - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) {ast, eat_eol(parser)} end @@ -845,8 +845,8 @@ defmodule Spitfire do type = encode_literal(parser, :do, meta) parser = parser |> next_token() |> eat_eol() - old_nestings = parser.nestings - parser = Map.put(parser, :nestings, 0) + old_nesting = parser.nesting + parser = Map.put(parser, :nesting, 0) {exprs, {_, parser}} = while2 current_token(parser) not in [:end, :eof] <- {type, parser} do @@ -936,7 +936,7 @@ defmodule Spitfire do {token, [do: do_meta, end: end_meta] ++ meta, args ++ [exprs]} end - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) {ast, parser} end @@ -1184,7 +1184,7 @@ defmodule Spitfire do tokens: tokens ++ [:eof], current_token: nil, peek_token: nil, - nestings: 0, + nesting: 0, errors: [], literal_encoder: parser.literal_encoder } @@ -1251,7 +1251,7 @@ defmodule Spitfire do tokens: tokens ++ [:eof], current_token: nil, peek_token: nil, - nestings: 0, + nesting: 0, errors: [], literal_encoder: parser.literal_encoder } @@ -1387,12 +1387,12 @@ defmodule Spitfire do newlines = peek_newlines(parser) parser = parser |> next_token() |> eat_eol() - old_nestings = parser.nestings - parser = Map.put(parser, :nestings, 0) + old_nesting = parser.nesting + parser = Map.put(parser, :nesting, 0) if current_token(parser) == :"}" do closing = current_meta(parser) - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) extra = if newlines do @@ -1417,7 +1417,7 @@ defmodule Spitfire do end closing = current_meta(parser) - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) extra = if newlines do @@ -1513,13 +1513,13 @@ defmodule Spitfire do parser = eat_eol(parser) - old_nestings = parser.nestings - parser = Map.put(parser, :nestings, 0) + old_nesting = parser.nesting + parser = Map.put(parser, :nesting, 0) if current_token(parser) == :"}" do closing = current_meta(parser) ast = {:%, meta, [type, {:%{}, newlines ++ [{:closing, closing} | brace_meta], []}]} - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) {ast, parser} else {pairs, parser} = parse_comma_list(parser, @list_comma, false, true) @@ -1537,7 +1537,7 @@ defmodule Spitfire do closing = current_meta(parser) ast = {:%, meta, [type, {:%{}, newlines ++ [{:closing, closing} | brace_meta], pairs}]} - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) {ast, parser} end end @@ -1548,13 +1548,13 @@ defmodule Spitfire do newlines = peek_newlines(parser) parser = parser |> next_token() |> eat_eol() - old_nestings = parser.nestings - parser = Map.put(parser, :nestings, 0) + old_nesting = parser.nesting + parser = Map.put(parser, :nesting, 0) cond do current_token(parser) == :"}" -> closing = current_meta(parser) - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) extra = if newlines do @@ -1578,7 +1578,7 @@ defmodule Spitfire do |> put_in([:peek_token], parser.current_token) |> update_in([:tokens], &[parser.peek_token | &1]) - parser = put_in(parser.nestings, old_nestings) + parser = put_in(parser.nesting, old_nesting) {{:{}, meta, []}, parser} true -> @@ -1620,11 +1620,11 @@ defmodule Spitfire do if length(pairs) == 2 do tuple = encode_literal(parser, pairs |> List.wrap() |> List.to_tuple(), orig_meta) - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) {tuple, parser} else closing = current_meta(parser) - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) extra = if newlines do @@ -1642,12 +1642,12 @@ defmodule Spitfire do meta = current_meta(parser) orig_parser = parser parser = parser |> next_token() |> eat_eol() - old_nestings = parser.nestings - parser = Map.put(parser, :nestings, 0) + old_nesting = parser.nesting + parser = Map.put(parser, :nesting, 0) cond do current_token(parser) == :"]" -> - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) {encode_literal(parser, [], orig_meta), parser} current_token(parser) in [:end, :"}", :")", :">>"] -> @@ -1663,7 +1663,7 @@ defmodule Spitfire do |> put_in([:peek_token], parser.current_token) |> update_in([:tokens], &[parser.peek_token | &1]) - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) {encode_literal(parser, [], orig_meta), parser} true -> @@ -1673,7 +1673,7 @@ defmodule Spitfire do case peek_token(parser) do :"]" -> - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) {encode_literal(parser, pairs, orig_meta), next_token(parser)} _ -> @@ -1700,7 +1700,7 @@ defmodule Spitfire do {pairs, _} = pairs |> Enum.reverse() |> Enum.unzip() - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) {encode_literal(parser, List.wrap(pairs), orig_meta), parser} end end @@ -1717,8 +1717,8 @@ defmodule Spitfire do closing = current_meta(parser) {{token, newlines ++ [{:closing, closing} | meta], []}, parser} else - old_nestings = parser.nestings - parser = Map.put(parser, :nestings, 0) + old_nesting = parser.nesting + parser = Map.put(parser, :nesting, 0) {pairs, parser} = parser @@ -1726,7 +1726,7 @@ defmodule Spitfire do |> eat_eol() |> parse_comma_list() - parser = Map.put(parser, :nestings, old_nestings) + parser = Map.put(parser, :nesting, old_nesting) parser = eat_at(parser, :eol, 1) @@ -1804,16 +1804,16 @@ defmodule Spitfire do {args, parser} = while2 peek_token(parser) == :"," <- parser do - parser = parser |> next_token() |> next_token() - {arg, parser} = parse_expression(parser) - - {arg, parser} + parser + |> next_token() + |> next_token() + |> parse_expression() end args = [front | args] parser = pop_nesting(parser) - if parser.nestings == 0 && current_token(parser) == :do do + if parser.nesting == 0 && current_token(parser) == :do do parse_do_block(parser, {token, meta, args}) else meta = @@ -1832,12 +1832,12 @@ defmodule Spitfire do meta = current_meta(parser) parser = next_token(parser) - # if nesting is empty, that means we are not currently an argument for a function call + # if nesting is 0, that means we are not currently an argument for a function call # and can assume we are a "lone do_identifier" and parse the block # foo do # :ok # end - if parser.nestings == 0 do + if parser.nesting == 0 do parse_do_block(parser, {token, meta, []}) else {{token, meta, nil}, parser} @@ -1929,7 +1929,7 @@ defmodule Spitfire do tokens: tokens ++ [:eof], current_token: nil, peek_token: nil, - nestings: 0, + nesting: 0, literal_encoder: parser.literal_encoder } |> next_token() @@ -1958,7 +1958,7 @@ defmodule Spitfire do tokens: tokenize(code, opts), current_token: nil, peek_token: nil, - nestings: 0, + nesting: 0, literal_encoder: Keyword.get(opts, :literal_encoder), errors: [] } @@ -2294,12 +2294,12 @@ defmodule Spitfire do Map.get(@precedences, peek_token_type(parser), @lowest) end - defp pop_nesting(%{nestings: nestings} = parser) do - %{parser | nestings: nestings - 1} + defp pop_nesting(%{nesting: nesting} = parser) do + %{parser | nesting: nesting - 1} end - defp push_nesting(%{nestings: nestings} = parser) do - %{parser | nestings: nestings + 1} + defp push_nesting(%{nesting: nesting} = parser) do + %{parser | nesting: nesting + 1} end defp encode_literal(%{literal_encoder: encoder} = parser, literal, {line, col, _}) when is_function(encoder) do