From b14c77ec3ec74e63a3175a428430b346ab922e9b Mon Sep 17 00:00:00 2001 From: Bijan Chokoufe Nejad Date: Sat, 7 May 2016 14:36:02 +0200 Subject: [PATCH 1/3] Add a custom identifier regex for tex --- ycmd/identifier_utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ycmd/identifier_utils.py b/ycmd/identifier_utils.py index 5f4cc8a1ad..be43e6cb30 100644 --- a/ycmd/identifier_utils.py +++ b/ycmd/identifier_utils.py @@ -93,6 +93,10 @@ # Section 2.4 'haskell': re.compile( r"[_a-zA-Z][\w']*", re.UNICODE ), + # Spec: ? + # Labels like \label{fig:foobar} are very common + 'tex': re.compile( r"[_a-zA-Z:-]*", re.UNICODE ), + # Spec: http://doc.perl6.org/language/syntax 'perl6': re.compile( r"[_a-zA-Z](?:\w|[-'](?=[_a-zA-Z]))*", re.UNICODE ), } From f65c7796f7316a1335b3da961d2487fc7c7f7347 Mon Sep 17 00:00:00 2001 From: Bijan Chokoufe Nejad Date: Sat, 7 May 2016 15:55:44 +0200 Subject: [PATCH 2/3] Add test for new tex regex --- ycmd/tests/identifier_utils_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ycmd/tests/identifier_utils_test.py b/ycmd/tests/identifier_utils_test.py index ce033a86e4..2043db19a6 100644 --- a/ycmd/tests/identifier_utils_test.py +++ b/ycmd/tests/identifier_utils_test.py @@ -244,6 +244,17 @@ def IsIdentifier_Haskell_test(): ok_( not iu.IsIdentifier( "9" , 'haskell' ) ) +def IsIdentifier_Tex_test(): + ok_( iu.IsIdentifier( 'foo', 'tex' ) ) + ok_( iu.IsIdentifier( 'fig:foo', 'tex' ) ) + ok_( iu.IsIdentifier( 'fig:foo-bar', 'tex' ) ) + ok_( iu.IsIdentifier( 'sec:summary', 'tex' ) ) + ok_( iu.IsIdentifier( 'eq:bar_foo', 'tex' ) ) + + ok_( not iu.IsIdentifier( '\section', 'tex' ) ) + ok_( not iu.IsIdentifier( 'some8', 'tex' ) ) + + def IsIdentifier_Perl6_test(): ok_( iu.IsIdentifier( 'foo' , 'perl6' ) ) ok_( iu.IsIdentifier( "f-o" , 'perl6' ) ) From 71884f4094063217fe06d7ebe44738d0c4e8e8ce Mon Sep 17 00:00:00 2001 From: Bijan Chokoufe Nejad Date: Sun, 8 May 2016 00:36:26 +0200 Subject: [PATCH 3/3] Add checks for empty identifiers and use `+` in regex --- ycmd/identifier_utils.py | 4 ++-- ycmd/tests/identifier_utils_test.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ycmd/identifier_utils.py b/ycmd/identifier_utils.py index be43e6cb30..8ab1b7669e 100644 --- a/ycmd/identifier_utils.py +++ b/ycmd/identifier_utils.py @@ -91,11 +91,11 @@ # Spec: http://www.haskell.org/onlinereport/lexemes.html # Section 2.4 - 'haskell': re.compile( r"[_a-zA-Z][\w']*", re.UNICODE ), + 'haskell': re.compile( r"[_a-zA-Z][\w']+", re.UNICODE ), # Spec: ? # Labels like \label{fig:foobar} are very common - 'tex': re.compile( r"[_a-zA-Z:-]*", re.UNICODE ), + 'tex': re.compile( r"[_a-zA-Z:-]+", re.UNICODE ), # Spec: http://doc.perl6.org/language/syntax 'perl6': re.compile( r"[_a-zA-Z](?:\w|[-'](?=[_a-zA-Z]))*", re.UNICODE ), diff --git a/ycmd/tests/identifier_utils_test.py b/ycmd/tests/identifier_utils_test.py index 2043db19a6..2fd025c772 100644 --- a/ycmd/tests/identifier_utils_test.py +++ b/ycmd/tests/identifier_utils_test.py @@ -183,6 +183,7 @@ def IsIdentifier_Css_test(): ok_( not iu.IsIdentifier( '-3' , 'css' ) ) ok_( not iu.IsIdentifier( '3' , 'css' ) ) ok_( not iu.IsIdentifier( 'a' , 'css' ) ) + ok_( not iu.IsIdentifier( '' , 'css' ) ) def IsIdentifier_R_test(): @@ -204,6 +205,7 @@ def IsIdentifier_R_test(): ok_( not iu.IsIdentifier( '123', 'r' ) ) ok_( not iu.IsIdentifier( '_1a', 'r' ) ) ok_( not iu.IsIdentifier( '_a' , 'r' ) ) + ok_( not iu.IsIdentifier( '' , 'r' ) ) def IsIdentifier_Clojure_test(): @@ -229,6 +231,7 @@ def IsIdentifier_Clojure_test(): ok_( not iu.IsIdentifier( '9' , 'clojure' ) ) ok_( not iu.IsIdentifier( 'a/b/c', 'clojure' ) ) ok_( not iu.IsIdentifier( '(a)' , 'clojure' ) ) + ok_( not iu.IsIdentifier( '' , 'clojure' ) ) def IsIdentifier_Haskell_test(): @@ -242,6 +245,7 @@ def IsIdentifier_Haskell_test(): ok_( not iu.IsIdentifier( "'x", 'haskell' ) ) ok_( not iu.IsIdentifier( "9x", 'haskell' ) ) ok_( not iu.IsIdentifier( "9" , 'haskell' ) ) + ok_( not iu.IsIdentifier( '' , 'haskell' ) ) def IsIdentifier_Tex_test(): @@ -253,6 +257,7 @@ def IsIdentifier_Tex_test(): ok_( not iu.IsIdentifier( '\section', 'tex' ) ) ok_( not iu.IsIdentifier( 'some8', 'tex' ) ) + ok_( not iu.IsIdentifier( '' , 'tex' ) ) def IsIdentifier_Perl6_test(): @@ -279,6 +284,7 @@ def IsIdentifier_Perl6_test(): ok_( not iu.IsIdentifier( "x+" , 'perl6' ) ) ok_( not iu.IsIdentifier( "9x" , 'perl6' ) ) ok_( not iu.IsIdentifier( "9" , 'perl6' ) ) + ok_( not iu.IsIdentifier( '' , 'perl6' ) ) def StartOfLongestIdentifierEndingAtIndex_Simple_test():