Commit Graph

7 Commits

Author SHA1 Message Date
Aodhnait Étaín 3062ac9f45 Add unary operator parsing
Now we can also parse unary +, i.e.
  +17,
and also expressions that contain it, i.e.
  +17 + 23.

We also now have custom Debug implementation for Expression, which
prints them in more useful, s-expression-like syntax, i.e.
  +17 + 23 => (+ +17 23).

We also change implementation of `TokenStream`s `next` and `parse_next`
methods to allow to easily implement `peek` method for looking at the
(possible) next token without advancing the stream.
2021-05-23 08:06:53 +01:00
Aodhnait Étaín 9539389e4f Fix segmentation fault
This segfault occurs in the future commits, but because it's more
important, I'm commiting it first.
2021-05-23 08:06:53 +01:00
Aodhnait Étaín fa2dcddd47 Rename CallWithContinuation trait to Then
New name is shorter and better reflects the intent of the trait.
2021-05-23 08:06:53 +01:00
Aodhnait Étaín 3d26398ac7 Add pretty-printing of the parsed expression
Adds `--unpretty` unstable flag, which currently accepts two arguments,
`dot` and `graphdotviz`, which are synonymous, and which prints the
expression we parsed in a graphdotviz-compatible format, i.e. in a form
of a directed graph.
2021-05-22 22:07:49 +01:00
Aodhnait Étaín ba409b9be0 Add simple expression parsing
Currently can only parse addition in a right-associative way, i.e.
  1 + 2 + 3 => 1 + (2 + 3).

The reason why are we using raw pointers in a form of OffsetStr struct
is because I don't think there is a way to prove to Rust compiler that
tokens the parse_next function returns are always valid references to
the TokenStream source string. Therefore we simply have to bypass the
borrow checker and handle this ourselves.
2021-05-22 21:45:42 +01:00
Aodhnait Étaín 4841f7b657 Add parsing of command-line arguments
Currently only supports `--help` argument and settings input file
implicitly from the positional arguments.
2021-05-22 21:38:34 +01:00
Aodhnait Étaín 37f58e24ac first commit, nyan~ 2021-05-22 21:34:55 +01:00