Skip to content

Commit 695c581

Browse files
omniomiTylerLeonhardt
authored andcommitted
Fix requires to handle single-line (#85)
1 parent e4072e6 commit 695c581

File tree

2 files changed

+26
-133
lines changed

2 files changed

+26
-133
lines changed

PowerShellSyntax.tmLanguage

Lines changed: 22 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,147 +1082,37 @@
10821082
</dict>
10831083
<key>RequiresDirective</key>
10841084
<dict>
1085-
<key>patterns</key>
1086-
<array>
1087-
<dict>
1088-
<key>match</key>
1089-
<string>(?i:(requires))\s(?i:(-Modules))\s(((?:\w+)\,?\s?){1,})$</string>
1090-
<key>captures</key>
1091-
<dict>
1092-
<key>0</key>
1093-
<dict>
1094-
<key>name</key>
1095-
<string>meta.requires.powershell</string>
1096-
</dict>
1097-
<key>1</key>
1098-
<dict>
1099-
<key>name</key>
1100-
<string>keyword.control.requires.powershell</string>
1101-
</dict>
1102-
<key>2</key>
1103-
<dict>
1104-
<key>name</key>
1105-
<string>keyword.other.powershell</string>
1106-
</dict>
1107-
<key>3</key>
1108-
<dict>
1109-
<key>name</key>
1110-
<string>variable.parameter.powershell</string>
1111-
</dict>
1112-
</dict>
1113-
</dict>
1085+
<key>begin</key>
1086+
<string>(?i:(requires))\s</string>
1087+
<key>beginCaptures</key>
1088+
<dict>
1089+
<key>0</key>
11141090
<dict>
1115-
<key>match</key>
1116-
<string>(?i:(requires))\s(?i:(-ShellId))\s(\w+)$</string>
1117-
<key>captures</key>
1118-
<dict>
1119-
<key>0</key>
1120-
<dict>
1121-
<key>name</key>
1122-
<string>meta.requires.powershell</string>
1123-
</dict>
1124-
<key>1</key>
1125-
<dict>
1126-
<key>name</key>
1127-
<string>keyword.control.requires.powershell</string>
1128-
</dict>
1129-
<key>2</key>
1130-
<dict>
1131-
<key>name</key>
1132-
<string>keyword.other.powershell</string>
1133-
</dict>
1134-
<key>3</key>
1135-
<dict>
1136-
<key>name</key>
1137-
<string>variable.parameter.powershell</string>
1138-
</dict>
1139-
</dict>
1091+
<key>name</key>
1092+
<string>keyword.control.requires.powershell</string>
11401093
</dict>
1094+
</dict>
1095+
<key>end</key>
1096+
<string>$</string>
1097+
<key>name</key>
1098+
<string>meta.requires.powershell</string>
1099+
<key>patterns</key>
1100+
<array>
11411101
<dict>
11421102
<key>match</key>
1143-
<string>(?i:(requires))\s(?i:(-RunAsAdministrator))$</string>
1144-
<key>captures</key>
1145-
<dict>
1146-
<key>0</key>
1147-
<dict>
1148-
<key>name</key>
1149-
<string>meta.requires.powershell</string>
1150-
</dict>
1151-
<key>1</key>
1152-
<dict>
1153-
<key>name</key>
1154-
<string>keyword.control.requires.powershell</string>
1155-
</dict>
1156-
<key>2</key>
1157-
<dict>
1158-
<key>name</key>
1159-
<string>keyword.other.powershell</string>
1160-
</dict>
1161-
</dict>
1103+
<string>\-(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version)</string>
1104+
<key>name</key>
1105+
<string>keyword.other.powershell</string>
11621106
</dict>
11631107
<dict>
11641108
<key>match</key>
1165-
<string>(?i:(requires))\s(?i:(-Version))\s((?:\d\.?){1,})$</string>
1166-
<key>captures</key>
1167-
<dict>
1168-
<key>0</key>
1169-
<dict>
1170-
<key>name</key>
1171-
<string>meta.requires.powershell</string>
1172-
</dict>
1173-
<key>1</key>
1174-
<dict>
1175-
<key>name</key>
1176-
<string>keyword.control.requires.powershell</string>
1177-
</dict>
1178-
<key>2</key>
1179-
<dict>
1180-
<key>name</key>
1181-
<string>keyword.other.powershell</string>
1182-
</dict>
1183-
<key>3</key>
1184-
<dict>
1185-
<key>name</key>
1186-
<string>variable.parameter.powershell</string>
1187-
</dict>
1188-
</dict>
1109+
<string>(?<!-)\b\p{L}+|\d+(?:\.\d+)*</string>
1110+
<key>name</key>
1111+
<string>variable.parameter.powershell</string>
11891112
</dict>
11901113
<dict>
1191-
<key>match</key>
1192-
<string>(?i:(requires))(?:\s(-PSSnapin)\s(\w+))(?:\s(?i:(-Version))\s((?:\d\.?){1,}))?$</string>
1193-
<key>captures</key>
1194-
<dict>
1195-
<key>0</key>
1196-
<dict>
1197-
<key>name</key>
1198-
<string>meta.requires.powershell</string>
1199-
</dict>
1200-
<key>1</key>
1201-
<dict>
1202-
<key>name</key>
1203-
<string>keyword.control.requires.powershell</string>
1204-
</dict>
1205-
<key>2</key>
1206-
<dict>
1207-
<key>name</key>
1208-
<string>keyword.other.powershell</string>
1209-
</dict>
1210-
<key>3</key>
1211-
<dict>
1212-
<key>name</key>
1213-
<string>variable.parameter.powershell</string>
1214-
</dict>
1215-
<key>4</key>
1216-
<dict>
1217-
<key>name</key>
1218-
<string>keyword.other.powershell</string>
1219-
</dict>
1220-
<key>5</key>
1221-
<dict>
1222-
<key>name</key>
1223-
<string>variable.parameter.powershell</string>
1224-
</dict>
1225-
</dict>
1114+
<key>include</key>
1115+
<string>#hashtable</string>
12261116
</dict>
12271117
</array>
12281118
</dict>

examples/TheBigTestFile.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ using namespace System.Management.Automation
33
#Requires -PSSnapin DiskSnapin
44
#Requires -Version 3
55
#Requires -Version 3.0
6+
#Requires -Version 3 -RunAsAdministrator
67
#Requires -RunAsAdministrator
78
#Requires -Modules PSWorkflow
9+
#Requires -Modules PSWorkflow -ThisIsInvalid
810
#Requires -Modules PSWorkflow, ActiveDirectory
11+
#Requires -Modules PSWorkflow,ActiveDirectory
912
#Requires -ShellId MyLocalShell
10-
#Requires -Modules @{
13+
#Requires -Modules PSWorkflow @{
1114
ModuleName="PSScheduledJob"
1215
ModuleVersion="1.0.0.0"
1316
}

0 commit comments

Comments
 (0)