From 9ee2d1f1028cead499d66ee73ed4c44c7ff6fbaa Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 8 Jul 2021 12:22:22 -0500 Subject: [PATCH] editor: clean up keywords and builtins - remove python 2 stuff - separate builtins from keywords --- src/editor/pybricksMicroPython.ts | 64 ++++++++++--------------------- 1 file changed, 20 insertions(+), 44 deletions(-) diff --git a/src/editor/pybricksMicroPython.ts b/src/editor/pybricksMicroPython.ts index f1e6c085..160155e3 100644 --- a/src/editor/pybricksMicroPython.ts +++ b/src/editor/pybricksMicroPython.ts @@ -52,19 +52,16 @@ export const language = { defaultToken: '', tokenPostfix: '.python', - keywords: [ - // This section is the result of running - // `for k in keyword.kwlist: print(' "' + k + '",')` in a Python REPL, - // though note that the output from Python 3 is not a strict superset of the - // output from Python 2. - 'False', // promoted to keyword.kwlist in Python 3 - 'None', // promoted to keyword.kwlist in Python 3 - 'True', // promoted to keyword.kwlist in Python 3 + // https://docs.python.org/3/reference/lexical_analysis.html#keywords + keywords: >[ + 'False', + 'None', + 'True', 'and', 'as', 'assert', - 'async', // new in Python 3 - 'await', // new in Python 3 + 'async', + 'await', 'break', 'class', 'continue', @@ -73,7 +70,6 @@ export const language = { 'elif', 'else', 'except', - 'exec', // Python 2, but not 3. 'finally', 'for', 'from', @@ -83,38 +79,32 @@ export const language = { 'in', 'is', 'lambda', - 'nonlocal', // new in Python 3 + 'nonlocal', 'not', 'or', 'pass', - 'print', // Python 2, but not 3. 'raise', 'return', 'try', 'while', 'with', 'yield', + ], - 'int', - 'float', - 'long', - 'complex', - 'hex', - + // https://docs.python.org/3/library/functions.html#built-in-funcs + builtins: >[ 'abs', 'all', 'any', - 'apply', - 'basestring', + 'ascii', 'bin', 'bool', - 'buffer', + 'breakpoint', 'bytearray', + 'bytes', 'callable', 'chr', 'classmethod', - 'cmp', - 'coerce', 'compile', 'complex', 'delattr', @@ -123,9 +113,9 @@ export const language = { 'divmod', 'enumerate', 'eval', - 'execfile', - 'file', + 'exec', 'filter', + 'float', 'format', 'frozenset', 'getattr', @@ -133,15 +123,16 @@ export const language = { 'hasattr', 'hash', 'help', + 'hex', 'id', 'input', - 'intern', + 'int', 'isinstance', 'issubclass', 'iter', 'len', - 'locals', 'list', + 'locals', 'map', 'max', 'memoryview', @@ -156,9 +147,6 @@ export const language = { 'property', 'reversed', 'range', - 'raw_input', - 'reduce', - 'reload', 'repr', 'reversed', 'round', @@ -173,21 +161,8 @@ export const language = { 'super', 'tuple', 'type', - 'unichr', - 'unicode', 'vars', - 'xrange', 'zip', - - '__dict__', - '__methods__', - '__members__', - '__class__', - '__bases__', - '__name__', - '__mro__', - '__subclasses__', - '__init__', '__import__', ], @@ -214,6 +189,7 @@ export const language = { { cases: { '@keywords': 'keyword', + '@builtins': 'support.function', '@default': 'identifier', }, },