0
我有這樣的解析器:防止Ragel從調用操作多次,同時匹配相同的字符串
class Parser
%%{
machine test_lexer;
action s { s = p; puts "s#{p}" }
action e { e = p; puts "e#{p}" }
action captured {
puts "captured #{s} #{e}"
}
key_value = "a" %s ("b" | "x" "c")+ %e %captured;
tags = ("x"+)? key_value;
main := tags*;
}%%
def initialize(data)
data = data
eof = data.length
%% write data;
%% write init;
%% write exec;
end
end
Parser.new(ARGV.first)
我打它與abxc那麼爲什麼它叫捕獲兩次/電子兩次,我怎麼能防止這個?
ragel -R simple.rl && ruby simple.rb "abxc"
s1
e2
captured 1 2
e4
captured 1 4
在GitHub上:https://github.com/grosser/ragel_example
嗯好吧,所以如果我添加一些愚蠢的結束表達式字符,它會起作用: – grosser
key_value =「a」%s(「b」|「x」「c」)+%e「z」%capture; – grosser