Skip to content

Commit

Permalink
Showing 3 changed files with 24 additions and 7 deletions.
8 changes: 8 additions & 0 deletions spec/compiler/lexer/lexer_string_array_spec.cr
Original file line number Diff line number Diff line change
@@ -77,4 +77,12 @@ describe "Lexer string array" do
it_should_be_valid_string_array_lexer(lexer)
end
end

context "using | as delimiter" do
it "lexes simple string array" do
lexer = Lexer.new("%w|one two|")

it_should_be_valid_string_array_lexer(lexer)
end
end
end
9 changes: 9 additions & 0 deletions spec/compiler/lexer/lexer_string_spec.cr
Original file line number Diff line number Diff line change
@@ -132,6 +132,15 @@ describe "Lexer string" do
tester.string_should_end_correctly
end

it "lexes simple string with %|" do
lexer = Lexer.new("%|hello|")
tester = LexerObjects::Strings.new(lexer)

tester.string_should_be_delimited_by('|', '|')
tester.next_string_token_should_be("hello")
tester.string_should_end_correctly
end

[['(', ')'], ['[', ']'], ['{', '}'], ['<', '>']].each do |(left, right)|
it "lexes simple string with nested %#{left}" do
lexer = Lexer.new("%#{left}hello #{left}world#{right}#{right}")
14 changes: 7 additions & 7 deletions src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
@@ -289,11 +289,11 @@ module Crystal
case next_char
when '='
next_char :"%="
when '(', '[', '{', '<'
when '(', '[', '{', '<', '|'
delimited_pair :string, current_char, closing_char, start
when 'i'
case peek_next_char
when '(', '{', '[', '<'
when '(', '{', '[', '<', '|'
start_char = next_char
next_char :SYMBOL_ARRAY_START
@token.raw = "%i#{start_char}" if @wants_raw
@@ -303,37 +303,37 @@ module Crystal
end
when 'q'
case peek_next_char
when '(', '{', '[', '<'
when '(', '{', '[', '<', '|'
next_char
delimited_pair :string, current_char, closing_char, start, allow_escapes: false
else
@token.type = :"%"
end
when 'Q'
case peek_next_char
when '(', '{', '[', '<'
when '(', '{', '[', '<', '|'
next_char
delimited_pair :string, current_char, closing_char, start
else
@token.type = :"%"
end
when 'r'
case next_char
when '(', '[', '{', '<'
when '(', '[', '{', '<', '|'
delimited_pair :regex, current_char, closing_char, start
else
raise "unknown %r char"
end
when 'x'
case next_char
when '(', '[', '{', '<'
when '(', '[', '{', '<', '|'
delimited_pair :command, current_char, closing_char, start
else
raise "unknown %x char"
end
when 'w'
case peek_next_char
when '(', '{', '[', '<'
when '(', '{', '[', '<', '|'
start_char = next_char
next_char :STRING_ARRAY_START
@token.raw = "%w#{start_char}" if @wants_raw

0 comments on commit 6b1067a

Please sign in to comment.