diff --git a/CHANGES.md b/CHANGES.md index 10c325aa64..b0efb3f85a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,11 +7,13 @@ Grammars: - fix(angelscript) incomplete int8, int16, int32, int64 highlighting [Melissa Geels][] - enh(ts) modify TypeScript-specific keywords and types list [anydonym][] - fix(brainfuck) fix highlighting of initial ++/-- [Christina Hanson][] +- fix(llvm) escaping in strings and number formats [Flakebi][] [Wojciech Kania]: https://github.com/wkania [Melissa Geels]: https://github.com/codecat [anydonym]: https://github.com/anydonym [Christina Hanson]: https://github.com/LyricLy +[Flakebi]: https://github.com/Flakebi ## Version 11.4.0 diff --git a/src/languages/llvm.js b/src/languages/llvm.js index 415b28f4e0..8358792eb0 100644 --- a/src/languages/llvm.js +++ b/src/languages/llvm.js @@ -28,8 +28,8 @@ export default function(hljs) { const NUMBER = { className: 'number', variants: [ - { begin: /0[xX][a-fA-F0-9]+/ }, - { begin: /-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/ } + { begin: /[su]?0[xX][KMLHR]?[a-fA-F0-9]+/ }, + { begin: /[-+]?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/ } ], relevance: 0 }; @@ -109,12 +109,15 @@ export default function(hljs) { // another language than an actual comment hljs.COMMENT(/;\s*$/, null, { relevance: 0 }), hljs.COMMENT(/;/, /$/), - hljs.QUOTE_STRING_MODE, { className: 'string', - variants: [ - // Double-quoted string - { begin: /"/, end: /[^\\]"/ }, + begin: /"/, + end: /"/, + contains: [ + { + className: 'char.escape', + match: /\\\d\d/ + } ] }, FUNCTION, diff --git a/test/markup/llvm/default.expect.txt b/test/markup/llvm/default.expect.txt index 8d09a4bc77..48662995cf 100644 --- a/test/markup/llvm/default.expect.txt +++ b/test/markup/llvm/default.expect.txt @@ -6,10 +6,10 @@ %struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 } %struct.what = type { i8, i16 } -@.str = private unnamed_addr constant [6 x i8] c"foo()\00", align 1 +@.str = private unnamed_addr constant [6 x i8] c"foo()\00", align 1 @e_long = common global i64 0, align 8 @g_double = common global double 0.000000e+00, align 8 -@.str.1 = private unnamed_addr constant [7 x i8] c"oooooh\00", align 1 +@.str.1 = private unnamed_addr constant [7 x i8] c"oooooh\00", align 1 @func_ptr = common global i32 (...)* null, align 8 @stderr = external global %struct._IO_FILE*, align 8 diff --git a/test/markup/llvm/numbers.expect.txt b/test/markup/llvm/numbers.expect.txt new file mode 100644 index 0000000000..bd41bc80d0 --- /dev/null +++ b/test/markup/llvm/numbers.expect.txt @@ -0,0 +1,11 @@ +define i32 @signed_int() { + ret i32 s0x12a +} + +define float @signed_float() { + ret float +1.0 +} + +define float @float_format() { + ret float 0xK12a +} diff --git a/test/markup/llvm/numbers.txt b/test/markup/llvm/numbers.txt new file mode 100644 index 0000000000..a347c96731 --- /dev/null +++ b/test/markup/llvm/numbers.txt @@ -0,0 +1,11 @@ +define i32 @signed_int() { + ret i32 s0x12a +} + +define float @signed_float() { + ret float +1.0 +} + +define float @float_format() { + ret float 0xK12a +} diff --git a/test/markup/llvm/string.expect.txt b/test/markup/llvm/string.expect.txt new file mode 100644 index 0000000000..6492317555 --- /dev/null +++ b/test/markup/llvm/string.expect.txt @@ -0,0 +1,8 @@ +; Backslashes do not escape quotes, this is a legal string +define void @"C:\"() { + ret void +} + +define void @"escape_code_\0123\04end"() { + ret void +} diff --git a/test/markup/llvm/string.txt b/test/markup/llvm/string.txt new file mode 100644 index 0000000000..1af23f7066 --- /dev/null +++ b/test/markup/llvm/string.txt @@ -0,0 +1,8 @@ +; Backslashes do not escape quotes, this is a legal string +define void @"C:\"() { + ret void +} + +define void @"escape_code_\0123\04end"() { + ret void +}