From fb9aae2c317302356fa9f7482fa8e364f1529abe Mon Sep 17 00:00:00 2001 From: Tan Le Date: Mon, 8 Jan 2024 09:08:36 +1100 Subject: [PATCH] Support primitive directives in NASM lexer (#1974) --- lib/rouge/lexers/nasm.rb | 9 +++++---- spec/visual/samples/nasm | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/rouge/lexers/nasm.rb b/lib/rouge/lexers/nasm.rb index cbf491ec9b..2e2df7f0bc 100644 --- a/lib/rouge/lexers/nasm.rb +++ b/lib/rouge/lexers/nasm.rb @@ -14,11 +14,12 @@ class Nasm < RegexLexer mimetypes 'text/x-nasm' state :root do - rule %r/^\s*%/, Comment::Preproc, :preproc + rule %r/^\s*%/, Comment::Preproc, :preproc - mixin :whitespace + mixin :whitespace + mixin :punctuation - rule %r/[a-z$._?][\w$.?#@~]*:/i, Name::Label + rule %r/[a-z$._?][\w$.?#@~]*:/i, Name::Label rule %r/([a-z$._?][\w$.?#@~]*)(\s+)(equ)/i do groups Name::Constant, Keyword::Declaration, Keyword::Declaration @@ -32,7 +33,7 @@ class Nasm < RegexLexer end state :instruction_args do - rule %r/"(\\\\"|[^"\\n])*"|'(\\\\'|[^'\\n])*'|`(\\\\`|[^`\\n])*`/, Str + rule %r/"(\\\\"|[^"\\n])*"|'(\\\\'|[^'\\n])*'|`(\\\\`|[^`\\n])*`/, Str rule %r/(?:0x[\da-f]+|$0[\da-f]*|\d+[\da-f]*h)/i, Num::Hex rule %r/[0-7]+q/i, Num::Oct rule %r/[01]+b/i, Num::Bin diff --git a/spec/visual/samples/nasm b/spec/visual/samples/nasm index 4d8e760082..7e95ea333d 100644 --- a/spec/visual/samples/nasm +++ b/spec/visual/samples/nasm @@ -1,3 +1,7 @@ +[global Start] +[BITS 16] +[ORG 0x7C00] + ; Simple test of the NASM parser ; Data section, initialized variables