File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1
1
WHITESPACE = _{ " " | "\t" | "\x0B" | "\x0C" | "\r" | "\n" }
2
2
3
+ COMMENT = _{ LineComment | BlockComment }
4
+
5
+ BlockComment = { "/*" ~ ( BlockComment | (!"*/" ~ ANY) )* ~ "*/" }
6
+ LineComment = { "--" ~ ( !"\n" ~ ANY )* ~ "\n" }
7
+
3
8
// TODO implement a full grammar, this is a very primitive version to start
4
9
// working with Pest and its APIs.
5
10
Original file line number Diff line number Diff line change @@ -399,6 +399,63 @@ mod test {
399
399
} ;
400
400
}
401
401
402
+ #[ rstest]
403
+ #[ case:: comment_single_keyword(
404
+ scanner_test_case![
405
+ "--" ,
406
+ "SELECT" ,
407
+ " \n " ,
408
+ ]
409
+ ) ]
410
+ #[ rstest]
411
+ #[ case:: comment_mid_line(
412
+ scanner_test_case![
413
+ "SELECT" => keyword( "SELECT" ) ,
414
+ " " ,
415
+ "FROM" => keyword( "FROM" ) ,
416
+ " -- " ,
417
+ "WHERE" ,
418
+ " \n " ,
419
+ ]
420
+ ) ]
421
+ #[ rstest]
422
+ #[ case:: comment_until_eol(
423
+ scanner_test_case![
424
+ " -- " ,
425
+ "CASE" ,
426
+ " " ,
427
+ "IN" ,
428
+ " " ,
429
+ "WHERE" ,
430
+ " \n " ,
431
+ "SELECT" => keyword( "SELECT" ) ,
432
+ ]
433
+ ) ]
434
+ #[ rstest]
435
+ #[ case:: comment_block(
436
+ scanner_test_case![
437
+ " /* " ,
438
+ "CASE" ,
439
+ " " ,
440
+ "IN" ,
441
+ " */ " ,
442
+ "SELECT" => keyword( "SELECT" ) ,
443
+ ]
444
+ ) ]
445
+ #[ rstest]
446
+ #[ case:: comment_block_nested(
447
+ scanner_test_case![
448
+ "employee" => identifier( "employee" ) ,
449
+ " /*\n " ,
450
+ "CASE" ,
451
+ " /* " ,
452
+ "WHERE" ,
453
+ " \n */ " ,
454
+ "employee" ,
455
+ " \n \n */ " ,
456
+ "IN" => keyword( "IN" ) ,
457
+ ]
458
+ ) ]
402
459
#[ rstest]
403
460
#[ case:: single_keyword(
404
461
scanner_test_case![
@@ -532,6 +589,11 @@ mod test {
532
589
533
590
#[ rstest]
534
591
#[ case:: bad_identifier( "💩" ) ]
592
+ #[ case:: unterminated_line_comment( "-- DROP" ) ]
593
+ #[ case:: unbalanced_block_comment( "/*\n \n SELECT /* WHERE */" ) ]
594
+ #[ case:: unbalanced_block_comment( "/* CASE do WHEN re THEN mi ELSE fa END /*" ) ]
595
+ #[ case:: unbalanced_block_comment( "/*SELECT /* FROM /* FULL OUTER JOIN */ */ " ) ]
596
+ #[ case:: unbalanced_block_comment( "/*/*/*/*/*/*/*/*[ascii art here]*/*/*/*/*/*/*/ " ) ]
535
597
fn bad_tokens ( #[ case] input : & str ) -> ParserResult < ( ) > {
536
598
let expecteds = vec ! [ syntax_error( "IGNORED MESSAGE" , Position :: at( 1 , 1 ) ) ] ;
537
599
assert_input ( input, expecteds)
You can’t perform that action at this time.
0 commit comments