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 11WHITESPACE = _{ " " | "\t" | "\x0B" | "\x0C" | "\r" | "\n" }
22
3+ COMMENT = _{ LineComment | BlockComment }
4+
5+ BlockComment = { "/*" ~ ( BlockComment | (!"*/" ~ ANY) )* ~ "*/" }
6+ LineComment = { "--" ~ ( !"\n" ~ ANY )* ~ "\n" }
7+
38// TODO implement a full grammar, this is a very primitive version to start
49// working with Pest and its APIs.
510
Original file line number Diff line number Diff line change @@ -399,6 +399,63 @@ mod test {
399399 } ;
400400 }
401401
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+ ) ]
402459 #[ rstest]
403460 #[ case:: single_keyword(
404461 scanner_test_case![
@@ -532,6 +589,11 @@ mod test {
532589
533590 #[ rstest]
534591 #[ 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]*/*/*/*/*/*/*/ " ) ]
535597 fn bad_tokens ( #[ case] input : & str ) -> ParserResult < ( ) > {
536598 let expecteds = vec ! [ syntax_error( "IGNORED MESSAGE" , Position :: at( 1 , 1 ) ) ] ;
537599 assert_input ( input, expecteds)
You can’t perform that action at this time.
0 commit comments