diff --git a/syntax/just.vim b/syntax/just.vim
index 10933f5..c110c90 100644
--- a/syntax/just.vim
+++ b/syntax/just.vim
@@ -238,15 +238,19 @@ syn cluster justExprInInterp contains=@justExprBase,justName,justExprParenInInte
syn cluster justExprFunc contains=@justBuiltInFunctions,justReplaceRegex,justExprParen
-syn match justImport /\v^import\ze%(\s|\\\n)+['"]@=/
+syn match justImport /\v^import%(%(\s|\\\n)*\?|%(\s|\\\n)+['"]@=)/ transparent
+ \ contains=justImportStatement,justOptionalFile
+syn match justImportStatement '^import' contained
syn match justOldInclude "^!include\s.*$" contains=justOldIncludeDirective
syn match justOldIncludeDirective "^!include" contained
-syn match justModule /\v^mod%(\s|\\\n)+\h\k*\s*%($|%(\s|\\\n)+['"]@=)/
- \ transparent contains=justModStatement,justName
+syn match justModule /\v^mod%(%(\s|\\\n)*\?)?%(\s|\\\n)+\h\k*\s*%($|%(\s|\\\n)+['"]@=)/
+ \ transparent contains=justModStatement,justName,justOptionalFile
syn match justModStatement '^mod' contained
+syn match justOptionalFile '\V?' contained
+
hi def link justAlias Statement
hi def link justAssignmentOperator Operator
hi def link justBacktick Special
@@ -260,7 +264,7 @@ hi def link justConditional Conditional
hi def link justCurlyBraces Special
hi def link justExport Statement
hi def link justFunction Function
-hi def link justImport Include
+hi def link justImportStatement Include
hi def link justIndentError Error
hi def link justInterpolation Normal
hi def link justInterpolationDelim Delimiter
@@ -271,6 +275,7 @@ hi def link justName Identifier
hi def link justOldInclude PreProc
hi def link justOldIncludeDirective Underlined
hi def link justOperator Operator
+hi def link justOptionalFile Conditional
hi def link justParameterError Error
hi def link justParameterOperator Operator
hi def link justParamExport Statement
diff --git a/tests/cases/import.html b/tests/cases/import.html
index 210c500..c0db306 100644
--- a/tests/cases/import.html
+++ b/tests/cases/import.html
@@ -3,5 +3,5 @@
import\
'line-continuations.just'
-import """
+import ? """
tricky.just"""
diff --git a/tests/cases/import.just b/tests/cases/import.just
index 3ebc3d2..39e633e 100644
--- a/tests/cases/import.just
+++ b/tests/cases/import.just
@@ -3,5 +3,5 @@ import 'recipes-simple.just'
import\
'line-continuations.just'
-import """
+import ? """
tricky.just"""
diff --git a/tests/cases/mod.html b/tests/cases/mod.html
index 0837997..520a800 100644
--- a/tests/cases/mod.html
+++ b/tests/cases/mod.html
@@ -7,3 +7,7 @@
mod _foo-Foo \
'foo/foo.just'
+
+mod? foo
+
+mod ? foo 'foo/justfile'
diff --git a/tests/cases/mod.just b/tests/cases/mod.just
index a9fe0b1..a50cc78 100644
--- a/tests/cases/mod.just
+++ b/tests/cases/mod.just
@@ -7,3 +7,7 @@ mod foo "foo/justfile"
mod _foo-Foo \
'foo/foo.just'
+
+mod? foo
+
+mod ? foo 'foo/justfile'