Skip to content

Commit

Permalink
Add multiline comments to PEG format
Browse files Browse the repository at this point in the history
- Add multiline comment to PEG's format grammar, at COMMENT pattern's definition
- Add test for single line comments
- Add test for multiline one-line comments
- Add test for multiline n-line comments
- Add test for nested:
--: Single line in multiline
--: (Multiline in) multiline
--: Invalid grammar pattern definition inside multiline
  • Loading branch information
felix91gr committed Nov 6, 2018
1 parent dba2949 commit b2a5021
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions derive/tests/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,23 @@ SYMBOL = { "shadows builtin" }

WHITESPACE = _{ " " }
COMMENT = _{ "$"+ }

// Line comment

/* 1-line multiline comment */

/*
N-line multiline comment
*/

/*
// Line comment inside multiline

/*
(Multiline inside) multiline
*/

Invalid segment of grammar below (repeated rule)

WHITESPACE = _{ "hi" }
*/
3 changes: 2 additions & 1 deletion meta/src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ range_operator = { ".." }

newline = _{ "\n" | "\r\n" }
WHITESPACE = _{ " " | "\t" | newline }
COMMENT = _{ "//" ~ (!newline ~ ANY)* }
block_comment = _{ "/*" ~ (block_comment | !"*/" ~ ANY)* ~ "*/" }
COMMENT = _{ block_comment | ("//" ~ (!newline ~ ANY)*) }

0 comments on commit b2a5021

Please sign in to comment.