Skip to content

Commit

Permalink
Implement parselet parse(word("foo")).
Browse files Browse the repository at this point in the history
  • Loading branch information
I3oris committed Jun 10, 2024
1 parent f594aef commit 1469d88
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/parser/parselets.cr
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ abstract class TopDown::Parser < TopDown::CharReader
{% elsif parselet.is_a? Call && parselet.name == "any" %}
parselet_any_char({{raises?}}, {{error}}, {{at}})

{% elsif parselet.is_a? Call && parselet.name == "word" && parselet.args.size == 1 && parselet.args[0].is_a? StringLiteral %}
parselet_word({{parselet.args[0]}}, {{raises?}}, {{error}}, {{at}})

{% elsif parselet.is_a? ArrayLiteral && parselet.size == 1 && parselet[0].is_a? Call && parselet[0].name == "any" %}
parselet_any_token({{raises?}}, {{error}}, {{at}})

Expand Down Expand Up @@ -229,4 +232,14 @@ abstract class TopDown::Parser < TopDown::CharReader
{% end %}
end)
end

private macro parselet_word(string, raises? = false, error = nil, at = nil)
%begin_location = self.location
%result = parselet_string({{string}}, {{raises?}}, {{error}}, {{at}})
if peek_char.alphanumeric?
self.location = %begin_location
break Fail.new
end
%result
end
end

0 comments on commit 1469d88

Please sign in to comment.