Re: [GNU Global] new issue - langmap exceptions in pygments_parser.py

Yoshitaro Makise <[email protected]>
Newsgroups gmane.comp.gnu.global.bugs
Message-ID <CAEXk8fn9sO28t7T=79OFpXY4yjQTLti2VwWJWL1thE46OKfSRA@mail.gmail.com>
Hello,

Lewis's patch will hide the error by skipping mixed-case files such as *.Bat.
But the root cause should be fixed.
Attached patch fixes incorrect handling of mixed-case files on
Windows, that was the root cause.

BR,

2018-05-30 12:50 GMT+09:00 Shigio YAMAGUCHI <[email protected]>:
> Hello,
> I have committed your patch.
> Thank you.
>
> Regards,
> Shigio
>
>
> 2018-05-29 19:31 GMT+09:00 Lewis Lin <[email protected]>:
>>
>> Hi,
>>
>> Running global on Windows, I encountered this:
>>
>> -------------------------------
>> E:\Lesson\lesson>gtags
>> Traceback (most recent call last):
>>   File
>> "d:\acm\github\support\tools\gtags\bin\../share/gtags/script/pygments_parser.py",
>> line 259, in <module>
>>     main()
>>   File
>> "d:\acm\github\support\tools\gtags\bin\../share/gtags/script/pygments_parser.py",
>> line 256, in main
>>     handle_requests(langmap, parser_options)
>>   File
>> "d:\acm\github\support\tools\gtags\bin\../share/gtags/script/pygments_parser.py",
>> line 218, in handle_requests
>>     tags = parser.parse(path)
>>   File
>> "d:\acm\github\support\tools\gtags\bin\../share/gtags/script/pygments_parser.py",
>> line 175, in parse
>>     ref_result = self.ref_parser.parse(path)
>>   File
>> "d:\acm\github\support\tools\gtags\bin\../share/gtags/script/pygments_parser.py",
>> line 104, in parse
>>     lexer = self.get_lexer_by_langmap(path)
>>   File
>> "d:\acm\github\support\tools\gtags\bin\../share/gtags/script/pygments_parser.py",
>> line 114, in get_lexer_by_langmap
>>     lang = self.langmap[ext]
>> KeyError: '.Bat'
>> gtags: unexpected EOF.
>> --------------------------
>>
>> it appears that a '.bat' file is not recognized by self.langmap.
>>
>> after looking into pygments_parser.py, I found:
>>
>> ---------------------------------------------
>>     def get_lexer_by_langmap(self, path):
>>         ext = os.path.splitext(path)[1]
>>  ->   lang = self.langmap[ext]
>>         if lang:
>>             name = lang.lower()
>>             if name in LANGUAGE_ALIASES:
>>                 name = LANGUAGE_ALIASES[name]
>>             lexer = pygments.lexers.get_lexer_by_name(name)
>>             return lexer
>>         return None
>> ---------------------------------------------
>>
>> line 114 cannot handle extnames which don't exist in the langmap, and
>> should be fixed as:
>>
>> -     lang = self.langmap[ext]
>> +     lang = self.langmap.get(ext, None)
>>
>>
>> ________________________________
>> skywind3000
>>
>>
>>
>> _______________________________________________
>> Bug-global mailing list
>> [email protected]
>> https://lists.gnu.org/mailman/listinfo/bug-global
>>
>
>
>
> --
> Shigio YAMAGUCHI <[email protected]>
> PGP fingerprint:
> 26F6 31B4 3D62 4A92 7E6F  1C33 969C 3BE3 89DD A6EB
>
> _______________________________________________
> Bug-global mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/bug-global
>

_______________________________________________
Bug-global mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-global
pygments_ignorecase.diff (application/octet-stream, 1.3 KB)
Index: plugin-factory/pygments_parser.py.in
===================================================================
RCS file: /sources/global/global/plugin-factory/pygments_parser.py.in,v
retrieving revision 1.7
diff -u -r1.7 pygments_parser.py.in
--- plugin-factory/pygments_parser.py.in	30 May 2018 03:47:52 -0000	1.7
+++ plugin-factory/pygments_parser.py.in	10 Jun 2018 04:35:45 -0000
@@ -111,7 +111,10 @@
 
     def get_lexer_by_langmap(self, path):
         ext = os.path.splitext(path)[1]
-        lang = self.langmap.get(ext, None)
+        if sys.platform == 'win32':
+            lang = self.langmap.get(ext.lower(), None)
+        else:
+            lang = self.langmap.get(ext, None)
         if lang:
             name = lang.lower()
             if name in LANGUAGE_ALIASES:
@@ -189,10 +192,10 @@
         if not lang[0].islower():  # skip lowercase, that is for builtin parser
             for ext in exts.split('.'):
                 if ext:
-                    langmap['.' + ext] = lang
                     if sys.platform == 'win32':
-                        langmap['.' + ext.upper()] = lang
                         langmap['.' + ext.lower()] = lang
+                    else:
+                        langmap['.' + ext] = lang
     return langmap
 
 def handle_requests(langmap, options):
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.