[geany/geany] d1ea9e: Merge pull request #755 from b4n/python/identifiers

Colomban Wendling git-noreply at xxxxx
Sat Nov 14 23:14:29 UTC 2015


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sat, 14 Nov 2015 23:14:29 UTC
Commit:      d1ea9ede48018b183037074aef6a1c723da9d094
             https://github.com/geany/geany/commit/d1ea9ede48018b183037074aef6a1c723da9d094

Log Message:
-----------
Merge pull request #755 from b4n/python/identifiers

Update keywords and identifiers list for Python 3

Part of #748.


Modified Paths:
--------------
    NEWS
    data/filetypes.python
    scripts/update-python-identifiers.sh

Modified: NEWS
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -32,6 +32,7 @@ Geany 1.26 (unreleased)
     Filetypes
     * Add Cargo build commands for Rust (Wayne Nilsen, PR#557).
     * Add recent Perl keywords (Olivier Duclos, PR#599).
+    * Add missing Python 3 keywords and builtins (PR#755).
     * Improvements to the Rust filetype (Pavel Sountsov, PR#613).
     * Add multiline comment to Haskell (Abel Serrano Juste, PR#638).
     * Recognize `.adoc` is as Asciidoc (PR#708, PR#711).


Modified: data/filetypes.python
8 lines changed, 5 insertions(+), 3 deletions(-)
===================================================================
@@ -20,10 +20,12 @@ decorator=decorator
 
 [keywords]
 # all items must be in one line
-primary=and as assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while with yield False None True
+# both primary and identifiers are auto-generated by scripts/update-python-identifiers.sh
+# Python 2&3 keywords
+primary=False None True and as assert break class continue def del elif else except exec finally for from global if import in is lambda nonlocal not or pass print raise return try while with yield
 # additional keywords, will be highlighted with style "word2"
-# these are the builtins for Python 2.7 created with ' '.join(dir(__builtins__))
-identifiers=ArithmeticError AssertionError AttributeError BaseException BufferError BytesWarning DeprecationWarning EOFError Ellipsis EnvironmentError Exception FloatingPointError FutureWarning GeneratorExit IOError ImportError ImportWarning IndentationError IndexError KeyError KeyboardInterrupt LookupError MemoryError NameError NotImplemented NotImplementedError OSError OverflowError PendingDeprecationWarning ReferenceError RuntimeError RuntimeWarning StandardError StopIteration SyntaxError SyntaxWarning SystemError SystemExit TabError TypeError UnboundLocalError UnicodeDecodeError UnicodeEncodeError UnicodeError UnicodeTranslateError UnicodeWarning UserWarning ValueError Warning ZeroDivisionError __debug__ __doc__ __import__ __name__ __package__ abs all any apply basestring bin bool buffer bytearray bytes callable chr classmethod cmp coerce compile complex copyright credits delattr dict dir divmod enumerate eval execfile exit file filter float format frozenset getattr globals hasattr hash help hex id input int intern isinstance issubclass iter len license list locals long map max memoryview min next object oct open ord pow print property quit range raw_input reduce reload repr reversed round set setattr slice sorted staticmethod str sum super tuple type unichr unicode vars xrange zip
+# Python 2&3 builtins (minus ones in primary)
+identifiers=ArithmeticError AssertionError AttributeError BaseException BlockingIOError BrokenPipeError BufferError BytesWarning ChildProcessError ConnectionAbortedError ConnectionError ConnectionRefusedError ConnectionResetError DeprecationWarning EOFError Ellipsis EnvironmentError Exception FileExistsError FileNotFoundError FloatingPointError FutureWarning GeneratorExit IOError ImportError ImportWarning IndentationError IndexError InterruptedError IsADirectoryError KeyError KeyboardInterrupt LookupError MemoryError NameError NotADirectoryError NotImplemented NotImplementedError OSError OverflowError PendingDeprecationWarning PermissionError ProcessLookupError ReferenceError ResourceWarning RuntimeError RuntimeWarning StandardError StopIteration SyntaxError SyntaxWarning SystemError SystemExit TabError TimeoutError TypeError UnboundLocalError UnicodeDecodeError UnicodeEncodeError UnicodeError UnicodeTranslateError UnicodeWarning UserWarning ValueError Warning ZeroDivisionError __build_class__ __debug__ __doc__ __import__ __loader__ __name__ __package__ __spec__ abs all any apply ascii basestring bin bool buffer bytearray bytes callable chr classmethod cmp coerce compile complex copyright credits delattr dict dir divmod enumerate eval execfile exit file filter float format frozenset getattr globals hasattr hash help hex id input int intern isinstance issubclass iter len license list locals long map max memoryview min next object oct open ord pow property quit range raw_input reduce reload repr reversed round set setattr slice sorted staticmethod str sum super tuple type unichr unicode vars xrange zip
 
 [lexer_properties]
 fold.comment.python=1


Modified: scripts/update-python-identifiers.sh
38 lines changed, 38 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# Author:  Colomban Wendling <colomban at geany.org>
+# License: GPL v2 or later
+#
+# Updates the `identifiers` entry in data/filetypes.python.
+# Requires both Python 2 and 3.
+
+set -e
+
+file=data/filetypes.python
+
+[ -f "$file" ]
+
+py_2_and_3() {
+  python2 "$@" && python3 "$@"
+}
+
+# sort_filter [exclude...]
+sort_filter() {
+  python -c '\
+from sys import stdin; \
+items=set(stdin.read().strip().split("\n")); \
+exclude=['"$(for a in "$@"; do printf "'%s', " "$a"; done)"']; \
+print(" ".join(sorted([i for i in items if i not in exclude])))
+'
+}
+
+keywords=$(py_2_and_3 -c 'from keyword import kwlist; print("\n".join(kwlist))')
+builtins=$(py_2_and_3 -c 'print("\n".join(dir(__builtins__)))')
+
+primary=$(echo "$keywords" | sort_filter)
+# builtins, but excluding keywords that are already listed in primary=
+identifiers=$(echo "$builtins" | sort_filter $primary)
+
+sed -e "s/^primary=.*$/primary=$primary/" \
+    -e "s/^identifiers=.*$/identifiers=$identifiers/" \
+    -i "$file"



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list