From 37c28b32eea1e55d708dbf1efd260e9ef5477079 Mon Sep 17 00:00:00 2001 From: Aleksey Yakovlev Date: Wed, 8 May 2024 13:47:29 +0700 Subject: [PATCH] added cst string support --- src/cst/parser.rs | 14 ++++++++++++++ src/main.rs | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cst/parser.rs b/src/cst/parser.rs index 6a45875..261fc3c 100644 --- a/src/cst/parser.rs +++ b/src/cst/parser.rs @@ -79,6 +79,7 @@ fn parse_emit_statement(node: &AstNode) -> Result parse_atom_hex_into(child, &mut atoms)?, + AstNodeType::AtomUtf8 => parse_atom_utf8_into(child, &mut atoms)?, _ => panic!("Unexpected node type: {:?}", child.node_type) } } @@ -91,6 +92,8 @@ fn parse_emit_statement(node: &AstNode) -> Result) -> Result<(), CstParserError> { + guard_node_type(node, AstNodeType::AtomHex)?; + let content = node.clone().content .ok_or(CstParserError::MissingContent { node_type: AstNodeType::AtomHex })?; @@ -106,6 +109,17 @@ fn parse_atom_hex_into(node: &AstNode, buf: &mut Vec) -> Result<(), Cst return Ok(()); } +fn parse_atom_utf8_into(node: &AstNode, buf: &mut Vec) -> Result<(), CstParserError> { + guard_node_type(node, AstNodeType::AtomUtf8)?; + + let content = node.clone().content + .ok_or(CstParserError::MissingContent { node_type: AstNodeType::AtomUtf8 })?; + + buf.push(CstAtom::String(content)); + + return Ok(()); +} + fn guard_node_type(node: &AstNode, expected_type: AstNodeType) -> Result<(), CstParserError> { if node.node_type != expected_type { return Err( diff --git a/src/main.rs b/src/main.rs index aaf0589..2ab2fa3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ fn new_compiler() { let source = StringCompilerSource::new( PathBuf::from(""), - "> 01 02 03" + "> 01 02 03 'lol'" ); let compilation_result = compiler.compile(source);