From 986040bc48a271b693ac81814b3c4607da6db1a3 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Tue, 2 Feb 2021 21:01:08 -0500 Subject: finished rust syntax highlighting --- keywords.h | 34 ++++++++++++++++++++++++---------- keywords.py | 17 +++++++++++++---- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/keywords.h b/keywords.h index d364c6f..b9d80f1 100644 --- a/keywords.h +++ b/keywords.h @@ -91,27 +91,41 @@ static Keyword const *const syntax_all_keywords_cpp[] = { ['A'] = syntax_keywords_cpp_A, ['B'] = syntax_keywords_cpp_B, ['C'] = syntax_keywords_cpp_C, ['D'] = syntax_keywords_cpp_D, ['E'] = syntax_keywords_cpp_E, ['F'] = syntax_keywords_cpp_F, ['H'] = syntax_keywords_cpp_H, ['I'] = syntax_keywords_cpp_I, ['L'] = syntax_keywords_cpp_L, ['M'] = syntax_keywords_cpp_M, ['N'] = syntax_keywords_cpp_N, ['O'] = syntax_keywords_cpp_O, ['P'] = syntax_keywords_cpp_P, ['R'] = syntax_keywords_cpp_R, ['S'] = syntax_keywords_cpp_S, ['T'] = syntax_keywords_cpp_T, ['U'] = syntax_keywords_cpp_U, ['W'] = syntax_keywords_cpp_W, ['_'] = syntax_keywords_cpp__, ['a'] = syntax_keywords_cpp_a, ['b'] = syntax_keywords_cpp_b, ['c'] = syntax_keywords_cpp_c, ['d'] = syntax_keywords_cpp_d, ['e'] = syntax_keywords_cpp_e, ['f'] = syntax_keywords_cpp_f, ['g'] = syntax_keywords_cpp_g, ['i'] = syntax_keywords_cpp_i, ['j'] = syntax_keywords_cpp_j, ['l'] = syntax_keywords_cpp_l, ['m'] = syntax_keywords_cpp_m, ['n'] = syntax_keywords_cpp_n, ['o'] = syntax_keywords_cpp_o, ['p'] = syntax_keywords_cpp_p, ['r'] = syntax_keywords_cpp_r, ['s'] = syntax_keywords_cpp_s, ['t'] = syntax_keywords_cpp_t, ['u'] = syntax_keywords_cpp_u, ['v'] = syntax_keywords_cpp_v, ['w'] = syntax_keywords_cpp_w, ['x'] = syntax_keywords_cpp_x }; -static Keyword const syntax_keywords_rust_S[2] = {{"Self", SYNTAX_KEYWORD}}; +static Keyword const syntax_keywords_rust_A[3] = {{"AsMut", SYNTAX_BUILTIN},{"AsRef", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_B[2] = {{"Box", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_C[3] = {{"Clone", SYNTAX_BUILTIN},{"Copy", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_D[4] = {{"Default", SYNTAX_BUILTIN},{"DoubleEndedIterator", SYNTAX_BUILTIN},{"Drop", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_E[5] = {{"Eq", SYNTAX_BUILTIN},{"Err", SYNTAX_BUILTIN},{"ExactSizeIterator", SYNTAX_BUILTIN},{"Extend", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_F[5] = {{"Fn", SYNTAX_BUILTIN},{"FnMut", SYNTAX_BUILTIN},{"FnOnce", SYNTAX_BUILTIN},{"From", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_I[4] = {{"Into", SYNTAX_BUILTIN},{"IntoIterator", SYNTAX_BUILTIN},{"Iterator", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_N[2] = {{"None", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_O[4] = {{"Ok", SYNTAX_BUILTIN},{"Option", SYNTAX_BUILTIN},{"Ord", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_P[3] = {{"PartialEq", SYNTAX_BUILTIN},{"PartialOrd", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_R[2] = {{"Result", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_S[7] = {{"Self", SYNTAX_KEYWORD},{"Send", SYNTAX_BUILTIN},{"Sized", SYNTAX_BUILTIN},{"Some", SYNTAX_BUILTIN},{"String", SYNTAX_BUILTIN},{"Sync", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_T[3] = {{"ToOwned", SYNTAX_BUILTIN},{"ToString", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_U[2] = {{"Unpin", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_V[2] = {{"Vec", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_a[9] = {{"abstract", SYNTAX_KEYWORD},{"as", SYNTAX_KEYWORD},{"async", SYNTAX_KEYWORD},{"await", SYNTAX_KEYWORD},{"asm!", SYNTAX_BUILTIN},{"assert!", SYNTAX_BUILTIN},{"assert_eq!", SYNTAX_BUILTIN},{"assert_ne!", SYNTAX_BUILTIN}}; -static Keyword const syntax_keywords_rust_b[4] = {{"become", SYNTAX_KEYWORD},{"box", SYNTAX_KEYWORD},{"break", SYNTAX_KEYWORD}}; -static Keyword const syntax_keywords_rust_c[9] = {{"const", SYNTAX_KEYWORD},{"continue", SYNTAX_KEYWORD},{"crate", SYNTAX_KEYWORD},{"cfg!", SYNTAX_BUILTIN},{"column!", SYNTAX_BUILTIN},{"compile_error!", SYNTAX_BUILTIN},{"concat!", SYNTAX_BUILTIN},{"concat_idents!", SYNTAX_BUILTIN}}; -static Keyword const syntax_keywords_rust_d[7] = {{"do", SYNTAX_KEYWORD},{"dyn", SYNTAX_KEYWORD},{"dbg!", SYNTAX_BUILTIN},{"debug_assert!", SYNTAX_BUILTIN},{"debug_assert_eq!", SYNTAX_BUILTIN},{"debug_assert_ne!", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_b[5] = {{"become", SYNTAX_KEYWORD},{"box", SYNTAX_KEYWORD},{"break", SYNTAX_KEYWORD},{"bool", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_c[10] = {{"const", SYNTAX_KEYWORD},{"continue", SYNTAX_KEYWORD},{"crate", SYNTAX_KEYWORD},{"cfg!", SYNTAX_BUILTIN},{"char", SYNTAX_BUILTIN},{"column!", SYNTAX_BUILTIN},{"compile_error!", SYNTAX_BUILTIN},{"concat!", SYNTAX_BUILTIN},{"concat_idents!", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_d[8] = {{"do", SYNTAX_KEYWORD},{"dyn", SYNTAX_KEYWORD},{"dbg!", SYNTAX_BUILTIN},{"debug_assert!", SYNTAX_BUILTIN},{"debug_assert_eq!", SYNTAX_BUILTIN},{"debug_assert_ne!", SYNTAX_BUILTIN},{"drop", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_e[7] = {{"else", SYNTAX_KEYWORD},{"enum", SYNTAX_KEYWORD},{"extern", SYNTAX_KEYWORD},{"env!", SYNTAX_BUILTIN},{"eprint!", SYNTAX_BUILTIN},{"eprintln!", SYNTAX_BUILTIN}}; -static Keyword const syntax_keywords_rust_f[9] = {{"false", SYNTAX_KEYWORD},{"final", SYNTAX_KEYWORD},{"fn", SYNTAX_KEYWORD},{"for", SYNTAX_KEYWORD},{"file!", SYNTAX_BUILTIN},{"format!", SYNTAX_BUILTIN},{"format_args!", SYNTAX_BUILTIN},{"format_args_nl!", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_f[11] = {{"final", SYNTAX_KEYWORD},{"fn", SYNTAX_KEYWORD},{"for", SYNTAX_KEYWORD},{"false", SYNTAX_CONSTANT},{"f32", SYNTAX_BUILTIN},{"f64", SYNTAX_BUILTIN},{"file!", SYNTAX_BUILTIN},{"format!", SYNTAX_BUILTIN},{"format_args!", SYNTAX_BUILTIN},{"format_args_nl!", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_g[2] = {{"global_asm!", SYNTAX_BUILTIN}}; -static Keyword const syntax_keywords_rust_i[14] = {{"if", SYNTAX_KEYWORD},{"impl", SYNTAX_KEYWORD},{"in", SYNTAX_KEYWORD},{"include!", SYNTAX_BUILTIN},{"include_bytes!", SYNTAX_BUILTIN},{"include_str!", SYNTAX_BUILTIN},{"is_aarch64_feature_detected!", SYNTAX_BUILTIN},{"is_arm_feature_detected!", SYNTAX_BUILTIN},{"is_mips64_feature_detected!", SYNTAX_BUILTIN},{"is_mips_feature_detected!", SYNTAX_BUILTIN},{"is_powerpc64_feature_detected!", SYNTAX_BUILTIN},{"is_powerpc_feature_detected!", SYNTAX_BUILTIN},{"is_x86_feature_detected!", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_i[20] = {{"if", SYNTAX_KEYWORD},{"impl", SYNTAX_KEYWORD},{"in", SYNTAX_KEYWORD},{"i128", SYNTAX_BUILTIN},{"i16", SYNTAX_BUILTIN},{"i32", SYNTAX_BUILTIN},{"i64", SYNTAX_BUILTIN},{"i8", SYNTAX_BUILTIN},{"include!", SYNTAX_BUILTIN},{"include_bytes!", SYNTAX_BUILTIN},{"include_str!", SYNTAX_BUILTIN},{"is_aarch64_feature_detected!", SYNTAX_BUILTIN},{"is_arm_feature_detected!", SYNTAX_BUILTIN},{"is_mips64_feature_detected!", SYNTAX_BUILTIN},{"is_mips_feature_detected!", SYNTAX_BUILTIN},{"is_powerpc64_feature_detected!", SYNTAX_BUILTIN},{"is_powerpc_feature_detected!", SYNTAX_BUILTIN},{"is_x86_feature_detected!", SYNTAX_BUILTIN},{"isize", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_l[6] = {{"let", SYNTAX_KEYWORD},{"loop", SYNTAX_KEYWORD},{"line!", SYNTAX_BUILTIN},{"llvm_asm!", SYNTAX_BUILTIN},{"log_syntax!", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_m[8] = {{"macro", SYNTAX_KEYWORD},{"match", SYNTAX_KEYWORD},{"mod", SYNTAX_KEYWORD},{"move", SYNTAX_KEYWORD},{"mut", SYNTAX_KEYWORD},{"matches!", SYNTAX_BUILTIN},{"module_path!", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_o[3] = {{"override", SYNTAX_KEYWORD},{"option_env!", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_p[6] = {{"priv", SYNTAX_KEYWORD},{"pub", SYNTAX_KEYWORD},{"panic!", SYNTAX_BUILTIN},{"print!", SYNTAX_BUILTIN},{"println!", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_r[3] = {{"ref", SYNTAX_KEYWORD},{"return", SYNTAX_KEYWORD}}; -static Keyword const syntax_keywords_rust_s[6] = {{"self", SYNTAX_KEYWORD},{"static", SYNTAX_KEYWORD},{"struct", SYNTAX_KEYWORD},{"super", SYNTAX_KEYWORD},{"stringify!", SYNTAX_BUILTIN}}; -static Keyword const syntax_keywords_rust_t[10] = {{"trait", SYNTAX_KEYWORD},{"true", SYNTAX_KEYWORD},{"try", SYNTAX_KEYWORD},{"type", SYNTAX_KEYWORD},{"typeof", SYNTAX_KEYWORD},{"thread_local!", SYNTAX_BUILTIN},{"todo!", SYNTAX_BUILTIN},{"trace_macros!", SYNTAX_BUILTIN},{"try!", SYNTAX_BUILTIN}}; -static Keyword const syntax_keywords_rust_u[7] = {{"union", SYNTAX_KEYWORD},{"unsafe", SYNTAX_KEYWORD},{"unsized", SYNTAX_KEYWORD},{"use", SYNTAX_KEYWORD},{"unimplemented!", SYNTAX_BUILTIN},{"unreachable!", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_s[7] = {{"self", SYNTAX_KEYWORD},{"static", SYNTAX_KEYWORD},{"struct", SYNTAX_KEYWORD},{"super", SYNTAX_KEYWORD},{"str", SYNTAX_BUILTIN},{"stringify!", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_t[10] = {{"trait", SYNTAX_KEYWORD},{"try", SYNTAX_KEYWORD},{"type", SYNTAX_KEYWORD},{"typeof", SYNTAX_KEYWORD},{"true", SYNTAX_CONSTANT},{"thread_local!", SYNTAX_BUILTIN},{"todo!", SYNTAX_BUILTIN},{"trace_macros!", SYNTAX_BUILTIN},{"try!", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_rust_u[13] = {{"union", SYNTAX_KEYWORD},{"unsafe", SYNTAX_KEYWORD},{"unsized", SYNTAX_KEYWORD},{"use", SYNTAX_KEYWORD},{"u128", SYNTAX_BUILTIN},{"u16", SYNTAX_BUILTIN},{"u32", SYNTAX_BUILTIN},{"u64", SYNTAX_BUILTIN},{"u8", SYNTAX_BUILTIN},{"unimplemented!", SYNTAX_BUILTIN},{"unreachable!", SYNTAX_BUILTIN},{"usize", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_v[3] = {{"virtual", SYNTAX_KEYWORD},{"vec!", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_w[5] = {{"where", SYNTAX_KEYWORD},{"while", SYNTAX_KEYWORD},{"write!", SYNTAX_BUILTIN},{"writeln!", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_rust_y[2] = {{"yield", SYNTAX_KEYWORD}}; static Keyword const *const syntax_all_keywords_rust[] = { - ['S'] = syntax_keywords_rust_S, ['a'] = syntax_keywords_rust_a, ['b'] = syntax_keywords_rust_b, ['c'] = syntax_keywords_rust_c, ['d'] = syntax_keywords_rust_d, ['e'] = syntax_keywords_rust_e, ['f'] = syntax_keywords_rust_f, ['g'] = syntax_keywords_rust_g, ['i'] = syntax_keywords_rust_i, ['l'] = syntax_keywords_rust_l, ['m'] = syntax_keywords_rust_m, ['o'] = syntax_keywords_rust_o, ['p'] = syntax_keywords_rust_p, ['r'] = syntax_keywords_rust_r, ['s'] = syntax_keywords_rust_s, ['t'] = syntax_keywords_rust_t, ['u'] = syntax_keywords_rust_u, ['v'] = syntax_keywords_rust_v, ['w'] = syntax_keywords_rust_w, ['y'] = syntax_keywords_rust_y + ['A'] = syntax_keywords_rust_A, ['B'] = syntax_keywords_rust_B, ['C'] = syntax_keywords_rust_C, ['D'] = syntax_keywords_rust_D, ['E'] = syntax_keywords_rust_E, ['F'] = syntax_keywords_rust_F, ['I'] = syntax_keywords_rust_I, ['N'] = syntax_keywords_rust_N, ['O'] = syntax_keywords_rust_O, ['P'] = syntax_keywords_rust_P, ['R'] = syntax_keywords_rust_R, ['S'] = syntax_keywords_rust_S, ['T'] = syntax_keywords_rust_T, ['U'] = syntax_keywords_rust_U, ['V'] = syntax_keywords_rust_V, ['a'] = syntax_keywords_rust_a, ['b'] = syntax_keywords_rust_b, ['c'] = syntax_keywords_rust_c, ['d'] = syntax_keywords_rust_d, ['e'] = syntax_keywords_rust_e, ['f'] = syntax_keywords_rust_f, ['g'] = syntax_keywords_rust_g, ['i'] = syntax_keywords_rust_i, ['l'] = syntax_keywords_rust_l, ['m'] = syntax_keywords_rust_m, ['o'] = syntax_keywords_rust_o, ['p'] = syntax_keywords_rust_p, ['r'] = syntax_keywords_rust_r, ['s'] = syntax_keywords_rust_s, ['t'] = syntax_keywords_rust_t, ['u'] = syntax_keywords_rust_u, ['v'] = syntax_keywords_rust_v, ['w'] = syntax_keywords_rust_w, ['y'] = syntax_keywords_rust_y }; diff --git a/keywords.py b/keywords.py index c4c4a13..b4645cb 100644 --- a/keywords.py +++ b/keywords.py @@ -157,9 +157,9 @@ def cant_overlap(*args): cant_overlap(keywords_c, keywords_cpp) keywords_rust = [ - 'as', 'break', 'const', 'continue', 'crate', 'else', 'enum', 'extern', 'false', 'fn', 'for', + 'as', 'break', 'const', 'continue', 'crate', 'else', 'enum', 'extern', 'fn', 'for', 'if', 'impl', 'in', 'let', 'loop', 'match', 'mod', 'move', 'mut', 'pub', 'ref', 'return', - 'self', 'Self', 'static', 'struct', 'super', 'trait', 'true', 'type', 'unsafe', 'use', + 'self', 'Self', 'static', 'struct', 'super', 'trait', 'type', 'unsafe', 'use', 'where', 'while', 'async', 'await', 'dyn', 'abstract', 'become', 'box', 'do', 'final', 'macro', 'override', 'priv', 'typeof', 'unsized', 'virtual', 'yield', 'try', 'union', ] @@ -173,8 +173,16 @@ builtins_rust = [ 'is_x86_feature_detected!','line!','matches!','module_path!','option_env!','panic!', 'print!','println!','stringify!','thread_local!','todo!','try!','unimplemented!', 'unreachable!','vec!','write!','writeln!', - # @TODO: i32, u32, Some, str, etc. + 'Copy', 'Send', 'Sized', 'Sync', 'Unpin', 'Drop', 'Fn', 'FnMut', 'FnOnce', + 'drop', 'Box', 'ToOwned', 'Clone', 'PartialEq', 'PartialOrd', 'Eq', 'Ord', + 'AsRef', 'AsMut', 'Into', 'From', 'Default', 'Iterator', 'Extend', 'IntoIterator', + 'DoubleEndedIterator', 'ExactSizeIterator', 'Option', 'Some', 'None', 'Result', 'Ok', + 'Err', 'String', 'ToString', 'Vec', + 'u8', 'u16', 'u32', 'u64', 'u128', 'usize', + 'i8', 'i16', 'i32', 'i64', 'i128', 'isize', + 'f32', 'f64', 'bool', 'char', 'str', ] +constants_rust = ['false', 'true'] file = open('keywords.h', 'w') file.write('''typedef struct { @@ -186,11 +194,12 @@ def label(kwds, l): return [(l, kwd) for kwd in kwds] cant_overlap(keywords_c, constants_c, builtins_c) +cant_overlap(keywords_rust, builtins_rust, constants_rust) c_things = label(keywords_c, SYNTAX_KEYWORD) + label(constants_c, SYNTAX_CONSTANT) + label(builtins_c, SYNTAX_BUILTIN) output_keywords(file, c_things, 'c') cpp_things = c_things + label(keywords_cpp, SYNTAX_KEYWORD) cpp_things.remove((SYNTAX_BUILTIN, 'bool')) cpp_things.remove((SYNTAX_BUILTIN, 'wchar_t')) output_keywords(file, cpp_things, 'cpp') -output_keywords(file, label(keywords_rust, SYNTAX_KEYWORD) + label(builtins_rust, SYNTAX_BUILTIN), 'rust') +output_keywords(file, label(keywords_rust, SYNTAX_KEYWORD) + label(builtins_rust, SYNTAX_BUILTIN) + label(constants_rust, SYNTAX_CONSTANT), 'rust') file.close() -- cgit v1.2.3