Project

General

Profile

Feature #10463 ยป tilde-bang-at-symbols.patch

jeremyevans0 (Jeremy Evans), 07/18/2019 07:19 PM

View differences:

parse.y
c = nextc(p);
if (IS_AFTER_OPERATOR()) {
SET_LEX_STATE(EXPR_ARG);
if (c == '@') {
if (c == '@' && !IS_lex_state_for(last_state, EXPR_FITEM)) {
return '!';
}
}
......
case '"':
p->lex.strterm = NEW_STRTERM(str_dsym, c, 0);
break;
case '!':
case '~':
pushback(p, c);
SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);
return tSYMBEG;
default:
pushback(p, c);
break;
......
case '~':
if (IS_AFTER_OPERATOR()) {
if ((c = nextc(p)) != '@') {
if ((c = nextc(p)) != '@' || IS_lex_state_for(last_state, EXPR_FITEM)) {
pushback(p, c);
}
SET_LEX_STATE(EXPR_ARG);
test/ruby/test_syntax.rb
end
end
def test_bang_tilde_atmark
assert_raise(SyntaxError) { eval ':!@' }
assert_raise(SyntaxError) { eval ':~@' }
bang, tilde = nil
klass = Class.new do
bang = def !@; 1 end
tilde = def ~@; 2 end
end
assert_equal(:!, bang)
assert_equal(:~, tilde)
assert_equal(1, !klass.new)
assert_equal(2, ~klass.new)
end
def test_cmd_symbol_after_keyword
bug6347 = '[ruby-dev:45563]'
assert_not_label(:foo, 'if true then not_label:foo end', bug6347)
    (1-1/1)