Skip to content

Commit

Permalink
fix: Resolve <<< parsing error. (asummers#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
asummers authored Mar 9, 2020
1 parent 35986f7 commit cb84676
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/lexer.xrl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ _ : {token, {'_', TokenLine}}.
\=\> : {token, {'=>', TokenLine}}.
\-\> : {token, {'->', TokenLine}}.
\| : {token, {'|', TokenLine}}.
\<\< : {token, {'<<', TokenLine}}.
\< : {token, {'<', TokenLine}}.
\>\> : {token, {'>>', TokenLine}}.
\> : {token, {'>', TokenLine}}.
\' : {token, {'\'', TokenLine}}.
, : {token, {',', TokenLine}}.
Expand Down
7 changes: 3 additions & 4 deletions src/parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ int
'::'
':'
'...'
'<<' '>>'
'<' '>'
'*'
'when'
Expand Down Expand Up @@ -67,9 +66,9 @@ value -> rest : '$1'.
value -> tuple : '$1'.
value -> type : '$1'.

binary -> '<<' '>>' : {binary, []}.
binary -> '<<' binary_items '>>' : {binary, '$2'}.
binary -> '<<' value_items '>>' : {binary, '$2'}.
binary -> '<' '<' '>' '>' : {binary, []}.
binary -> '<' '<' binary_items '>' '>' : {binary, '$3'}.
binary -> '<' '<' value_items '>' '>' : {binary, '$3'}.

pattern -> '<' value_items '>' : {pattern, '$2'}.

Expand Down
8 changes: 8 additions & 0 deletions test/literals_pretty_print_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,12 @@ defmodule Erlex.Test.LiteralsPretyPrintTest do
expected_output = "<<_ :: 64, _ :: size(8)>>"
assert pretty_printed == expected_output
end

test "binary as first value in pattern" do
input = "<<<_:8,_:_*1>>,'false'>"

pretty_printed = Erlex.pretty_print(input)

assert pretty_printed == "<<_ :: 8, _ :: size(1)>>, false"
end
end

0 comments on commit cb84676

Please sign in to comment.