Skip to content

Allow nls before pipe operator #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object PSLanguageHostUtils {
private suspend fun readPowerShellVersion(exePath: String): PSVersionInfo {
var process: Process? = null
val commandString = "(\$PSVersionTable.PSVersion, \$PSVersionTable.PSEdition) -join ' '"
val commandLine = GeneralCommandLine(exePath, "-Command", commandString)
val commandLine = GeneralCommandLine(exePath, "–NoProfile", "-Command", commandString)
return coroutineScope {
try {
process = commandLine.createProcess()
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/PowerShell.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ cast_expression ::= type_literal_expression unary_expression

//private attributed_expression ::= type_literal variable

left pipeline_tail ::= ( PIPE nls? command_call_expression )+
left pipeline_tail ::= ( nls? PIPE nls? command_call_expression )+
{elementType=pipeline}

command_call_expression ::= command_invocation_operator ( (command_module command_name_expr command_element* ) | command_name_expr command_element* ) | command_name_expression command_element*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ class PowerShellParserTest : ParsingTestCase("parser", "ps1", PowerShellParserDe
fun testEnumDeclaration() { doTest(true) }
fun testParamBlock() { doTest(true) }
fun testComment() { doTest(true) }
fun testNewLineThenPipeOperator() { doTest(true) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1, 2, 3
| Foreach-Object { $_ }

1, 2, 3

| Foreach-Object { $_ }
64 changes: 64 additions & 0 deletions src/test/resources/testData/parser/NewLineThenPipeOperator.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FILE(0,65)
PowerShellPipelineTailImplGen(PIPELINE)(0,31)
PowerShellArrayLiteralExpressionImplGen(ARRAY_LITERAL_EXPRESSION)(0,7)
PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(0,1)
PsiElement(DEC_INTEGER)('1')(0,1)
PsiElement(,)(',')(1,2)
PsiWhiteSpace(' ')(2,3)
PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(3,4)
PsiElement(DEC_INTEGER)('2')(3,4)
PsiElement(,)(',')(4,5)
PsiWhiteSpace(' ')(5,6)
PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(6,7)
PsiElement(DEC_INTEGER)('3')(6,7)
PsiElement(NLS)('\n')(7,8)
PsiElement(|)('|')(8,9)
PsiWhiteSpace(' ')(9,10)
PowerShellCommandCallExpressionImplGen(COMMAND_CALL_EXPRESSION)(10,31)
PowerShellCommandNameImplGen(COMMAND_NAME)(10,24)
PowerShellIdentifierImplGen(IDENTIFIER)(10,24)
PsiElement(GENERIC_ID_PART)('Foreach-Object')(10,24)
PsiWhiteSpace(' ')(24,25)
PowerShellCommandArgumentImplGen(COMMAND_ARGUMENT)(25,31)
PowerShellScriptBlockExpressionImplGen(SCRIPT_BLOCK_EXPRESSION)(25,31)
PsiElement({)('{')(25,26)
PsiWhiteSpace(' ')(26,27)
PowerShellBlockBodyImplGen(BLOCK_BODY)(27,29)
PowerShellTargetVariableExpressionImplGen(TARGET_VARIABLE_EXPRESSION)(27,29)
PsiElement($)('$')(27,28)
PowerShellIdentifierImplGen(IDENTIFIER)(28,29)
PsiElement(SIMPLE_ID)('_')(28,29)
PsiWhiteSpace(' ')(29,30)
PsiElement(})('}')(30,31)
PsiElement(NLS)('\n\n')(31,33)
PowerShellPipelineTailImplGen(PIPELINE)(33,65)
PowerShellArrayLiteralExpressionImplGen(ARRAY_LITERAL_EXPRESSION)(33,40)
PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(33,34)
PsiElement(DEC_INTEGER)('1')(33,34)
PsiElement(,)(',')(34,35)
PsiWhiteSpace(' ')(35,36)
PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(36,37)
PsiElement(DEC_INTEGER)('2')(36,37)
PsiElement(,)(',')(37,38)
PsiWhiteSpace(' ')(38,39)
PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(39,40)
PsiElement(DEC_INTEGER)('3')(39,40)
PsiElement(NLS)('\n\n')(40,42)
PsiElement(|)('|')(42,43)
PsiWhiteSpace(' ')(43,44)
PowerShellCommandCallExpressionImplGen(COMMAND_CALL_EXPRESSION)(44,65)
PowerShellCommandNameImplGen(COMMAND_NAME)(44,58)
PowerShellIdentifierImplGen(IDENTIFIER)(44,58)
PsiElement(GENERIC_ID_PART)('Foreach-Object')(44,58)
PsiWhiteSpace(' ')(58,59)
PowerShellCommandArgumentImplGen(COMMAND_ARGUMENT)(59,65)
PowerShellScriptBlockExpressionImplGen(SCRIPT_BLOCK_EXPRESSION)(59,65)
PsiElement({)('{')(59,60)
PsiWhiteSpace(' ')(60,61)
PowerShellBlockBodyImplGen(BLOCK_BODY)(61,63)
PowerShellTargetVariableExpressionImplGen(TARGET_VARIABLE_EXPRESSION)(61,63)
PsiElement($)('$')(61,62)
PowerShellIdentifierImplGen(IDENTIFIER)(62,63)
PsiElement(SIMPLE_ID)('_')(62,63)
PsiWhiteSpace(' ')(63,64)
PsiElement(})('}')(64,65)