summaryrefslogtreecommitdiff
path: root/src/syntax.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-10 23:35:16 +0200
committerLaurenz <laurmaedje@gmail.com>2019-10-10 23:35:16 +0200
commit61470fba68e9f19b481034427add5f3d8cfbc0a8 (patch)
tree65ae88e73018dd76d46e3b0761b32ba0e17f5f55 /src/syntax.rs
parentf22a3070001e9c8db6fcc7b83b036111a6559a3d (diff)
Basic positional argument parsing 🗃
Supported types are identifiers, strings, numbers, sizes and booleans.
Diffstat (limited to 'src/syntax.rs')
-rw-r--r--src/syntax.rs33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/syntax.rs b/src/syntax.rs
index 7d30d894..ac40c562 100644
--- a/src/syntax.rs
+++ b/src/syntax.rs
@@ -1,7 +1,9 @@
//! Tokenized and syntax tree representations of source code.
use std::collections::HashMap;
+use std::fmt::{self, Display, Formatter};
use crate::func::Function;
+use crate::size::Size;
/// A logical unit of the incoming text stream.
@@ -15,15 +17,17 @@ pub enum Token<'s> {
LeftBracket,
/// A right bracket: `]`.
RightBracket,
- /// A colon (`:`) indicating the beginning of function arguments.
+ /// A colon (`:`) indicating the beginning of function arguments (Function header only).
///
/// If a colon occurs outside of a function header, it will be tokenized as a
/// [Word](Token::Word).
Colon,
- /// An equals (`=`) sign assigning a function argument a value.
- ///
- /// Outside of functions headers, same as with [Colon](Token::Colon).
+ /// An equals (`=`) sign assigning a function argument a value (Function header only).
Equals,
+ /// A comma (`,`) separating two function arguments (Function header only).
+ Comma,
+ /// Quoted text as a string value (Function header only).
+ Quoted(&'s str),
/// An underscore, indicating text in italics.
Underscore,
/// A star, indicating bold text.
@@ -98,4 +102,23 @@ pub struct FuncHeader {
/// A value expression.
#[derive(Debug, Clone, PartialEq)]
-pub enum Expression {}
+pub enum Expression {
+ Ident(String),
+ Str(String),
+ Number(f64),
+ Size(Size),
+ Bool(bool),
+}
+
+impl Display for Expression {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ use Expression::*;
+ match self {
+ Ident(s) => write!(f, "{}", s),
+ Str(s) => write!(f, "{:?}", s),
+ Number(n) => write!(f, "{}", n),
+ Size(s) => write!(f, "{}", s),
+ Bool(b) => write!(f, "{}", b),
+ }
+ }
+}