Skip to content

Commit

Permalink
feat: @enter and @escape syntax for modes in commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lavafroth committed Jul 4, 2024
1 parent 829e100 commit f8d0b7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Here's what has been worked on so far.
- [x] Modes
- [x] Oneoff
- [x] Swallow
- [ ] `@mode` in commands
- [ ] `@mode` in commands (Grammar implemented)
- [x] Comments
- [x] Imports
- [x] Merge definitions from all imports
Expand Down
12 changes: 9 additions & 3 deletions template.pest
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,17 @@ command_component_and = _{ WHITESPACE* ~ "," ~ WHITESPACE* ~ (range | command_co
inside_braces = _{ (command_component ~ command_component_and+) | (range ~ command_component_and*) }
command_shorthand = { "{" ~ inside_braces ~ "}" }

command_double_ampersand = { " && " }

// make sure that a standalone part of a command does not overlap with
// parts inside braces
command_standalone = { (!shorthand_bounds ~ not_newline)+ }

command_line = _{ (command_shorthand | command_standalone)* }
command_standalone = { (!shorthand_bounds ~ !command_double_ampersand ~ not_newline)+ }
command_chunk = _{command_shorthand | command_standalone}
enter_mode = { "@enter" ~ WHITESPACE ~ modename ~ WHITESPACE }
escape_mode = { "@escape" ~ WHITESPACE }
command_chunk_maybe_with_mode = _{(enter_mode | escape_mode)? ~ command_chunk*}
command_line = _{ command_chunk_maybe_with_mode ~ (command_double_ampersand ~ command_chunk_maybe_with_mode)* }

// We use a WHITESPACE+ in the trailing matcher to automatically trim whitespaces (and tabs) from
// multiline commands. ---------------------------------------------v
Expand Down Expand Up @@ -203,7 +209,7 @@ import = { "include" ~ import_file }

oneoff = { "oneoff" }
swallow = { "swallow" }
modename_characters = _{ !NEWLINE ~ !(oneoff | swallow) ~ ANY }
modename_characters = _{ !NEWLINE ~ !(oneoff | swallow | command_double_ampersand) ~ !WHITESPACE ~ ANY }
modename = { modename_characters+ }
primitives = _{ comment | unbind | binding }

Expand Down

0 comments on commit f8d0b7b

Please sign in to comment.