dakyskye / dxhd

daky's X11 Hotkey Daemon
MIT License
99 stars 6 forks source link

Parser Proposal #49

Open NotUnlikeTheWaves opened 3 years ago

NotUnlikeTheWaves commented 3 years ago

This issue is currently mostly focused on parsing the bindings, not the actions. I'll update this soon

I currently propose the parser for dxhd to consist of 4 parts:

  1. Tokenizer. This turns an input strings (e.g. shift + d + {b,c}) into a list of tokens like [Text("shift"), Plus, Text("d"), Plus, OptionStart, Text("b"), Comma, Text("c"), OptionEnd] that can be more easily read and understood. This can also remove whitespaces and possibly detect (but not handle) escape characters for control elements. (Is this necessary? might mess with the substitution logic for the action on a binding)
  2. A lexer. This takes the tokens and creates syntax elements from them based on the information around them. For example, {0-9} would become a Range(0, 9) and an option list {a,b} would become Option(["a", "b"])
  3. A desugarer for syntactic sugar elements. A range of for example {1-4} is no different than an option list of {1,2,3,4} and should be parsed as such.
  4. A parser that will understand the remaining syntax elements

All parts except the tokenizer can throw an error. The tokenizer can't throw an error because it only transforms input into tokens that are representations of the input.

dakyskye commented 3 years ago

Sounds good to me :+1: