Skip to content
Permalink
Browse files

use chained pattern matching to assign token

  • Loading branch information
Maples7 committed Jun 16, 2019
1 parent 9af5145 commit 456d3d4c4f26919055c18a7d2ff233437530f553
Showing with 9 additions and 9 deletions.
  1. +1 −1 .credo.exs
  2. +8 −8 lib/field_mask.ex
@@ -76,7 +76,7 @@
{Credo.Check.Readability.TrailingBlankLine},
{Credo.Check.Readability.TrailingWhiteSpace},
{Credo.Check.Readability.VariableNames},
{Credo.Check.Refactor.ABCSize, max_size: 80},
{Credo.Check.Refactor.ABCSize, max_size: 100},
# {Credo.Check.Refactor.CaseTrivialMatches}, # deprecated in 0.4.0
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.FunctionArity, max_arity: 6},
@@ -191,21 +191,21 @@ defmodule FieldMask do
def parse(tokens) do
tokens
|> Enum.reduce({%{}, [], [], nil}, fn
",", {tree, path, stack, last_token} ->
"," = token, {tree, path, stack, last_token} ->
if List.first(stack) === "/" do
{tree, tl(path), tl(stack), ","}
{tree, tl(path), tl(stack), token}
else
{tree, path, stack, last_token}
end

"/", {tree, path, stack, last_token} ->
{tree, [last_token | path], ["/" | stack], "/"}
"/" = token, {tree, path, stack, last_token} ->
{tree, [last_token | path], [token | stack], token}

"(", {tree, path, stack, last_token} ->
{tree, [last_token | path], ["(" | stack], "("}
"(" = token, {tree, path, stack, last_token} ->
{tree, [last_token | path], [token | stack], token}

")", {tree, path, stack, _} ->
{tree, tl(path), [")" | stack], ")"}
")" = token, {tree, path, stack, _} ->
{tree, tl(path), [token | stack], token}

token, {tree, path, stack, _} ->
{put_in(tree, Enum.reverse([token | path]), %{}), path, stack, token}

0 comments on commit 456d3d4

Please sign in to comment.
You can’t perform that action at this time.