Project

General

Profile

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

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

View differences:

parse.y
8779 8779
	c = nextc(p);
8780 8780
	if (IS_AFTER_OPERATOR()) {
8781 8781
	    SET_LEX_STATE(EXPR_ARG);
8782
	    if (c == '@') {
8782
	    if (c == '@' && !IS_lex_state_for(last_state, EXPR_FITEM)) {
8783 8783
		return '!';
8784 8784
	    }
8785 8785
	}
......
9144 9144
	  case '"':
9145 9145
	    p->lex.strterm = NEW_STRTERM(str_dsym, c, 0);
9146 9146
	    break;
9147
          case '!':
9148
          case '~':
9149
            pushback(p, c);
9150
            SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);
9151
            return tSYMBEG;
9147 9152
	  default:
9148 9153
	    pushback(p, c);
9149 9154
	    break;
......
9191 9196

  
9192 9197
      case '~':
9193 9198
	if (IS_AFTER_OPERATOR()) {
9194
	    if ((c = nextc(p)) != '@') {
9199
            if ((c = nextc(p)) != '@' || IS_lex_state_for(last_state, EXPR_FITEM)) {
9195 9200
		pushback(p, c);
9196 9201
	    }
9197 9202
	    SET_LEX_STATE(EXPR_ARG);
test/ruby/test_syntax.rb
341 341
    end
342 342
  end
343 343

  
344
  def test_bang_tilde_atmark
345
    assert_raise(SyntaxError) { eval ':!@' }
346
    assert_raise(SyntaxError) { eval ':~@' }
347
    bang, tilde = nil
348
    klass = Class.new do
349
      bang = def !@; 1 end
350
      tilde = def ~@; 2 end
351
    end
352
    assert_equal(:!, bang)
353
    assert_equal(:~, tilde)
354
    assert_equal(1, !klass.new)
355
    assert_equal(2, ~klass.new)
356
  end
357

  
344 358
  def test_cmd_symbol_after_keyword
345 359
    bug6347 = '[ruby-dev:45563]'
346 360
    assert_not_label(:foo, 'if true then not_label:foo end', bug6347)
347
-