-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from linusdm/diff_symbol_first_character_of_line
Only consider the first character as the diff symbol to avoid ambiguous interpretations
- Loading branch information
Showing
3 changed files
with
83 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule Makeup.Lexers.DiffLexer.Helper do | ||
@moduledoc false | ||
|
||
import NimbleParsec | ||
import Makeup.Lexer.Combinators | ||
|
||
def line_starting_with(start, token_type) when is_binary(start) do | ||
string(start) | ||
|> rest_of_line() | ||
|> token(token_type) | ||
end | ||
|
||
def line_starting_with([_, _ | _] = start, token_type) do | ||
start | ||
|> Enum.map(&string/1) | ||
|> choice() | ||
|> rest_of_line() | ||
|> token(token_type) | ||
end | ||
|
||
def text_line() do | ||
rest_of_line() |> token(:text) | ||
end | ||
|
||
defp rest_of_line(combinator \\ empty()) do | ||
utf8_string(combinator, [not: ?\n, not: ?\r], min: 0) | ||
end | ||
|
||
def newline(combinator \\ empty()) do | ||
concat(combinator, ascii_string([?\n, ?\r], min: 1) |> token(:whitespace)) | ||
end | ||
end |
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