From dba769e13ca5029643c6068e53fa34ae0fea8421 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 28 Feb 2025 13:23:20 +1300 Subject: Implement string literals String literals are treated as integers. If a string is passed as an integer argument to a packed binary literal, a new instance of the packed binary literal is invoked for every character in the string, with each character being passed to the packed binary literal as a Unicode character value. --- src/parsers/syntactic.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/parsers/syntactic.rs') diff --git a/src/parsers/syntactic.rs b/src/parsers/syntactic.rs index 37f8e6c..f3fcec1 100644 --- a/src/parsers/syntactic.rs +++ b/src/parsers/syntactic.rs @@ -77,6 +77,21 @@ impl SyntacticParser { None => SynVar::Error(SynErr::UnterminatedExpression), } } + '"' => { + t.mark_child(); + match t.eat_to_delimiter('"') { + Some(string) => { + let child = t.subtokenise(); + t.mark_end(); + let chars = parse_tracked_chars(child); + let tracked_string = TrackedString { + source: t.get_source(), string, chars, + }; + SynVar::String(tracked_string) + } + None => SynVar::Error(SynErr::UnterminatedString), + } + } '(' => match t.eat_to_delimiter(')') { Some(string) => { // Check if the comment fills the entire line. @@ -145,3 +160,13 @@ impl SyntacticParser { return self.tokens; } } + + +fn parse_tracked_chars(mut t: Tokeniser) -> Vec> { + let mut output = Vec::new(); + while let Some(c) = t.eat_char() { + output.push(Tracked::from(c, t.get_source())); + t.mark_start(); + } + return output; +} -- cgit v1.2.3-70-g09d2