@@ -4,17 +4,20 @@ defmodule Gradient.Tokens do
44 """
55 alias Gradient.Types , as: T
66
7- @ doc """
8- Drop tokens to the first conditional occurrence. Returns type of the encountered
9- conditional and the following tokens.
10- """
11- @ spec get_conditional ( T . tokens ( ) , integer ( ) , T . options ( ) ) ::
7+ @ typedoc "Type of conditional with following tokens"
8+ @ type conditional_t ( ) ::
129 { :case , T . tokens ( ) }
1310 | { :cond , T . tokens ( ) }
1411 | { :unless , T . tokens ( ) }
1512 | { :if , T . tokens ( ) }
1613 | { :with , T . tokens ( ) }
1714 | :undefined
15+
16+ @ doc """
17+ Drop tokens to the first conditional occurrence. Returns type of the encountered
18+ conditional and the following tokens.
19+ """
20+ @ spec get_conditional ( T . tokens ( ) , integer ( ) , T . options ( ) ) :: conditional_t ( )
1821 def get_conditional ( tokens , line , opts ) do
1922 conditionals = [ :if , :unless , :cond , :case , :with ]
2023 { :ok , limit_line } = Keyword . fetch ( opts , :end_line )
@@ -38,7 +41,7 @@ defmodule Gradient.Tokens do
3841 @ spec get_list ( T . tokens ( ) , T . options ( ) ) ::
3942 { :list , T . tokens ( ) } | { :keyword , T . tokens ( ) } | { :charlist , T . tokens ( ) } | :undefined
4043 def get_list ( tokens , opts ) do
41- tokens = flat_tokens ( tokens )
44+ tokens = flatten_tokens ( tokens )
4245 { :ok , limit_line } = Keyword . fetch ( opts , :end_line )
4346
4447 res =
@@ -148,26 +151,26 @@ defmodule Gradient.Tokens do
148151 end
149152
150153 @ doc """
151- Flat the tokens, mostly binaries or string interpolation.
154+ Flatten the tokens, mostly binaries or string interpolation.
152155 """
153- @ spec flat_tokens ( T . tokens ( ) ) :: T . tokens ( )
154- def flat_tokens ( tokens ) do
155- Enum . map ( tokens , & flat_token / 1 )
156+ @ spec flatten_tokens ( T . tokens ( ) ) :: T . tokens ( )
157+ def flatten_tokens ( tokens ) do
158+ Enum . map ( tokens , & flatten_token / 1 )
156159 |> Enum . concat ( )
157160 end
158161
159162 # Private
160163
161- defp flat_token ( token ) do
164+ defp flatten_token ( token ) do
162165 case token do
163166 { :bin_string , _ , [ s ] } = t when is_binary ( s ) ->
164167 [ t ]
165168
166169 { :bin_string , _ , ts } ->
167- flat_tokens ( ts )
170+ flatten_tokens ( ts )
168171
169172 { { _ , _ , nil } , { _ , _ , nil } , ts } ->
170- flat_tokens ( ts )
173+ flatten_tokens ( ts )
171174
172175 str when is_binary ( str ) ->
173176 [ { :str , { 0 , 0 , nil } , str } ]
0 commit comments