diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-01-16 23:00:39 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-01-16 23:00:39 +0100 |
| commit | 70878885f5d169f2c5d9e66d3919ee56d5f9f9ca (patch) | |
| tree | fc4ebbc0f0246edb93e6fde6c816cbca4dc93bef /src/syntax/mod.rs | |
| parent | 08b91a265fcda74f5463473938ec33873b49a7f7 (diff) | |
Do argument parsing ☑
Diffstat (limited to 'src/syntax/mod.rs')
| -rw-r--r-- | src/syntax/mod.rs | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index bcec05af..e9725f04 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -154,6 +154,22 @@ pub struct FuncArgs { pub keyword: Object, } +#[derive(Debug, Clone, PartialEq)] +pub enum Arg { + Pos(Spanned<Expression>), + Key(Pair), +} + +impl Arg { + /// The span or the value or combined span of key and value. + pub fn span(&self) -> Span { + match self { + Arg::Pos(spanned) => spanned.span, + Arg::Key(Pair { key, value }) => Span::merge(key.span, value.span), + } + } +} + impl FuncArgs { pub fn new() -> FuncArgs { FuncArgs { @@ -246,32 +262,40 @@ pub struct Colorization { pub tokens: Vec<Spanned<ColorToken>>, } +impl Colorization { + pub fn new() -> Colorization { + Colorization { tokens: vec![] } + } + + pub fn add(&mut self, token: ColorToken, span: Span) { + self.tokens.push(Spanned { v: token, span }); + } + + pub fn replace_last(&mut self, token: ColorToken) { + self.tokens.last_mut().expect("replace_last: no token").v = token; + } +} + /// Entities which can be colored by syntax highlighting. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum ColorToken { Comment, - Bracket, FuncName, Colon, - Key, Equals, Comma, - Paren, Brace, - ExprIdent, ExprStr, ExprNumber, ExprSize, ExprBool, - Bold, Italic, Monospace, - Invalid, } @@ -279,3 +303,17 @@ pub enum ColorToken { pub struct ErrorMap { pub errors: Vec<Spanned<String>>, } + +impl ErrorMap { + pub fn new() -> ErrorMap { + ErrorMap { errors: vec![] } + } + + pub fn add(&mut self, message: impl Into<String>, span: Span) { + self.errors.push(Spanned { v: message.into(), span }); + } + + pub fn add_at(&mut self, message: impl Into<String>, pos: Position) { + self.errors.push(Spanned { v: message.into(), span: Span::at(pos) }) + } +} |
