Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions grammars/tree-sitter-ssh-server-config/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = grammar({
repeat1(choice($.comment, $.keyword)),
),

arguments: $ => repeat1(choice($.boolean, $.number, $._quotedString, $._commaSeparatedString)),
arguments: $ => repeat1(choice($.boolean, $.number, $.quotedString, $._commaSeparatedString)),

alphanumeric: $ => /[a-zA-Z0-9]+/i,
boolean: $ => choice('yes', 'no'),
Expand All @@ -43,7 +43,7 @@ module.exports = grammar({
string: $ => /[^\r\n,"]+/,

_commaSeparatedString: $ => seq($.string, repeat(seq(',', $.string))),
_quotedString: $ => seq('\"', $.string, '\"'),
quotedString: $ => seq('\"', $.string, '\"'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the parser, you don't care if it's quoted or not, but simply the result is the contents between the quotes (if provided), right? Can't you define a string as a choice between quoted and not quoted where the quoted is just the contents between the quotes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full scenario the Rust parser is running into:

The existing parser has a test for:
allowgroups group1 "group with spaces"

However, the existing parser would parse this scenario:
allowgroups group1 group2

as a single string, "group1 group2" instead of "group1" and "group2"

To support both, I plan to update the Rust parser to be able to split "string" nodes by spaces but not "quoted string nodes"

It may be easier to consolidate the grammar and parser changes because this has broken the parser anyway

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another option would probably be to update the grammar to not declare space in extras but that may have broader impact

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think space in extras is fine to allow arbitrary whitespace, but the Rust parsing code should just handle the tokens returned by the grammar and not have to worry about the enclosing quotes and just the contents which can contain whitespace. I think this should be possible by defining as (pseudo-grammar):

[keyword] [parameter]+

where [parameter] is choice([string], [number], [yes/no], etc...) and [string] is either a bareString or quotedString, but the parser just gets it as a string.

}

});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ authorizedKEYSfile "path to authorized keys file"
(keyword
(alphanumeric)
(arguments
(string))))
(quotedString
(string)))))
=====
comment
=====
Expand All @@ -36,7 +37,8 @@ authorizedkeysfile "path to authorized keys file"
(keyword
(alphanumeric)
(arguments
(string)))))
(quotedString
(string))))))
=====
boolean and match
=====
Expand All @@ -59,7 +61,8 @@ authorizedkeysfile "path to authorized keys file"
(keyword
(alphanumeric)
(arguments
(string)))))
(quotedString
(string))))))
=====
directive with = operator
=====
Expand Down Expand Up @@ -108,7 +111,8 @@ AllowGroups group1 "group two"
(alphanumeric)
(arguments
(string)
(string))))
(quotedString
(string)))))
=====
directive with comma-separated arguments
=====
Expand Down Expand Up @@ -316,7 +320,8 @@ passwordauthentication yes
(alphanumeric)
(arguments
(string)
(string))))
(quotedString
(string)))))
(match
(keyword
(alphanumeric)
Expand Down Expand Up @@ -367,4 +372,5 @@ allowgroups administrators "openssh users"
(alphanumeric)
(arguments
(string)
(string))))
(quotedString
(string)))))
Loading