seam

Symbolic-Expressions As Markup.
git clone git://git.knutsen.co/seam
Log | Files | Refs | README | LICENSE

commit 27bbd52fed4cb5ad46492d6c75908109ae28421a
parent cf3af37f4b2850d46f524cbe0c4d6eb417a0882f
Author: Demonstrandum <moi@knutsen.co>
Date:   Tue,  1 Dec 2020 19:39:57 +0000

Add some much needed basic string escapes.

Diffstat:
MCargo.toml | 2+-
Msrc/lib.rs | 2+-
Msrc/parse/lexer.rs | 11+++++++++++
Mtest.html | 29+++++++++++++++++++++++++++++
4 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -4,7 +4,7 @@ description = "Symbolic Expressions As Markup." keywords = ["markup", "lisp", "macro", "symbolic-expression", "sexp"] license-file = "LICENSE" homepage = "https://git.knutsen.co/seam" -version = "0.1.4" +version = "0.1.5" authors = ["Demonstrandum <moi@knutsen.co>"] edition = "2018" diff --git a/src/lib.rs b/src/lib.rs @@ -6,7 +6,7 @@ use parse::{expander, parser, lexer}; use std::error::Error; use std::{fs, io, path::Path}; -pub const VERSION : (u8, u8, u8) = (0, 1, 3); +pub const VERSION : (u8, u8, u8) = (0, 1, 5); pub fn parse<P: AsRef<Path>>(string : String, source : Option<P>) -> Result<parser::ParseTree, Box<dyn Error>> { diff --git a/src/parse/lexer.rs b/src/parse/lexer.rs @@ -131,6 +131,17 @@ pub fn lex<P: AsRef<Path>>(string : String, source : Option<P>) if character == '\\' { // Escapes if current_kind == Some(tokens::Kind::String) { // How escapes work in strings (TODO) + let new_char = match string.as_bytes()[bytes + 1] as char { + 'n' => '\n', + 't' => '\t', + 'r' => '\r', + '0' => '\0', + c => c, + }; + accumulator.push(new_char as u8); + bytes += 2; + line_bytes += 2; + continue; } else { // How they work outside strings: // TODO: add more escapes. diff --git a/test.html b/test.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<html lang="en"><head><title>Example HTML Document</title> +<style> +html { + width: 100%; + height: 100%; +} +html , body { + margin: 0; + padding: 0; +} +body { + padding: 4em 6em; +} +#hello { + color: rgb(24 calc((3 + (7 * 3) + 1)) 4); + font-family: sans-serif; +} +img { + border-radius: 5px; +} +</style></head> +<body><p id="hello">Hello, World!</p> +<p>something something text...</p> +<h1>A (big) Header!</h1> +<p>Yet some more <span style="color: red">text</span> <3</p> +<p>Hello<span style="color: green">World</span>!</p> +<img alt="Cute cat" src="https://static.insider.com/image/5d24d6b921a861093e71fef3.jpg" width="300"></img></body></html> +<!-- Generated by SEAM, from symbolic-expressions into HTML. -->