Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace .xrl and .yrl files #474

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/earmark_parser/helpers/lookahead_helpers.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Earmark.Parser.Helpers.LookaheadHelpers do

@moduledoc false

import Earmark.Parser.Helpers.LeexHelpers
Expand All @@ -13,8 +12,7 @@ defmodule Earmark.Parser.Helpers.LookaheadHelpers do
Otherwise `{nil, 0}` is returned
"""
def opens_inline_code(%{line: line, lnb: lnb}) do
# case tokenize(line, with: :string_lexer) |> IO.inspect() |> has_still_opening_backtix(nil) do
case tokenize(line, with: :string_lexer) |> has_still_opening_backtix(nil) do
case tokenize(line, with: :earmark_string_lexer) |> has_still_opening_backtix(nil) do
nil -> {nil, 0}
{_, btx} -> {btx, lnb}
end
Expand All @@ -29,7 +27,8 @@ defmodule Earmark.Parser.Helpers.LookaheadHelpers do
"""
# (#{},{_,_}) -> {_,_}
def still_inline_code(%{line: line, lnb: lnb}, old = {pending, _pending_lnb}) do
case tokenize(line, with: :string_lexer) |> has_still_opening_backtix({:old, pending}) do
case tokenize(line, with: :earmark_string_lexer)
|> has_still_opening_backtix({:old, pending}) do
nil -> {nil, 0}
{:new, btx} -> {btx, lnb}
{:old, _} -> old
Expand Down
27 changes: 19 additions & 8 deletions lib/earmark_parser/parser/link_parser.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Earmark.Parser.Parser.LinkParser do

@moduledoc false
import Earmark.Parser.Helpers.LeexHelpers, only: [tokenize: 2]
import Earmark.Parser.Helpers.YeccHelpers, only: [parse!: 2]
Expand Down Expand Up @@ -28,12 +27,16 @@ defmodule Earmark.Parser.Parser.LinkParser do

@doc false
def parse_link(src, lnb) do
case parse!(src, lexer: :link_text_lexer, parser: :link_text_parser) do
{link_or_img, link_text, parsed_text} ->
beheaded = behead(src, to_string(parsed_text))
tokens = tokenize(beheaded, with: :link_text_lexer)
p_url(tokens, lnb) |> make_result(to_string(link_text), to_string(parsed_text), link_or_img)
_ -> nil
case parse!(src, lexer: :earmark_link_text_lexer, parser: :earmark_link_text_parser) do
{link_or_img, link_text, parsed_text} ->
beheaded = behead(src, to_string(parsed_text))
tokens = tokenize(beheaded, with: :earmark_link_text_lexer)

p_url(tokens, lnb)
|> make_result(to_string(link_text), to_string(parsed_text), link_or_img)

_ ->
nil
end
end

Expand Down Expand Up @@ -61,14 +64,19 @@ defmodule Earmark.Parser.Parser.LinkParser do
# All these are just added to the url
defp url([{:open_bracket, text} | ts], result, needed, lnb),
do: url(ts, add(result, text), needed, lnb)

defp url([{:close_bracket, text} | ts], result, needed, lnb),
do: url(ts, add(result, text), needed, lnb)

defp url([{:any_quote, text} | ts], result, needed, lnb),
do: url(ts, add(result, text), needed, lnb)

defp url([{:verbatim, text} | ts], result, needed, lnb),
do: url(ts, add(result, text), needed, lnb)

defp url([{:ws, text} | ts], result, needed, lnb),
do: url(ts, add(result, text), needed, lnb)

defp url([{:escaped, text} | ts], result, needed, lnb),
do: url(ts, add(result, text), needed, lnb)

Expand All @@ -78,7 +86,9 @@ defmodule Earmark.Parser.Parser.LinkParser do
defp bail_out_to_title(ts, result) do
with remaining_text <- ts |> Enum.map(&text_of_token/1) |> Enum.join("") do
case title(remaining_text) do
nil -> nil
nil ->
nil

{title_text, inner_title} ->
add_title(result, {title_text, inner_title})
end
Expand All @@ -87,6 +97,7 @@ defmodule Earmark.Parser.Parser.LinkParser do

defp text_of_token(token)
defp text_of_token({:escaped, text}), do: "\\#{text}"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the formatter kicked in on this file, but it should be all good still. :)

defp text_of_token({_, text}) do
text
end
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.