-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
~R is deprecated in favour of ~r (#476)
* ~R is deprecated in favor of ~r * map_join/3 refactor * readability refactors * changed with syntax, refactored cond -> if/else
- Loading branch information
Showing
12 changed files
with
222 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
defmodule Earmark.Parser.Helpers.LeexHelpers do | ||
|
||
@moduledoc false | ||
@doc """ | ||
Allows to lex an Elixir string with a leex lexer and returns | ||
the tokens as needed for a yecc parser. | ||
""" | ||
def lex text, with: lexer do | ||
def lex(text, with: lexer) do | ||
case text | ||
|> String.to_charlist() | ||
|> lexer.string() do | ||
{:ok, tokens, _} -> tokens | ||
end | ||
|> String.to_charlist() | ||
|> lexer.string() do | ||
{:ok, tokens, _} -> tokens | ||
end | ||
end | ||
|
||
def tokenize line, with: lexer do | ||
def tokenize(line, with: lexer) do | ||
{:ok, tokens, _} = | ||
line | ||
|> to_charlist() | ||
|> lexer.string() | ||
elixirize_tokens(tokens,[]) | ||
line | ||
|> to_charlist() | ||
|> lexer.string() | ||
|
||
elixirize_tokens(tokens, []) | ||
|> Enum.reverse() | ||
end | ||
|
||
defp elixirize_tokens(tokens, rest) | ||
defp elixirize_tokens([], result), do: result | ||
defp elixirize_tokens([{token, _, text}|rest], result), do: elixirize_tokens(rest, [{token,to_string(text)}|result]) | ||
|
||
defp elixirize_tokens([{token, _, text} | rest], result), | ||
do: elixirize_tokens(rest, [{token, to_string(text)} | result]) | ||
end | ||
|
||
# SPDX-License-Identifier: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.