diff --git a/kotlin-mode-lexer.el b/kotlin-mode-lexer.el index 8e99415..c19e999 100644 --- a/kotlin-mode-lexer.el +++ b/kotlin-mode-lexer.el @@ -685,7 +685,7 @@ expression as a token with one of the following types: (kotlin-mode--token-text previous-token) '("(" "{" "[" "*" "%" "/" "+" "-" "&&" "||" ":" "&" "=" "+=" "-=" "*=" "/=" "%=" - "->" "." ".." "::" "?:" "?." "<=" ">=" "!=" "!==" "==" "===" + "->" "." ".." "..<" "::" "?:" "?." "<=" ">=" "!=" "!==" "==" "===" "as" "as?" "is" "!is" "in" "!in" "," ";" "{" "[" "(" ;; "class" will be handled later. "package" "import" "interface" "fun" "object" @@ -791,7 +791,7 @@ expression as a token with one of the following types: (member (kotlin-mode--token-text next-token) '("*" "%" "/" "&" "&&" "||" ":" "=" "+=" "-=" "*=" "/=" "%=" - "->" "." ".." "::" "?:" "?." "?" "<" ">" "<=" ">=" + "->" "." ".." "..<" "::" "?:" "?." "?" "<" ">" "<=" ">=" "!=" "!==" "==" "===" "," ";" ")" "]" "}" "as" "as?" "get" "set" "by" "where" "else" "catch" "finally" @@ -1487,7 +1487,7 @@ It is a type parameter list if: "is" "!is" "!in" "as" "as?" "!" "=" "+=" "-=" "*=" "/=" "%=" - ".." "::" "?:" "?." "<=" ">=" "==" "===" + ".." "..<" "::" "?:" "?." "<=" ">=" "==" "===" "package" "import" "class" "interface" "fun" "object" "val" "var" "typealias" "constructor" "by" "companion" "init" "if" "else" "when" "try" "catch" "finally" "for" "do" "while" "throw" @@ -1825,9 +1825,9 @@ This function does not return `implicit-;'." "!==" "!=" (seq "!is" word-end) (seq "!in" word-end) "as?" "!" - "=" "+=" "-=" "*=" "/=" "%=" "->" - ".." "." "?:" "?." "?" "<" ">" "<=" ">=" "==" "===" + "..<" ".." "." "?:" "?." "?" "<" ">" "<=" ">=" "===" "==" + "=" "+=" "-=" "*=" "/=" "%=" "*" "%" "/" "+" "-" "&"))) (let ((text (match-string-no-properties 0)) (start (match-beginning 0)) @@ -2151,6 +2151,35 @@ This function does not return `implicit-;'" :start (point) :end (1+ (point)))) + ;; Operator (3 letters) + ((member (buffer-substring-no-properties + (max (point-min) (- (point) 3)) + (point)) + '("===" "!==" "!is" "!in" "..<")) + (backward-char 3) + (make-instance 'kotlin-mode--token + :type 'operator + :text (buffer-substring-no-properties (point) (+ 3 (point))) + :start (point) + :end (+ 3 (point)))) + + ;; Operator (2 letters, other than as, in, or is) + ((member (buffer-substring-no-properties + (max (point-min) (- (point) 2)) + (point)) + '("++" "--" + "&&" "||" + "+=" "-=" "*=" "/=" "%=" + ".." "?." + "<=" ">=" "!=" "==" + "->")) + (backward-char 2) + (make-instance 'kotlin-mode--token + :type 'operator + :text (buffer-substring-no-properties (point) (+ 2 (point))) + :start (point) + :end (+ 2 (point)))) + ;; Open angle bracket for type parameters ;; ;; We use a heuristic: spaces are inserted around inequality sign, @@ -2185,35 +2214,6 @@ This function does not return `implicit-;'" :start (point) :end (1+ (point)))) - ;; Operator (3 letters) - ((member (buffer-substring-no-properties - (max (point-min) (- (point) 3)) - (point)) - '("===" "!==" "!is" "!in")) - (backward-char 3) - (make-instance 'kotlin-mode--token - :type 'operator - :text (buffer-substring-no-properties (point) (+ 3 (point))) - :start (point) - :end (+ 3 (point)))) - - ;; Operator (2 letters, other than as, in, or is) - ((member (buffer-substring-no-properties - (max (point-min) (- (point) 2)) - (point)) - '("++" "--" - "&&" "||" - "+=" "-=" "*=" "/=" "%=" - ".." "?." - "<=" ">=" "!=" "==" - "->")) - (backward-char 2) - (make-instance 'kotlin-mode--token - :type 'operator - :text (buffer-substring-no-properties (point) (+ 2 (point))) - :start (point) - :end (+ 2 (point)))) - ;; ? or as? ((eq (char-before) ??) (let ((pos-before-comment (point))) diff --git a/test/pathological.kt b/test/pathological.kt index b17d82a..2c2624a 100644 --- a/test/pathological.kt +++ b/test/pathological.kt @@ -667,18 +667,20 @@ fun foo() { val x = a shl // Line breaks are allowed after infix function. b // KNOWN_BUG + val y = 1 // KNOWN_BUG - var shl = 1 // KNOWN_BUG - val x = shl shl shl - shl < 100 && foo() // this is not a continuation of the previous line. + var shl = 1 + val x = shl shl shl + shl < 100 && foo() // this is not a continuation of the previous line. - var shl = 1 - val x = shl shl - shl < 100 && foo() // this is a continuation of the previous line. // KNOWN_BUG + var shl = 1 + val x = shl shl + shl < 100 && foo() // this is a continuation of the previous line. // KNOWN_BUG + val y = 1 // KNOWN_BUG - // This is not a infix function call; line breaks are // KNOWN_BUG + // This is not a infix function call; line breaks are // prohibited before infix function. - val x = // KNOWN_BUG + val x = a f (b) // So this line should not indented. @@ -686,6 +688,10 @@ fun foo() { a .. // Line breaks are prohibited before range operator. b + val x = + a ..< // Line breaks are prohibited before closed range operator. + b + val x = a + // Line breaks are prohibited before additive operators. b -