Skip to content

Commit bf615e1

Browse files
committed
update grammar to not error on blank line
1 parent 0ef8730 commit bf615e1

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

sshdconfig/src/parser.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl SshdConfigParser {
5656
}
5757
match node.kind() {
5858
"keyword" => self.parse_keyword_node(node, input, input_bytes),
59-
"comment" => Ok(()),
59+
"comment" | "empty_line" => Ok(()),
6060
_ => Err(SshdConfigError::ParserError(format!("unknown node type: {}", node.kind()))),
6161
}
6262
}
@@ -234,4 +234,13 @@ mod tests {
234234
let result = parse_text_to_map(input);
235235
assert!(result.is_err());
236236
}
237+
238+
#[test]
239+
fn err() {
240+
let code = r#"
241+
"#;
242+
let result = parse_text_to_map(code);
243+
println!("{result:?}");
244+
assert!(result.is_ok());
245+
}
237246
}

tree-sitter-ssh-server-config/grammar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ module.exports = grammar({
1414
extras: $ => [' ', '\t', '\r'],
1515

1616
rules: {
17-
server_config: $ => seq(repeat(choice($.comment, $.keyword)), repeat($.match)),
17+
server_config: $ => seq(repeat(choice($.empty_line, $.comment, $.keyword)), repeat($.match)),
1818

19+
// check for an empty line that is just a /n character
20+
empty_line: $ => seq('\n'),
1921
comment: $ => /#.*\n/,
2022

2123
keyword: $ => seq(

tree-sitter-ssh-server-config/test/corpus/invalid_expressions.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ AuthorizedKeysFile"ARG"
88
(server_config
99
(ERROR
1010
(alphanumeric)
11-
(UNEXPECTED 'A')))
11+
(UNEXPECTED 'A'))
12+
(empty_line))
1213
=====
1314
missing argument after keyword
1415
=====
@@ -18,4 +19,5 @@ AuthorizedKeysFile
1819

1920
(server_config
2021
(ERROR
21-
(alphanumeric)))
22+
(alphanumeric))
23+
(empty_line))

tree-sitter-ssh-server-config/test/corpus/valid_expressions.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,11 @@ port 1234
348348
(alphanumeric)
349349
(arguments
350350
(number))))
351+
====
352+
parse empty line
353+
====
354+
355+
356+
---
357+
(server_config
358+
(empty_line))

0 commit comments

Comments
 (0)