在利用ANTLR 3.3时,我正在改变当前语法以支持没有括号的输入.这是我的语法的第一个版本:
grammar PropLogic;
NOT : '!' ;
OR : '+' ;
AND : '.' ;
IMPLIES : '->' ;
SYMBOLS : ('a'..'z') | '~' ;
OP : '(' ;
CP : ')' ;
prog : formula EOF ;
formula : NOT formula
| OP formula( AND formula CP | OR formula CP | IMPLIES formula CP)
| SYMBOLS ;
WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = HIDDEN; } ;
Run Code Online (Sandbox Code Playgroud)
然后我改变它以支持适当的功能: …
当我遇到这两个函数时,我正在通过ruby koans学习红宝石:
def test_flexible_quotes_can_handle_multiple_lines
*long_string = %{
It was the best of times,
It was the worst of times.
}*
assert_equal *54*, long_string.size
end
def test_here_documents_can_also_handle_multiple_lines
*long_string = <<EOS
It was the best of times,
It was the worst of times.
EOS*
assert_equal *53*, long_string.size
end
Run Code Online (Sandbox Code Playgroud)
问题是,当使用灵活的引号时,我无法理解这个额外字符的来源.Ruby koans说两个答案都是正确的.