Skip to content

grammar freezes #134

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

Closed
aeschli opened this issue Aug 15, 2018 · 7 comments
Closed

grammar freezes #134

aeschli opened this issue Aug 15, 2018 · 7 comments
Assignees
Labels

Comments

@aeschli
Copy link

aeschli commented Aug 15, 2018

Opening this file freezes with the latest grammar.

I reverted the VSCode grammar to 6f54386

@aeschli aeschli changed the title grammar fresses grammar freezes Aug 15, 2018
@Serega124
Copy link

Serega124 commented Aug 15, 2018

This line has catastrophic backtracking:

<string>^(?i:(?:\s*|#)+(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS))</string>

Changing the * to ? symbol seems to work.

via microsoft/vscode#56476

@omniomi omniomi added the bug label Aug 15, 2018
@omniomi omniomi self-assigned this Aug 15, 2018
@omniomi
Copy link
Contributor

omniomi commented Aug 15, 2018

The difference between the two versions was (?i:\s*(\.) - > ^(?i:(?:\s*|#)+(\.) reason being if you forgot a space after a sentence and had a keyword it would highlight (#119). The * has been there all along but coupled with the + that's what's doing it in. Whether you change it to ^(?i:(?:\s?|#)+(\.) or ^(?i:(?:\s*|#)(\.) the crash stops.

I will push that ASAP.

omniomi added a commit to omniomi/EditorSyntax that referenced this issue Aug 15, 2018
@msftrncs
Copy link
Contributor

I see another minor problem. It appears that PowerShell Get-Help requires these documentation keywords to be the only word on the line (spaces are accepted at the end of the line, but not even '#'). (not sure if its true for all of them, PARAMETER which does accept additional text is in a different pattern) Also, I am not getting any scoping of these documentation keywords if they are on a single line comment, but PowerShell Get-Help seems to accept that. It even seems to accept <# #> # .SYNOPSIS but any other non space characters are not accepted.

Seems that it might be that the same pattern (repository?) is used for both comment types, but the match here requires being at the beginning of the line, and I am not sure if that reference is valid inside the 'include' of another pattern? I tried it, modifying my tmLanguage.json file on VS Code, copying the commentEmbeddedDocs pattern to slCommentEmbeddedDocs and removed the ^ from the match, and changed the include reference on commentLine and that seems to get the single line comment's to work (scope and color for the documentation keyword). I'm not sure how the rest of the rules can be adhered to.

trial and error seems to indicate get-help only supports spaces at the start of multi-line comments, and only accepts consecutive '#'s immediately after the start of a single line comment. I finally determined that \G would fix that.

		"commentEmbeddedDocs": {
			"patterns": [
				{
					"captures": {
						"1": {
							"name": "constant.string.documentation.powershell"
						},
						"2": {
							"name": "keyword.operator.documentation.powershell"
						}
					},
					"match": "^(?i:\\s*(\\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS))",
					"name": "comment.documentation.embedded.powershell"
				},
				{
					"captures": {
						"1": {
							"name": "constant.string.documentation.powershell"
						},
						"2": {
							"name": "keyword.operator.documentation.powershell"
						},
						"3": {
							"name": "keyword.operator.documentation.powershell"
						}
					},
					"match": "^(?i:\\s*(\\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\\s+([a-z0-9-_]+))",
					"name": "comment.documentation.embedded.powershell"
				}
			]
		},
		"slCommentEmbeddedDocs": {
			"patterns": [
				{
					"captures": {
						"1": {
							"name": "constant.string.documentation.powershell"
						},
						"2": {
							"name": "keyword.operator.documentation.powershell"
						}
					},
					"match": "\\G(?i:#*\\s*(\\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS))",
					"name": "comment.documentation.embedded.powershell"
				},
				{
					"captures": {
						"1": {
							"name": "constant.string.documentation.powershell"
						},
						"2": {
							"name": "keyword.operator.documentation.powershell"
						},
						"3": {
							"name": "keyword.operator.documentation.powershell"
						}
					},
					"match": "\\G(?i:#*\\s*(\\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\\s+([a-z0-9-_]+))",
					"name": "comment.documentation.embedded.powershell"
				}
			]
		}

(JSON from VS Code)

@msftrncs
Copy link
Contributor

Quick correction: The ^ should be changed to (?:^|\\G), as get-help allows the keyword on the same line as the start of the multiline comment, but with nothing other than spaces between.

@msftrncs
Copy link
Contributor

msftrncs commented Aug 16, 2018

and a final correction, I completely missed the first point I brought up, get-help doesn't allow anything trailing on the keyword lines that do not pass an argument for the help keyword.

Add (?:\\s*$) to the end of the matches with only two captures.

Edited to add '*' after '\s'

@Jaykul
Copy link

Jaykul commented Aug 16, 2018

@msftrncs probably should open a separate issue to track that.

@msftrncs
Copy link
Contributor

I was able to come up with a better solution that doesn't require an additional repository item, I'll include this all in a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants