From 7acabe62370f61de7c6e4d73922ad83c4ddc8935 Mon Sep 17 00:00:00 2001 From: Pete Lomax Date: Thu, 15 Sep 2022 18:19:29 +0100 Subject: [PATCH] Add Phix (#2222) --- AUTHORS | 1 + pygments/lexers/_mapping.py | 1 + pygments/lexers/phix.py | 364 +++++++++++++ tests/examplefiles/phix/example.exw | 85 +++ tests/examplefiles/phix/example.exw.output | 606 +++++++++++++++++++++ 5 files changed, 1057 insertions(+) create mode 100644 pygments/lexers/phix.py create mode 100644 tests/examplefiles/phix/example.exw create mode 100644 tests/examplefiles/phix/example.exw.output diff --git a/AUTHORS b/AUTHORS index 9f417bf909..5d2a810998 100644 --- a/AUTHORS +++ b/AUTHORS @@ -136,6 +136,7 @@ Other contributors, listed alphabetically, are: * Sylvestre Ledru -- Scilab lexer * Chee Sing Lee -- Flatline lexer * Mark Lee -- Vala lexer +* Pete Lomax -- Phix lexer * Valentin Lorentz -- C++ lexer improvements * Ben Mabey -- Gherkin lexer * Angus MacArthur -- QML lexer diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index f043a33c98..3c5f043a53 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -351,6 +351,7 @@ 'PegLexer': ('pygments.lexers.grammar_notation', 'PEG', ('peg',), ('*.peg',), ('text/x-peg',)), 'Perl6Lexer': ('pygments.lexers.perl', 'Perl6', ('perl6', 'pl6', 'raku'), ('*.pl', '*.pm', '*.nqp', '*.p6', '*.6pl', '*.p6l', '*.pl6', '*.6pm', '*.p6m', '*.pm6', '*.t', '*.raku', '*.rakumod', '*.rakutest', '*.rakudoc'), ('text/x-perl6', 'application/x-perl6')), 'PerlLexer': ('pygments.lexers.perl', 'Perl', ('perl', 'pl'), ('*.pl', '*.pm', '*.t', '*.perl'), ('text/x-perl', 'application/x-perl')), + 'PhixLexer': ('pygments.lexers.phix', 'Phix', ('phix',), ('*.exw',), ('text/x-phix',)), 'PhpLexer': ('pygments.lexers.php', 'PHP', ('php', 'php3', 'php4', 'php5'), ('*.php', '*.php[345]', '*.inc'), ('text/x-php',)), 'PigLexer': ('pygments.lexers.jvm', 'Pig', ('pig',), ('*.pig',), ('text/x-pig',)), 'PikeLexer': ('pygments.lexers.c_like', 'Pike', ('pike',), ('*.pike', '*.pmod'), ('text/x-pike',)), diff --git a/pygments/lexers/phix.py b/pygments/lexers/phix.py new file mode 100644 index 0000000000..6027e336d6 --- /dev/null +++ b/pygments/lexers/phix.py @@ -0,0 +1,364 @@ +""" + pygments.lexers.phix + ~~~~~~~~~~~~~~~~~~~~ + + Lexers for Phix. + + :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, words +from pygments.token import Text, Comment, Operator, Keyword, Name, String, Whitespace + +__all__ = ['PhixLexer'] + + +class PhixLexer(RegexLexer): + """ + Pygments Lexer for Phix files (.exw). + See http://phix.x10.mx + + .. versionadded:: 2.14.0 + """ + + name = 'Phix' + url = 'http://phix.x10.mx' + aliases = ['phix'] + filenames = ['*.exw'] + mimetypes = ['text/x-phix'] + + flags = re.MULTILINE # nb: **NOT** re.DOTALL! (totally spanners comment handling) + + preproc = ( + 'ifdef', 'elsifdef', 'elsedef' + ) + # Note these lists are auto-generated by pwa/p2js.exw, when pwa\src\p2js_keywords.e (etc) + # change, though of course subsequent copy/commit/pull requests are all manual steps. + types = ( + 'string', 'nullable_string', 'atom_string', 'atom', 'bool', 'boolean', + 'cdCanvan', 'cdCanvas', 'complex', 'CURLcode', 'dictionary', 'int', + 'integer', 'Ihandle', 'Ihandles', 'Ihandln', 'mpfr', 'mpq', 'mpz', + 'mpz_or_string', 'number', 'rid_string', 'seq', 'sequence', 'timedate', + 'object' + ) + keywords = ( + 'abstract', 'class', 'continue', 'export', 'extends', 'nullable', + 'private', 'public', 'static', 'struct', 'trace', + 'and', 'break', 'by', 'case', 'catch', 'const', 'constant', 'debug', + 'default', 'do', 'else', 'elsif', 'end', 'enum', 'exit', 'fallthru', + 'fallthrough', 'for', 'forward', 'function', 'global', 'if', 'in', + 'include', 'js', 'javascript', 'javascript_semantics', 'let', 'not', + 'or', 'procedure', 'profile', 'profile_time', 'return', 'safe_mode', + 'switch', 'then', 'to', 'try', 'type', 'type_check', 'until', 'warning', + 'while', 'with', 'without', 'xor' + ) + routines = ( + 'abort', 'abs', 'adjust_timedate', 'and_bits', 'and_bitsu', 'apply', + 'append', 'arccos', 'arcsin', 'arctan', 'assert', 'atan2', + 'atom_to_float32', 'atom_to_float64', 'bankers_rounding', 'beep', + 'begins', 'binary_search', 'bits_to_int', 'bk_color', 'bytes_to_int', + 'call_func', 'call_proc', 'cdCanvasActivate', 'cdCanvasArc', + 'cdCanvasBegin', 'cdCanvasBox', 'cdCanvasChord', 'cdCanvasCircle', + 'cdCanvasClear', 'cdCanvasEnd', 'cdCanvasFlush', 'cdCanvasFont', + 'cdCanvasGetImageRGB', 'cdCanvasGetSize', 'cdCanvasGetTextAlignment', + 'cdCanvasGetTextSize', 'cdCanvasLine', 'cdCanvasMark', + 'cdCanvasMarkSize', 'cdCanvasMultiLineVectorText', 'cdCanvasPixel', + 'cdCanvasRect', 'cdCanvasRoundedBox', 'cdCanvasRoundedRect', + 'cdCanvasSector', 'cdCanvasSetAttribute', 'cdCanvasSetBackground', + 'cdCanvasSetFillMode', 'cdCanvasSetForeground', + 'cdCanvasSetInteriorStyle', 'cdCanvasSetLineStyle', + 'cdCanvasSetLineWidth', 'cdCanvasSetTextAlignment', 'cdCanvasText', + 'cdCanvasSetTextOrientation', 'cdCanvasGetTextOrientation', + 'cdCanvasVectorText', 'cdCanvasVectorTextDirection', + 'cdCanvasVectorTextSize', 'cdCanvasVertex', 'cdCreateCanvas', + 'cdDecodeAlpha', 'cdDecodeColor', 'cdDecodeColorAlpha', 'cdEncodeAlpha', + 'cdEncodeColor', 'cdEncodeColorAlpha', 'cdKillCanvas', 'cdVersion', + 'cdVersionDate', 'ceil', 'change_timezone', 'choose', 'clear_screen', + 'columnize', 'command_line', 'compare', 'complex_abs', 'complex_add', + 'complex_arg', 'complex_conjugate', 'complex_cos', 'complex_cosh', + 'complex_div', 'complex_exp', 'complex_imag', 'complex_inv', + 'complex_log', 'complex_mul', 'complex_neg', 'complex_new', + 'complex_norm', 'complex_power', 'complex_rho', 'complex_real', + 'complex_round', 'complex_sin', 'complex_sinh', 'complex_sprint', + 'complex_sqrt', 'complex_sub', 'complex_theta', 'concat', 'cos', + 'crash', 'custom_sort', 'date', 'day_of_week', 'day_of_year', + 'days_in_month', 'decode_base64', 'decode_flags', 'deep_copy', 'deld', + 'deserialize', 'destroy_dict', 'destroy_queue', 'destroy_stack', + 'dict_name', 'dict_size', 'elapsed', 'elapsed_short', 'encode_base64', + 'equal', 'even', 'exp', 'extract', 'factorial', 'factors', + 'file_size_k', 'find', 'find_all', 'find_any', 'find_replace', 'filter', + 'flatten', 'float32_to_atom', 'float64_to_atom', 'floor', + 'format_timedate', 'free_console', 'from_polar', 'gcd', 'get_file_base', + 'get_file_extension', 'get_file_name', 'get_file_name_and_path', + 'get_file_path', 'get_file_path_and_name', 'get_maxprime', 'get_prime', + 'get_primes', 'get_primes_le', 'get_proper_dir', 'get_proper_path', + 'get_rand', 'get_routine_info', 'get_test_abort', 'get_test_logfile', + 'get_test_pause', 'get_test_verbosity', 'get_tzid', 'getd', 'getdd', + 'getd_all_keys', 'getd_by_index', 'getd_index', 'getd_partial_key', + 'glAttachShader', 'glBindBuffer', 'glBindTexture', 'glBufferData', + 'glCanvasSpecialText', 'glClear', 'glClearColor', 'glColor', + 'glCompileShader', 'glCreateBuffer', 'glCreateProgram', + 'glCreateShader', 'glCreateTexture', 'glDeleteProgram', + 'glDeleteShader', 'glDrawArrays', 'glEnable', + 'glEnableVertexAttribArray', 'glFloat32Array', 'glInt32Array', + 'glFlush', 'glGetAttribLocation', 'glGetError', 'glGetProgramInfoLog', + 'glGetProgramParameter', 'glGetShaderInfoLog', 'glGetShaderParameter', + 'glGetUniformLocation', 'glLinkProgram', 'glLoadIdentity', + 'glMatrixMode', 'glOrtho', 'glRotatef', 'glShadeModel', + 'glShaderSource', 'glSimpleA7texcoords', 'glTexImage2Dc', + 'glTexParameteri', 'glTranslate', 'glUniform1f', 'glUniform1i', + 'glUniformMatrix4fv', 'glUseProgram', 'glVertex', + 'glVertexAttribPointer', 'glViewport', 'head', 'hsv_to_rgb', 'iff', + 'iif', 'include_file', 'incl0de_file', 'insert', 'instance', + 'int_to_bits', 'int_to_bytes', 'is_dict', 'is_integer', 's_leap_year', + 'is_prime', 'is_prime2', 'islower', 'isupper', 'Icallback', + 'iup_isdouble', 'iup_isprint', 'iup_XkeyBase', 'IupAppend', 'IupAlarm', + 'IupBackgroundBox', 'IupButton', 'IupCalendar', 'IupCanvas', + 'IupClipboard', 'IupClose', 'IupCloseOnEscape', 'IupControlsOpen', + 'IupDatePick', 'IupDestroy', 'IupDialog', 'IupDrawArc', 'IupDrawBegin', + 'IupDrawEnd', 'IupDrawGetSize', 'IupDrawGetTextSize', 'IupDrawLine', + 'IupDrawRectangle', 'IupDrawText', 'IupExpander', 'IupFill', + 'IupFlatLabel', 'IupFlatList', 'IupFlatTree', 'IupFlush', 'IupFrame', + 'IupGetAttribute', 'IupGetAttributeId', 'IupGetAttributePtr', + 'IupGetBrother', 'IupGetChild', 'IupGetChildCount', 'IupGetClassName', + 'IupGetDialog', 'IupGetDialogChild', 'IupGetDouble', 'IupGetFocus', + 'IupGetGlobal', 'IupGetGlobalInt', 'IupGetGlobalIntInt', 'IupGetInt', + 'IupGetInt2', 'IupGetIntId', 'IupGetIntInt', 'IupGetParent', + 'IupGLCanvas', 'IupGLCanvasOpen', 'IupGLMakeCurrent', 'IupGraph', + 'IupHbox', 'IupHide', 'IupImage', 'IupImageRGBA', 'IupItem', + 'iupKeyCodeToName', 'IupLabel', 'IupLink', 'IupList', 'IupMap', + 'IupMenu', 'IupMenuItem', 'IupMessage', 'IupMessageDlg', 'IupMultiBox', + 'IupMultiLine', 'IupNextField', 'IupNormaliser', 'IupOpen', + 'IupPlayInput', 'IupPopup', 'IupPreviousField', 'IupProgressBar', + 'IupRadio', 'IupRecordInput', 'IupRedraw', 'IupRefresh', + 'IupRefreshChildren', 'IupSeparator', 'IupSetAttribute', + 'IupSetAttributes', 'IupSetAttributeHandle', 'IupSetAttributeId', + 'IupSetAttributePtr', 'IupSetCallback', 'IupSetCallbacks', + 'IupSetDouble', 'IupSetFocus', 'IupSetGlobal', 'IupSetGlobalInt', + 'IupSetGlobalFunction', 'IupSetHandle', 'IupSetInt', + 'IupSetStrAttribute', 'IupSetStrGlobal', 'IupShow', 'IupShowXY', + 'IupSplit', 'IupStoreAttribute', 'IupSubmenu', 'IupTable', + 'IupTableClearSelected', 'IupTableClick_cb', 'IupTableGetSelected', + 'IupTableResize_cb', 'IupTableSetData', 'IupTabs', 'IupText', + 'IupTimer', 'IupToggle', 'IupTreeAddNodes', 'IupTreeView', 'IupUpdate', + 'IupValuator', 'IupVbox', 'join', 'join_by', 'join_path', 'k_perm', + 'largest', 'lcm', 'length', 'log', 'log10', 'log2', 'lower', + 'm4_crossProduct', 'm4_inverse', 'm4_lookAt', 'm4_multiply', + 'm4_normalize', 'm4_perspective', 'm4_subtractVectors', 'm4_xRotate', + 'm4_yRotate', 'machine_bits', 'machine_word', 'match', 'match_all', + 'match_replace', 'max', 'maxsq', 'min', 'minsq', 'mod', 'mpfr_add', + 'mpfr_ceil', 'mpfr_cmp', 'mpfr_cmp_si', 'mpfr_const_pi', 'mpfr_div', + 'mpfr_div_si', 'mpfr_div_z', 'mpfr_floor', 'mpfr_free', 'mpfr_get_d', + 'mpfr_get_default_precision', 'mpfr_get_default_rounding_mode', + 'mpfr_get_fixed', 'mpfr_get_precision', 'mpfr_get_si', 'mpfr_init', + 'mpfr_inits', 'mpfr_init_set', 'mpfr_init_set_q', 'mpfr_init_set_z', + 'mpfr_mul', 'mpfr_mul_si', 'mpfr_pow_si', 'mpfr_set', 'mpfr_set_d', + 'mpfr_set_default_precision', 'mpfr_set_default_rounding_mode', + 'mpfr_set_precision', 'mpfr_set_q', 'mpfr_set_si', 'mpfr_set_str', + 'mpfr_set_z', 'mpfr_si_div', 'mpfr_si_sub', 'mpfr_sqrt', 'mpfr_sub', + 'mpfr_sub_si', 'mpq_abs', 'mpq_add', 'mpq_add_si', 'mpq_canonicalize', + 'mpq_cmp', 'mpq_cmp_si', 'mpq_div', 'mpq_div_2exp', 'mpq_free', + 'mpq_get_den', 'mpq_get_num', 'mpq_get_str', 'mpq_init', 'mpq_init_set', + 'mpq_init_set_si', 'mpq_init_set_str', 'mpq_init_set_z', 'mpq_inits', + 'mpq_inv', 'mpq_mul', 'mpq_neg', 'mpq_set', 'mpq_set_si', 'mpq_set_str', + 'mpq_set_z', 'mpq_sub', 'mpz_abs', 'mpz_add', 'mpz_addmul', + 'mpz_addmul_ui', 'mpz_addmul_si', 'mpz_add_si', 'mpz_add_ui', 'mpz_and', + 'mpz_bin_uiui', 'mpz_cdiv_q', 'mpz_cmp', 'mpz_cmp_si', 'mpz_divexact', + 'mpz_divexact_ui', 'mpz_divisible_p', 'mpz_divisible_ui_p', 'mpz_even', + 'mpz_fac_ui', 'mpz_factorstring', 'mpz_fdiv_q', 'mpz_fdiv_q_2exp', + 'mpz_fdiv_q_ui', 'mpz_fdiv_qr', 'mpz_fdiv_r', 'mpz_fdiv_ui', + 'mpz_fib_ui', 'mpz_fib2_ui', 'mpz_fits_atom', 'mpz_fits_integer', + 'mpz_free', 'mpz_gcd', 'mpz_gcd_ui', 'mpz_get_atom', 'mpz_get_integer', + 'mpz_get_short_str', 'mpz_get_str', 'mpz_init', 'mpz_init_set', + 'mpz_inits', 'mpz_invert', 'mpz_lcm', 'mpz_lcm_ui', 'mpz_max', + 'mpz_min', 'mpz_mod', 'mpz_mod_ui', 'mpz_mul', 'mpz_mul_2exp', + 'mpz_mul_d', 'mpz_mul_si', 'mpz_neg', 'mpz_nthroot', 'mpz_odd', + 'mpz_pollard_rho', 'mpz_pow_ui', 'mpz_powm', 'mpz_powm_ui', 'mpz_prime', + 'mpz_prime_factors', 'mpz_prime_mr', 'mpz_rand', 'mpz_rand_ui', + 'mpz_re_compose', 'mpz_remove', 'mpz_scan0', 'mpz_scan1', 'mpz_set', + 'mpz_set_d', 'mpz_set_si', 'mpz_set_str', 'mpz_set_v', 'mpz_sign', + 'mpz_sizeinbase', 'mpz_sqrt', 'mpz_sub', 'mpz_sub_si', 'mpz_sub_ui', + 'mpz_si_sub', 'mpz_tdiv_q_2exp', 'mpz_tdiv_r_2exp', 'mpz_tstbit', + 'mpz_ui_pow_ui', 'mpz_xor', 'named_dict', 'new_dict', 'new_queue', + 'new_stack', 'not_bits', 'not_bitsu', 'odd', 'or_all', 'or_allu', + 'or_bits', 'or_bitsu', 'ord', 'ordinal', 'ordinant', + 'override_timezone', 'pad', 'pad_head', 'pad_tail', 'parse_date_string', + 'papply', 'peep', 'peepn', 'peep_dict', 'permute', 'permutes', + 'platform', 'pop', 'popn', 'pop_dict', 'power', 'pp', 'ppEx', 'ppExf', + 'ppf', 'ppOpt', 'pq_add', 'pq_destroy', 'pq_empty', 'pq_new', 'pq_peek', + 'pq_pop', 'pq_pop_data', 'pq_size', 'prepend', 'prime_factors', + 'printf', 'product', 'proper', 'push', 'pushn', 'putd', 'puts', + 'queue_empty', 'queue_size', 'rand', 'rand_range', 'reinstate', + 'remainder', 'remove', 'remove_all', 'repeat', 'repeatch', 'replace', + 'requires', 'reverse', 'rfind', 'rgb', 'rmatch', 'rmdr', 'rnd', 'round', + 'routine_id', 'scanf', 'serialize', 'series', 'set_rand', + 'set_test_abort', 'set_test_logfile', 'set_test_module', + 'set_test_pause', 'set_test_verbosity', 'set_timedate_formats', + 'set_timezone', 'setd', 'setd_default', 'shorten', 'sha256', + 'shift_bits', 'shuffle', 'sign', 'sin', 'smallest', 'sort', + 'sort_columns', 'speak', 'splice', 'split', 'split_any', 'split_by', + 'sprint', 'sprintf', 'sq_abs', 'sq_add', 'sq_and', 'sq_and_bits', + 'sq_arccos', 'sq_arcsin', 'sq_arctan', 'sq_atom', 'sq_ceil', 'sq_cmp', + 'sq_cos', 'sq_div', 'sq_even', 'sq_eq', 'sq_floor', 'sq_floor_div', + 'sq_ge', 'sq_gt', 'sq_int', 'sq_le', 'sq_log', 'sq_log10', 'sq_log2', + 'sq_lt', 'sq_max', 'sq_min', 'sq_mod', 'sq_mul', 'sq_ne', 'sq_not', + 'sq_not_bits', 'sq_odd', 'sq_or', 'sq_or_bits', 'sq_power', 'sq_rand', + 'sq_remainder', 'sq_rmdr', 'sq_rnd', 'sq_round', 'sq_seq', 'sq_sign', + 'sq_sin', 'sq_sqrt', 'sq_str', 'sq_sub', 'sq_tan', 'sq_trunc', + 'sq_uminus', 'sq_xor', 'sq_xor_bits', 'sqrt', 'square_free', + 'stack_empty', 'stack_size', 'substitute', 'substitute_all', 'sum', + 'tail', 'tan', 'test_equal', 'test_fail', 'test_false', + 'test_not_equal', 'test_pass', 'test_summary', 'test_true', + 'text_color', 'throw', 'time', 'timedate_diff', 'timedelta', + 'to_integer', 'to_number', 'to_rgb', 'to_string', 'traverse_dict', + 'traverse_dict_partial_key', 'trim', 'trim_head', 'trim_tail', 'trunc', + 'tagset', 'tagstart', 'typeof', 'unique', 'unix_dict', 'upper', + 'utf8_to_utf32', 'utf32_to_utf8', 'version', 'vlookup', 'vslice', + 'wglGetProcAddress', 'wildcard_file', 'wildcard_match', 'with_rho', + 'with_theta', 'xml_new_doc', 'xml_new_element', 'xml_set_attribute', + 'xml_sprint', 'xor_bits', 'xor_bitsu', + 'accept', 'allocate', 'allocate_string', 'allow_break', 'ARM', + 'atom_to_float80', 'c_func', 'c_proc', 'call_back', 'chdir', + 'check_break', 'clearDib', 'close', 'closesocket', 'console', + 'copy_file', 'create', 'create_directory', 'create_thread', + 'curl_easy_cleanup', 'curl_easy_get_file', 'curl_easy_init', + 'curl_easy_perform', 'curl_easy_perform_ex', 'curl_easy_setopt', + 'curl_easy_strerror', 'curl_global_cleanup', 'curl_global_init', + 'curl_slist_append', 'curl_slist_free_all', 'current_dir', 'cursor', + 'define_c_func', 'define_c_proc', 'delete', 'delete_cs', 'delete_file', + 'dir', 'DLL', 'drawDib', 'drawShadedPolygonToDib', 'ELF32', 'ELF64', + 'enter_cs', 'eval', 'exit_thread', 'free', 'file_exists', 'final', + 'float80_to_atom', 'format', 'get_bytes', 'get_file_date', + 'get_file_size', 'get_file_type', 'get_interpreter', 'get_key', + 'get_socket_error', 'get_text', 'get_thread_exitcode', 'get_thread_id', + 'getc', 'getenv', 'gets', 'getsockaddr', 'glBegin', 'glCallList', + 'glFrustum', 'glGenLists', 'glGetString', 'glLight', 'glMaterial', + 'glNewList', 'glNormal', 'glPopMatrix', 'glPushMatrix', 'glRotate', + 'glEnd', 'glEndList', 'glTexImage2D', 'goto', 'GUI', 'icons', 'ilASM', + 'include_files', 'include_paths', 'init_cs', 'ip_to_string', + 'IupConfig', 'IupConfigDialogClosed', 'IupConfigDialogShow', + 'IupConfigGetVariableInt', 'IupConfigLoad', 'IupConfigSave', + 'IupConfigSetVariableInt', 'IupExitLoop', 'IupFileDlg', 'IupFileList', + 'IupGLSwapBuffers', 'IupHelp', 'IupLoopStep', 'IupMainLoop', + 'IupNormalizer', 'IupPlot', 'IupPlotAdd', 'IupPlotBegin', 'IupPlotEnd', + 'IupPlotInsert', 'IupSaveImage', 'IupTreeGetUserId', 'IupUser', + 'IupVersion', 'IupVersionDate', 'IupVersionNumber', 'IupVersionShow', + 'killDib', 'leave_cs', 'listen', 'manifest', 'mem_copy', 'mem_set', + 'mpfr_gamma', 'mpfr_printf', 'mpfr_sprintf', 'mpz_export', 'mpz_import', + 'namespace', 'new', 'newDib', 'open', 'open_dll', 'PE32', 'PE64', + 'peek', 'peek_string', 'peek1s', 'peek1u', 'peek2s', 'peek2u', 'peek4s', + 'peek4u', 'peek8s', 'peek8u', 'peekNS', 'peekns', 'peeknu', 'poke', + 'poke2', 'poke4', 'poke8', 'pokeN', 'poke_string', 'poke_wstring', + 'position', 'progress', 'prompt_number', 'prompt_string', 'read_file', + 'read_lines', 'recv', 'resume_thread', 'seek', 'select', 'send', + 'setHandler', 'shutdown', 'sleep', 'SO', 'sockaddr_in', 'socket', + 'split_path', 'suspend_thread', 'system', 'system_exec', 'system_open', + 'system_wait', 'task_clock_start', 'task_clock_stop', 'task_create', + 'task_delay', 'task_list', 'task_schedule', 'task_self', 'task_status', + 'task_suspend', 'task_yield', 'thread_safe_string', 'try_cs', + 'utf8_to_utf16', 'utf16_to_utf8', 'utf16_to_utf32', 'utf32_to_utf16', + 'video_config', 'WSACleanup', 'wait_thread', 'walk_dir', 'where', + 'write_lines', 'wait_key' + ) + constants = ( + 'ANY_QUEUE', 'ASCENDING', 'BLACK', 'BLOCK_CURSOR', 'BLUE', + 'BRIGHT_CYAN', 'BRIGHT_BLUE', 'BRIGHT_GREEN', 'BRIGHT_MAGENTA', + 'BRIGHT_RED', 'BRIGHT_WHITE', 'BROWN', 'C_DWORD', 'C_INT', 'C_POINTER', + 'C_USHORT', 'C_WORD', 'CD_AMBER', 'CD_BLACK', 'CD_BLUE', 'CD_BOLD', + 'CD_BOLD_ITALIC', 'CD_BOX', 'CD_CENTER', 'CD_CIRCLE', 'CD_CLOSED_LINES', + 'CD_CONTINUOUS', 'CD_CUSTOM', 'CD_CYAN', 'CD_DARK_BLUE', 'CD_DARK_CYAN', + 'CD_DARK_GRAY', 'CD_DARK_GREY', 'CD_DARK_GREEN', 'CD_DARK_MAGENTA', + 'CD_DARK_RED', 'CD_DARK_YELLOW', 'CD_DASH_DOT', 'CD_DASH_DOT_DOT', + 'CD_DASHED', 'CD_DBUFFER', 'CD_DEG2RAD', 'CD_DIAMOND', 'CD_DOTTED', + 'CD_EAST', 'CD_EVENODD', 'CD_FILL', 'CD_GL', 'CD_GRAY', 'CD_GREY', + 'CD_GREEN', 'CD_HATCH', 'CD_HOLLOW', 'CD_HOLLOW_BOX', + 'CD_HOLLOW_CIRCLE', 'CD_HOLLOW_DIAMOND', 'CD_INDIGO', 'CD_ITALIC', + 'CD_IUP', 'CD_IUPDBUFFER', 'CD_LIGHT_BLUE', 'CD_LIGHT_GRAY', + 'CD_LIGHT_GREY', 'CD_LIGHT_GREEN', 'CD_LIGHT_PARCHMENT', 'CD_MAGENTA', + 'CD_NAVY', 'CD_NORTH', 'CD_NORTH_EAST', 'CD_NORTH_WEST', 'CD_OLIVE', + 'CD_OPEN_LINES', 'CD_ORANGE', 'CD_PARCHMENT', 'CD_PATTERN', + 'CD_PRINTER', 'CD_PURPLE', 'CD_PLAIN', 'CD_PLUS', 'CD_QUERY', + 'CD_RAD2DEG', 'CD_RED', 'CD_SILVER', 'CD_SOLID', 'CD_SOUTH_EAST', + 'CD_SOUTH_WEST', 'CD_STAR', 'CD_STIPPLE', 'CD_STRIKEOUT', + 'CD_UNDERLINE', 'CD_WEST', 'CD_WHITE', 'CD_WINDING', 'CD_VIOLET', + 'CD_X', 'CD_YELLOW', 'CURLE_OK', 'CURLOPT_MAIL_FROM', + 'CURLOPT_MAIL_RCPT', 'CURLOPT_PASSWORD', 'CURLOPT_READDATA', + 'CURLOPT_READFUNCTION', 'CURLOPT_SSL_VERIFYPEER', + 'CURLOPT_SSL_VERIFYHOST', 'CURLOPT_UPLOAD', 'CURLOPT_URL', + 'CURLOPT_USE_SSL', 'CURLOPT_USERNAME', 'CURLOPT_VERBOSE', + 'CURLOPT_WRITEFUNCTION', 'CURLUSESSL_ALL', 'CYAN', 'D_NAME', + 'D_ATTRIBUTES', 'D_SIZE', 'D_YEAR', 'D_MONTH', 'D_DAY', 'D_HOUR', + 'D_MINUTE', 'D_SECOND', 'D_CREATION', 'D_LASTACCESS', 'D_MODIFICATION', + 'DT_YEAR', 'DT_MONTH', 'DT_DAY', 'DT_HOUR', 'DT_MINUTE', 'DT_SECOND', + 'DT_DOW', 'DT_MSEC', 'DT_DOY', 'DT_GMT', 'EULER', 'E_CODE', 'E_ADDR', + 'E_LINE', 'E_RTN', 'E_NAME', 'E_FILE', 'E_PATH', 'E_USER', 'false', + 'False', 'FALSE', 'FIFO_QUEUE', 'FILETYPE_DIRECTORY', 'FILETYPE_FILE', + 'GET_EOF', 'GET_FAIL', 'GET_IGNORE', 'GET_SUCCESS', + 'GL_AMBIENT_AND_DIFFUSE', 'GL_ARRAY_BUFFER', 'GL_CLAMP', + 'GL_CLAMP_TO_BORDER', 'GL_CLAMP_TO_EDGE', 'GL_COLOR_BUFFER_BIT', + 'GL_COMPILE', 'GL_COMPILE_STATUS', 'GL_CULL_FACE', + 'GL_DEPTH_BUFFER_BIT', 'GL_DEPTH_TEST', 'GL_EXTENSIONS', 'GL_FLAT', + 'GL_FLOAT', 'GL_FRAGMENT_SHADER', 'GL_FRONT', 'GL_LIGHT0', + 'GL_LIGHTING', 'GL_LINEAR', 'GL_LINK_STATUS', 'GL_MODELVIEW', + 'GL_NEAREST', 'GL_NO_ERROR', 'GL_NORMALIZE', 'GL_POSITION', + 'GL_PROJECTION', 'GL_QUAD_STRIP', 'GL_QUADS', 'GL_RENDERER', + 'GL_REPEAT', 'GL_RGB', 'GL_RGBA', 'GL_SMOOTH', 'GL_STATIC_DRAW', + 'GL_TEXTURE_2D', 'GL_TEXTURE_MAG_FILTER', 'GL_TEXTURE_MIN_FILTER', + 'GL_TEXTURE_WRAP_S', 'GL_TEXTURE_WRAP_T', 'GL_TRIANGLES', + 'GL_UNSIGNED_BYTE', 'GL_VENDOR', 'GL_VERSION', 'GL_VERTEX_SHADER', + 'GRAY', 'GREEN', 'GT_LF_STRIPPED', 'GT_WHOLE_FILE', 'INVLN10', + 'IUP_CLOSE', 'IUP_CONTINUE', 'IUP_DEFAULT', 'IUP_BLACK', 'IUP_BLUE', + 'IUP_BUTTON1', 'IUP_BUTTON3', 'IUP_CENTER', 'IUP_CYAN', 'IUP_DARK_BLUE', + 'IUP_DARK_CYAN', 'IUP_DARK_GRAY', 'IUP_DARK_GREY', 'IUP_DARK_GREEN', + 'IUP_DARK_MAGENTA', 'IUP_DARK_RED', 'IUP_GRAY', 'IUP_GREY', 'IUP_GREEN', + 'IUP_IGNORE', 'IUP_INDIGO', 'IUP_MAGENTA', 'IUP_MASK_INT', + 'IUP_MASK_UINT', 'IUP_MOUSEPOS', 'IUP_NAVY', 'IUP_OLIVE', 'IUP_RECTEXT', + 'IUP_RED', 'IUP_LIGHT_BLUE', 'IUP_LIGHT_GRAY', 'IUP_LIGHT_GREY', + 'IUP_LIGHT_GREEN', 'IUP_ORANGE', 'IUP_PARCHMENT', 'IUP_PURPLE', + 'IUP_SILVER', 'IUP_TEAL', 'IUP_VIOLET', 'IUP_WHITE', 'IUP_YELLOW', + 'K_BS', 'K_cA', 'K_cC', 'K_cD', 'K_cF5', 'K_cK', 'K_cM', 'K_cN', 'K_cO', + 'K_cP', 'K_cR', 'K_cS', 'K_cT', 'K_cW', 'K_CR', 'K_DEL', 'K_DOWN', + 'K_END', 'K_ESC', 'K_F1', 'K_F2', 'K_F3', 'K_F4', 'K_F5', 'K_F6', + 'K_F7', 'K_F8', 'K_F9', 'K_F10', 'K_F11', 'K_F12', 'K_HOME', 'K_INS', + 'K_LEFT', 'K_MIDDLE', 'K_PGDN', 'K_PGUP', 'K_RIGHT', 'K_SP', 'K_TAB', + 'K_UP', 'K_h', 'K_i', 'K_j', 'K_p', 'K_r', 'K_s', 'JS', 'LIFO_QUEUE', + 'LINUX', 'MAX_HEAP', 'MAGENTA', 'MIN_HEAP', 'Nan', 'NO_CURSOR', 'null', + 'NULL', 'PI', 'pp_Ascii', 'pp_Brkt', 'pp_Date', 'pp_File', 'pp_FltFmt', + 'pp_Indent', 'pp_IntCh', 'pp_IntFmt', 'pp_Maxlen', 'pp_Nest', + 'pp_Pause', 'pp_Q22', 'pp_StrFmt', 'RED', 'SEEK_OK', 'SLASH', + 'TEST_ABORT', 'TEST_CRASH', 'TEST_PAUSE', 'TEST_PAUSE_FAIL', + 'TEST_QUIET', 'TEST_SHOW_ALL', 'TEST_SHOW_FAILED', 'TEST_SUMMARY', + 'true', 'True', 'TRUE', 'VC_SCRNLINES', 'WHITE', 'WINDOWS', 'YELLOW' + ) + + tokens = { + 'root': [ + (r"\s+", Whitespace), + (r'/\*|--/\*|#\[', Comment.Multiline, 'comment'), + (r'(?://|--|#!).*$', Comment.Single), +#Alt: +# (r'//.*$|--.*$|#!.*$', Comment.Single), + (r'"([^"\\]|\\.)*"', String.Other), + (r'\'[^\']*\'', String.Other), + (r'`[^`]*`', String.Other), + + (words(types, prefix=r'\b', suffix=r'\b'), Name.Function), + (words(routines, prefix=r'\b', suffix=r'\b'), Name.Function), + (words(preproc, prefix=r'\b', suffix=r'\b'), Keyword.Declaration), + (words(keywords, prefix=r'\b', suffix=r'\b'), Keyword.Declaration), + (words(constants, prefix=r'\b', suffix=r'\b'), Name.Constant), + # Aside: Phix only supports/uses the ascii/non-unicode tilde + (r'!=|==|<<|>>|:=|[-~+/*%=<>&^|\.(){},?:\[\]$\\;#]', Operator), + (r'[\w-]+', Text) + ], + 'comment': [ + (r'[^*/#]+', Comment.Multiline), + (r'/\*|#\[', Comment.Multiline, '#push'), + (r'\*/|#\]', Comment.Multiline, '#pop'), + (r'[*/#]', Comment.Multiline) + ] + } + diff --git a/tests/examplefiles/phix/example.exw b/tests/examplefiles/phix/example.exw new file mode 100644 index 0000000000..583feed77d --- /dev/null +++ b/tests/examplefiles/phix/example.exw @@ -0,0 +1,85 @@ +#!/bin/bash +#[ + echo Phix ignores all text between #[ and #] in exactly the same way as /* and */ + echo (both "and" are nested comments), allowing arbitrary shell code, for example: + cd /user/project/working + exec /path/to/phix "$0" "$@" + exit # may be needed for the shell to ignore the rest of this file. +# comments(/shebang) ignored by Phix end here -> #] +-- aside: few files have [multiline] shebangs like above, but this *is* a test file. +/* + Standard + /* + ** Nested + ** /* + ** Block + *//* /* + ** Comments, of which Phix has quite a few [ok, six] varieties... + ** */ + *****/ + **/ +*/ +--/* + Euphoria-compatibility-style nestable multiline comments/code +--*/ +// This program should be runnable (C-style line comments, btw, too!) +with javascript_semantics +string pe, te := iff(platform()==JS?"JavaScript/browser":"Phix/desktop") +ifdef PHIX then + pe = "Phix" +elsedef + pe = "Euphoria" -- not that this file is compatible with that.. +end ifdef +printf(1,"This is %s (%s)\n",{pe,te}); -- the ; is entirely optional +assert("\n\r\b\t\\\"\'\0\e"=join({"",10,13,8,9,#5C,#22,#27,#00,#1B},"")) +assert("\#42\x43\u4445\U00105678"="B"&'C'&"\xE4\x91\x85\xF4\x85\x99\xB8") + +-- triplequote, triplequote indented, backtick, and doublequote strings: +constant tqs = """ +this +string\thing""", + +tqis = """ +_____this + string\thing""", + +bts = `this +string\thing`, + +dqs = "this\nstring\\thing" +assert(tqs==tqis and tqis==bts and bts==dqs and dqs==tqs) +assert(x"1 2 34 5678_AbC"=={0x01, 0x02, 0x34, 0x56, 0x78, 0xAB, 0x0C}) + +-- Beyond comments and strings, not much in Phix bothers a syntax colourer. +-- Originally I had another 380+ lines in here, that didn't prove anything. + +function merge_sort(sequence x) + -- put x into ascending order using a recursive merge sort + if length(x)<=1 then + return x -- trivial case + end if + integer midpoint = floor(length(x)/2) + sequence merged = {}, + first_half = merge_sort(x[1..midpoint]), + second_half = merge_sort(x[midpoint+1..$]) + -- merge the two sorted halves into one + while length(first_half)>0 + and length(second_half)>0 do + if first_half[1]<=second_half[1] then + merged = append(merged, first_half[1]) + first_half = first_half[2..$] + else + merged = append(merged, second_half[1]) + second_half = second_half[2..$] + end if + end while + -- result is the merged data plus any leftovers + return merged & first_half & second_half +end function + +?merge_sort({9, 10, 3, 1, 4, 5, 8, 7, 6, 2}) +?{1,0(2)10,0b11,0d4,0t5,0(6)10,0(7)10,0o10,0x9,#A} -- [the same 1..10 but with extra weirdness] + +wait_key() + + diff --git a/tests/examplefiles/phix/example.exw.output b/tests/examplefiles/phix/example.exw.output new file mode 100644 index 0000000000..107709b042 --- /dev/null +++ b/tests/examplefiles/phix/example.exw.output @@ -0,0 +1,606 @@ +'#!/bin/bash' Comment.Single +'\n' Text.Whitespace + +'#[' Comment.Multiline +'\n echo Phix ignores all text between ' Comment.Multiline +'#[' Comment.Multiline +' and ' Comment.Multiline +'#]' Comment.Multiline +' in exactly the same way as ' Comment.Multiline +'/*' Comment.Multiline +' and ' Comment.Multiline +'*/' Comment.Multiline +' \n echo (both "and" are nested comments), allowing arbitrary shell code, for example:\n cd ' Comment.Multiline +'/' Comment.Multiline +'user' Comment.Multiline +'/' Comment.Multiline +'project' Comment.Multiline +'/' Comment.Multiline +'working\n exec ' Comment.Multiline +'/' Comment.Multiline +'path' Comment.Multiline +'/' Comment.Multiline +'to' Comment.Multiline +'/' Comment.Multiline +'phix "$0" "$@"\n exit ' Comment.Multiline +'#' Comment.Multiline +' may be needed for the shell to ignore the rest of this file.\n' Comment.Multiline + +'#' Comment.Multiline +' comments(' Comment.Multiline +'/' Comment.Multiline +'shebang) ignored by Phix end here -> ' Comment.Multiline +'#]' Comment.Multiline +'\n' Text.Whitespace + +'-- aside: few files have [multiline] shebangs like above, but this *is* a test file.' Comment.Single +'\n' Text.Whitespace + +'/*' Comment.Multiline +' \n Standard\n ' Comment.Multiline +'/*' Comment.Multiline +'\n ' Comment.Multiline +'*' Comment.Multiline +'*' Comment.Multiline +' Nested\n ' Comment.Multiline +'*' Comment.Multiline +'*' Comment.Multiline +' ' Comment.Multiline +'/*' Comment.Multiline +'\n ' Comment.Multiline +'*' Comment.Multiline +'*' Comment.Multiline +' Block\n ' Comment.Multiline +'*/' Comment.Multiline +'/*' Comment.Multiline +' ' Comment.Multiline +'/*' Comment.Multiline +'\n ' Comment.Multiline +'*' Comment.Multiline +'*' Comment.Multiline +' Comments, of which Phix has quite a few [ok, six] varieties...\n ' Comment.Multiline +'*' Comment.Multiline +'*' Comment.Multiline +' ' Comment.Multiline +'*/' Comment.Multiline +'\n ' Comment.Multiline +'*' Comment.Multiline +'*' Comment.Multiline +'*' Comment.Multiline +'*' Comment.Multiline +'*/' Comment.Multiline +'\n ' Comment.Multiline +'*' Comment.Multiline +'*/' Comment.Multiline +'\n' Comment.Multiline + +'*/' Comment.Multiline +'\n' Text.Whitespace + +'--/*' Comment.Multiline +'\n Euphoria-compatibility-style nestable multiline comments' Comment.Multiline +'/' Comment.Multiline +'code\n--' Comment.Multiline +'*/' Comment.Multiline +'\n' Text.Whitespace + +'// This program should be runnable (C-style line comments, btw, too!)' Comment.Single +'\n' Text.Whitespace + +'with' Keyword.Declaration +' ' Text.Whitespace +'javascript_semantics' Keyword.Declaration +'\n' Text.Whitespace + +'string' Name.Function +' ' Text.Whitespace +'pe' Text +',' Operator +' ' Text.Whitespace +'te' Text +' ' Text.Whitespace +':=' Operator +' ' Text.Whitespace +'iff' Name.Function +'(' Operator +'platform' Name.Function +'(' Operator +')' Operator +'==' Operator +'JS' Name.Constant +'?' Operator +'"JavaScript/browser"' Literal.String.Other +':' Operator +'"Phix/desktop"' Literal.String.Other +')' Operator +'\n' Text.Whitespace + +'ifdef' Keyword.Declaration +' ' Text.Whitespace +'PHIX' Text +' ' Text.Whitespace +'then' Keyword.Declaration +' \n ' Text.Whitespace +'pe' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'"Phix"' Literal.String.Other +' \n' Text.Whitespace + +'elsedef' Keyword.Declaration +' \n ' Text.Whitespace +'pe' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'"Euphoria"' Literal.String.Other +' ' Text.Whitespace +'-- not that this file is compatible with that..' Comment.Single +'\n' Text.Whitespace + +'end' Keyword.Declaration +' ' Text.Whitespace +'ifdef' Keyword.Declaration +' \n' Text.Whitespace + +'printf' Name.Function +'(' Operator +'1' Text +',' Operator +'"This is %s (%s)\\n"' Literal.String.Other +',' Operator +'{' Operator +'pe' Text +',' Operator +'te' Text +'}' Operator +')' Operator +';' Operator +' ' Text.Whitespace +'-- the ; is entirely optional' Comment.Single +'\n' Text.Whitespace + +'assert' Name.Function +'(' Operator +'"\\n\\r\\b\\t\\\\\\"\\\'\\0\\e"' Literal.String.Other +'=' Operator +'join' Name.Function +'(' Operator +'{' Operator +'""' Literal.String.Other +',' Operator +'10' Text +',' Operator +'13' Text +',' Operator +'8' Text +',' Operator +'9' Text +',' Operator +'#' Operator +'5C' Text +',' Operator +'#' Operator +'22' Text +',' Operator +'#' Operator +'27' Text +',' Operator +'#' Operator +'00' Text +',' Operator +'#' Operator +'1B' Text +'}' Operator +',' Operator +'""' Literal.String.Other +')' Operator +')' Operator +'\n' Text.Whitespace + +'assert' Name.Function +'(' Operator +'"\\#42\\x43\\u4445\\U00105678"' Literal.String.Other +'=' Operator +'"B"' Literal.String.Other +'&' Operator +"'C'" Literal.String.Other +'&' Operator +'"\\xE4\\x91\\x85\\xF4\\x85\\x99\\xB8"' Literal.String.Other +')' Operator +'\n\n' Text.Whitespace + +'-- triplequote, triplequote indented, backtick, and doublequote strings:' Comment.Single +'\n' Text.Whitespace + +'constant' Keyword.Declaration +' ' Text.Whitespace +'tqs' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'""' Literal.String.Other +'"\nthis\nstring\\thing"' Literal.String.Other +'""' Literal.String.Other +',' Operator +'\n\n' Text.Whitespace + +'tqis' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'""' Literal.String.Other +'"\n_____this\n string\\thing"' Literal.String.Other +'""' Literal.String.Other +',' Operator +'\n\n' Text.Whitespace + +'bts' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'`this\nstring\\thing`' Literal.String.Other +',' Operator +'\n\n' Text.Whitespace + +'dqs' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'"this\\nstring\\\\thing"' Literal.String.Other +'\n' Text.Whitespace + +'assert' Name.Function +'(' Operator +'tqs' Text +'==' Operator +'tqis' Text +' ' Text.Whitespace +'and' Keyword.Declaration +' ' Text.Whitespace +'tqis' Text +'==' Operator +'bts' Text +' ' Text.Whitespace +'and' Keyword.Declaration +' ' Text.Whitespace +'bts' Text +'==' Operator +'dqs' Text +' ' Text.Whitespace +'and' Keyword.Declaration +' ' Text.Whitespace +'dqs' Text +'==' Operator +'tqs' Text +')' Operator +'\n' Text.Whitespace + +'assert' Name.Function +'(' Operator +'x' Text +'"1 2 34 5678_AbC"' Literal.String.Other +'==' Operator +'{' Operator +'0x01' Text +',' Operator +' ' Text.Whitespace +'0x02' Text +',' Operator +' ' Text.Whitespace +'0x34' Text +',' Operator +' ' Text.Whitespace +'0x56' Text +',' Operator +' ' Text.Whitespace +'0x78' Text +',' Operator +' ' Text.Whitespace +'0xAB' Text +',' Operator +' ' Text.Whitespace +'0x0C' Text +'}' Operator +')' Operator +'\n\n' Text.Whitespace + +'-- Beyond comments and strings, not much in Phix bothers a syntax colourer.' Comment.Single +'\n' Text.Whitespace + +"-- Originally I had another 380+ lines in here, that didn't prove anything." Comment.Single +'\n\n' Text.Whitespace + +'function' Keyword.Declaration +' ' Text.Whitespace +'merge_sort' Text +'(' Operator +'sequence' Name.Function +' ' Text.Whitespace +'x' Text +')' Operator +'\n ' Text.Whitespace +'-- put x into ascending order using a recursive merge sort' Comment.Single +'\n ' Text.Whitespace +'if' Keyword.Declaration +' ' Text.Whitespace +'length' Name.Function +'(' Operator +'x' Text +')' Operator +'<' Operator +'=' Operator +'1' Text +' ' Text.Whitespace +'then' Keyword.Declaration +'\n ' Text.Whitespace +'return' Keyword.Declaration +' ' Text.Whitespace +'x' Text +' ' Text.Whitespace +'-- trivial case' Comment.Single +'\n ' Text.Whitespace +'end' Keyword.Declaration +' ' Text.Whitespace +'if' Keyword.Declaration +'\n ' Text.Whitespace +'integer' Name.Function +' ' Text.Whitespace +'midpoint' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'floor' Name.Function +'(' Operator +'length' Name.Function +'(' Operator +'x' Text +')' Operator +'/' Operator +'2' Text +')' Operator +'\n ' Text.Whitespace +'sequence' Name.Function +' ' Text.Whitespace +'merged' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'{' Operator +'}' Operator +',' Operator +'\n ' Text.Whitespace +'first_half' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'merge_sort' Text +'(' Operator +'x' Text +'[' Operator +'1' Text +'.' Operator +'.' Operator +'midpoint' Text +']' Operator +')' Operator +',' Operator +'\n ' Text.Whitespace +'second_half' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'merge_sort' Text +'(' Operator +'x' Text +'[' Operator +'midpoint' Text +'+' Operator +'1' Text +'.' Operator +'.' Operator +'$' Operator +']' Operator +')' Operator +'\n ' Text.Whitespace +'-- merge the two sorted halves into one' Comment.Single +'\n ' Text.Whitespace +'while' Keyword.Declaration +' ' Text.Whitespace +'length' Name.Function +'(' Operator +'first_half' Text +')' Operator +'>' Operator +'0' Text +' \n ' Text.Whitespace +'and' Keyword.Declaration +' ' Text.Whitespace +'length' Name.Function +'(' Operator +'second_half' Text +')' Operator +'>' Operator +'0' Text +' ' Text.Whitespace +'do' Keyword.Declaration +'\n ' Text.Whitespace +'if' Keyword.Declaration +' ' Text.Whitespace +'first_half' Text +'[' Operator +'1' Text +']' Operator +'<' Operator +'=' Operator +'second_half' Text +'[' Operator +'1' Text +']' Operator +' ' Text.Whitespace +'then' Keyword.Declaration +'\n ' Text.Whitespace +'merged' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'append' Name.Function +'(' Operator +'merged' Text +',' Operator +' ' Text.Whitespace +'first_half' Text +'[' Operator +'1' Text +']' Operator +')' Operator +'\n ' Text.Whitespace +'first_half' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'first_half' Text +'[' Operator +'2' Text +'.' Operator +'.' Operator +'$' Operator +']' Operator +'\n ' Text.Whitespace +'else' Keyword.Declaration +'\n ' Text.Whitespace +'merged' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'append' Name.Function +'(' Operator +'merged' Text +',' Operator +' ' Text.Whitespace +'second_half' Text +'[' Operator +'1' Text +']' Operator +')' Operator +'\n ' Text.Whitespace +'second_half' Text +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'second_half' Text +'[' Operator +'2' Text +'.' Operator +'.' Operator +'$' Operator +']' Operator +'\n ' Text.Whitespace +'end' Keyword.Declaration +' ' Text.Whitespace +'if' Keyword.Declaration +'\n ' Text.Whitespace +'end' Keyword.Declaration +' ' Text.Whitespace +'while' Keyword.Declaration +'\n ' Text.Whitespace +'-- result is the merged data plus any leftovers' Comment.Single +'\n ' Text.Whitespace +'return' Keyword.Declaration +' ' Text.Whitespace +'merged' Text +' ' Text.Whitespace +'&' Operator +' ' Text.Whitespace +'first_half' Text +' ' Text.Whitespace +'&' Operator +' ' Text.Whitespace +'second_half' Text +'\n' Text.Whitespace + +'end' Keyword.Declaration +' ' Text.Whitespace +'function' Keyword.Declaration +'\n\n' Text.Whitespace + +'?' Operator +'merge_sort' Text +'(' Operator +'{' Operator +'9' Text +',' Operator +' ' Text.Whitespace +'10' Text +',' Operator +' ' Text.Whitespace +'3' Text +',' Operator +' ' Text.Whitespace +'1' Text +',' Operator +' ' Text.Whitespace +'4' Text +',' Operator +' ' Text.Whitespace +'5' Text +',' Operator +' ' Text.Whitespace +'8' Text +',' Operator +' ' Text.Whitespace +'7' Text +',' Operator +' ' Text.Whitespace +'6' Text +',' Operator +' ' Text.Whitespace +'2' Text +'}' Operator +')' Operator +'\n' Text.Whitespace + +'?' Operator +'{' Operator +'1' Text +',' Operator +'0' Text +'(' Operator +'2' Text +')' Operator +'10' Text +',' Operator +'0b11' Text +',' Operator +'0d4' Text +',' Operator +'0t5' Text +',' Operator +'0' Text +'(' Operator +'6' Text +')' Operator +'10' Text +',' Operator +'0' Text +'(' Operator +'7' Text +')' Operator +'10' Text +',' Operator +'0o10' Text +',' Operator +'0x9' Text +',' Operator +'#' Operator +'A' Text +'}' Operator +' ' Text.Whitespace +'-- [the same 1..10 but with extra weirdness]' Comment.Single +'\n\n' Text.Whitespace + +'wait_key' Name.Function +'(' Operator +')' Operator +'\n' Text.Whitespace