我在解析树顶语法中的分数时遇到了一些困难。
我的语法看起来像这样
grammar Numbers
rule number
regular_number optional_frac {
def value
[:number, text_value]
end
}
end
rule optional_frac
frac_number? {
def value
[:optional_frac, text_value]
end
}
end
rule frac_number
(s? regular_number '/' regular_number)? / ('/' regular_number)? {
def value
[:frac_number, text_value]
end
}
end
rule regular_number
[0-9\.\/-]+ {
def value
text_value
end
}
end
end
当我尝试从中获取值时
2 => number
1/2 => number, frac_number
2 2/4 => not recognized
我虽然规则
s? regular_number '/' regular_number
将作为分数返回。知道我的语法有什么问题吗?