[gtksourceview] sql.lang: fix floating/integer numbers matching



commit 697f8e8ac9964f48c15efa87b38cbcd3650bcb13
Author: Tomisław Kityński <t kitynski e-owl tech>
Date:   Fri Jun 26 01:41:54 2020 +0200

    sql.lang: fix floating/integer numbers matching
    
    Also add some missing keywords.

 data/language-specs/sql.lang       |  8 ++++++--
 tests/syntax-highlighting/file.sql | 29 +++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/data/language-specs/sql.lang b/data/language-specs/sql.lang
index 02af4458..f6dc1286 100644
--- a/data/language-specs/sql.lang
+++ b/data/language-specs/sql.lang
@@ -117,11 +117,12 @@
     </context>
 
     <context id="integer-literals" style-ref="decimal">
-      <match>\b[0-9]+\b</match>
+      <match>\b[0-9]+(?![Ee][\+\-]?[0-9]*)\b</match>
     </context>
 
     <context id="number-literals" style-ref="floating-point">
-      <match>(\b[0-9]+(\.[0-9]+)?|\.[0-9]+)([Ee][\+-]?[0-9]+)?\b</match>
+      <!--match>(\b[0-9]+(\.[0-9]+)?|\.[0-9]+)([Ee][\+-]?[0-9]+)?\b</match-->
+      
<match>(?&lt;![\w\.])(([0-9]+\.[0-9]*|\.[0-9]+)([Ee][\+\-]?[0-9]*)?|([0-9]+[Ee][\+\-]?[0-9]*))(?![\w\.])</match>
     </context>
 
     <context id="size-clause" style-ref="decimal">
@@ -412,6 +413,7 @@
       <keyword>LEVEL</keyword>
       <keyword>LIKE</keyword>
       <keyword>LIMIT</keyword>
+      <keyword>LOOP</keyword>
       <keyword>NATURAL</keyword>
       <keyword>NOT</keyword>
       <keyword>OF</keyword>
@@ -426,6 +428,7 @@
       <keyword>PRIVILEGES</keyword>
       <keyword>PUBLIC</keyword>
       <keyword>REFERENCES</keyword>
+      <keyword>REVERSE</keyword>
       <keyword>REVOKE</keyword>
       <keyword>RIGHT</keyword>
       <keyword>ROWS</keyword>
@@ -509,6 +512,7 @@
       <keyword>EXCEPTION</keyword>
       <keyword>HINT</keyword>
       <keyword>IF</keyword>
+      <keyword>NOTICE</keyword>
       <keyword>RAISE</keyword>
       <keyword>RETURN</keyword>
     </context>
diff --git a/tests/syntax-highlighting/file.sql b/tests/syntax-highlighting/file.sql
index 78366dc3..eb795c4b 100644
--- a/tests/syntax-highlighting/file.sql
+++ b/tests/syntax-highlighting/file.sql
@@ -18,8 +18,37 @@ BEGIN;
 -- more comment
 COMMIT;
 
+-- Oh no!
+ROLLBACK;
+
+-- Too late... We're $100 shorter...
+
 CREATE TABLE other_table (
        col1 int4 NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
        col2 integer REFERENCES table_name
 );
 
+-- Except first column, all others are fp numbers. (Dot should be included
+-- in highlight). Note that last column is actually a sum of two floats,
+-- so '+' should not be matched as part of exponential notation.
+SELECT 1, 1., 1.1, .1, 1e, 1e2, 1.1e2, 12.12e-3, 7.e+4, 7.e+4.0;
+
+-- 7e55 at the end is part of an identifier, not a floating point number.
+-- (Whole identifier should be in one color).
+CREATE DOMAIN no_realI7e55 AS integer CHECK (VALUE > 0);
+
+-- CREATE OR REPLACE FUNCTION is one statement, so REPLACE should NOT be
+-- highlighted as function name.
+CREATE OR REPLACE FUNCTION function_name(IN param_name integer) RETURNS integer
+LANGUAGE plpgsql AS $$
+DECLARE
+       ctr integer;
+BEGIN
+       -- 20..0 is a range, not two consecutive floats, so both dots should NOT
+       -- be selected as part of any fp number and both numbers should be selected
+       -- as integers.
+       FOR ctr IN REVERSE 20..0 BY 2 LOOP
+               RAISE NOTICE 'Counter: %', ctr;
+       END LOOP;
+END; $$
+


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