emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r115076: * lisp/progmodes/ruby-mode.el (ruby-smie-gr


From: Dmitry Gutov
Subject: [Emacs-diffs] trunk r115076: * lisp/progmodes/ruby-mode.el (ruby-smie-grammar): Disambiguate between
Date: Tue, 12 Nov 2013 14:15:28 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 115076
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Gutov <address@hidden>
branch nick: trunk
timestamp: Tue 2013-11-12 16:15:14 +0200
message:
  * lisp/progmodes/ruby-mode.el (ruby-smie-grammar): Disambiguate between
  binary "|" operator and closing block args delimiter.  Remove
  FIXME comment referring to Ruby 1.8-only syntax.
  (ruby-smie--implicit-semi-p): Not after "|" operator.
  (ruby-smie--closing-pipe-p): New function.
  (ruby-smie--forward-token, ruby-smie--backward-token): Use it.
  (ruby-smie-rules): Indent after "|".
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/progmodes/ruby-mode.el    
rubymode.el-20091113204419-o5vbwnq5f7feedwu-8804
  test/indent/ruby.rb            ruby.rb-20120424165921-h044139hbrd7snvw-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-11-12 08:16:50 +0000
+++ b/lisp/ChangeLog    2013-11-12 14:15:14 +0000
@@ -1,3 +1,13 @@
+2013-11-12  Dmitry Gutov  <address@hidden>
+
+       * progmodes/ruby-mode.el (ruby-smie-grammar): Disambiguate between
+       binary "|" operator and closing block args delimiter.  Remove
+       FIXME comment referring to Ruby 1.8-only syntax.
+       (ruby-smie--implicit-semi-p): Not after "|" operator.
+       (ruby-smie--closing-pipe-p): New function.
+       (ruby-smie--forward-token, ruby-smie--backward-token): Use it.
+       (ruby-smie-rules): Indent after "|".
+
 2013-11-12  Glenn Morris  <address@hidden>
 
        * ps-print.el (ps-face-attribute-list):

=== modified file 'lisp/progmodes/ruby-mode.el'
--- a/lisp/progmodes/ruby-mode.el       2013-11-08 23:59:56 +0000
+++ b/lisp/progmodes/ruby-mode.el       2013-11-12 14:15:14 +0000
@@ -310,10 +310,10 @@
              ("unless" insts "end")
              ("if" if-body "end")
              ("case"  cases "end"))
-       (formal-params ("opening-|" exp "|"))
+       (formal-params ("opening-|" exp "closing-|"))
        (for-body (for-head ";" insts))
        (for-head (id "in" exp))
-       (cases (exp "then" insts) ;; FIXME: Ruby also allows (exp ":" insts).
+       (cases (exp "then" insts)
               (cases "when" cases) (insts "else" insts))
        (expseq (exp) );;(expseq "," expseq)
        (hashvals (id "=>" exp1) (hashvals "," hashvals))
@@ -337,9 +337,8 @@
        (left ".." "...")
        (left "+" "-")
        (left "*" "/" "%" "**")
-       ;; (left "|") ; FIXME: Conflicts with | after block parameters.
        (left "&&" "||")
-       (left "^" "&")
+       (left "^" "&" "|")
        (nonassoc "<=>")
        (nonassoc ">" ">=" "<" "<=")
        (nonassoc "==" "===" "!=")
@@ -365,7 +364,8 @@
                   (string-match "\\`\\s." (save-excursion
                                             (ruby-smie--backward-token))))
              (and (eq (char-before) ?|)
-                  (eq (char-before (1- (point))) ?|))
+                  (member (save-excursion (ruby-smie--backward-token))
+                          '("|" "||")))
              (and (eq (car (syntax-after (1- (point)))) 2)
                   (member (save-excursion (ruby-smie--backward-token))
                           '("iuwu-mod" "and" "or")))
@@ -385,6 +385,12 @@
     (or (eq ?\{ (char-before))
         (looking-back "\\_<do" (- (point) 2)))))
 
+(defun ruby-smie--closing-pipe-p ()
+  (save-excursion
+    (if (eq ?| (char-before)) (forward-char -1))
+    (and (re-search-backward "|" (line-beginning-position) t)
+         (ruby-smie--opening-pipe-p))))
+
 (defun ruby-smie--args-separator-p (pos)
   (and
    (< pos (line-end-position))
@@ -442,7 +448,10 @@
            ((string-match-p "\\`|[*&]?\\'" tok)
             (forward-char (- 1 (length tok)))
             (setq tok "|")
-            (if (ruby-smie--opening-pipe-p) "opening-|" tok))
+            (cond
+             ((ruby-smie--opening-pipe-p) "opening-|")
+             ((ruby-smie--closing-pipe-p) "closing-|")
+             (t tok)))
            ((and (equal tok "") (looking-at "\\\\\n"))
             (goto-char (match-end 0)) (ruby-smie--forward-token))
            ((equal tok "do")
@@ -482,7 +491,10 @@
           (if (ruby-smie--bosp)
               tok "iuwu-mod"))
          ((equal tok "|")
-          (if (ruby-smie--opening-pipe-p) "opening-|" tok))
+          (cond
+           ((ruby-smie--opening-pipe-p) "opening-|")
+           ((ruby-smie--closing-pipe-p) "closing-|")
+           (t tok)))
          ((string-match-p "\\`|[*&]\\'" tok)
           (forward-char 1)
           (substring tok 1))
@@ -545,7 +557,7 @@
      (if (not (smie-rule-sibling-p)) 0)) ;; ruby-indent-level
     (`(:after . ,(or "=" "iuwu-mod" "+" "-" "*" "/" "&&" "||" "%" "**" "^" "&"
                      "<=>" ">" "<" ">=" "<=" "==" "===" "!=" "<<" ">>"
-                     "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^="
+                     "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" "|"
                      "<<=" ">>=" "&&=" "||=" "and" "or"))
      (if (smie-rule-parent-p ";" nil) ruby-indent-level))
     (`(:before . "begin")

=== modified file 'test/indent/ruby.rb'
--- a/test/indent/ruby.rb       2013-11-08 23:59:56 +0000
+++ b/test/indent/ruby.rb       2013-11-12 14:15:14 +0000
@@ -285,6 +285,9 @@
   end
 end
 
+foo |
+  bar
+
 foo ||
   begin
     bar


reply via email to

[Prev in Thread] Current Thread [Next in Thread]