mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 05:22:23 +00:00
More idiomatic
This commit is contained in:
parent
cb09dff9f1
commit
20d6b65346
@ -31,7 +31,6 @@ module BytesRegex
|
|||||||
end
|
end
|
||||||
|
|
||||||
def match(str : Bytes, pos = 0) : Array(Match)
|
def match(str : Bytes, pos = 0) : Array(Match)
|
||||||
match = [] of Match
|
|
||||||
rc = LibPCRE2.match(
|
rc = LibPCRE2.match(
|
||||||
@re,
|
@re,
|
||||||
str,
|
str,
|
||||||
@ -42,18 +41,19 @@ module BytesRegex
|
|||||||
nil)
|
nil)
|
||||||
if rc > 0
|
if rc > 0
|
||||||
ovector = LibPCRE2.get_ovector_pointer(@match_data)
|
ovector = LibPCRE2.get_ovector_pointer(@match_data)
|
||||||
(0...rc).each do |i|
|
(0...rc).map do |i|
|
||||||
m_start = ovector[2 * i]
|
m_start = ovector[2 * i]
|
||||||
m_size = ovector[2 * i + 1] - m_start
|
m_end = ovector[2 * i + 1]
|
||||||
if m_size == 0
|
if m_start == m_end
|
||||||
m_value = Bytes.new(0)
|
m_value = Bytes.new(0)
|
||||||
else
|
else
|
||||||
m_value = str[m_start...m_start + m_size]
|
m_value = str[m_start...m_end]
|
||||||
end
|
end
|
||||||
match << Match.new(m_value, m_start, m_size)
|
Match.new(m_value, m_start, m_end - m_start)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
[] of Match
|
||||||
end
|
end
|
||||||
match
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ module Tartrazine
|
|||||||
|
|
||||||
# No match
|
# No match
|
||||||
return false, pos, [] of Token if match.size == 0
|
return false, pos, [] of Token if match.size == 0
|
||||||
return true, pos + match[0].size, actions.flat_map { |action| action.emit(match, lexer) }
|
return true, pos + match[0].size, actions.flat_map(&.emit(match, lexer))
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(node : XML::Node)
|
def initialize(node : XML::Node)
|
||||||
@ -80,7 +80,7 @@ module Tartrazine
|
|||||||
NO_MATCH = [] of Match
|
NO_MATCH = [] of Match
|
||||||
|
|
||||||
def match(text, pos, lexer) : Tuple(Bool, Int32, Array(Token))
|
def match(text, pos, lexer) : Tuple(Bool, Int32, Array(Token))
|
||||||
return true, pos, actions.flat_map { |action| action.emit(NO_MATCH, lexer) }
|
return true, pos, actions.flat_map(&.emit(NO_MATCH, lexer))
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(node : XML::Node)
|
def initialize(node : XML::Node)
|
||||||
|
Loading…
Reference in New Issue
Block a user