From 5e0d74b70b15d63993539c07905e0a9ba8117b5b Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Fri, 24 Mar 2023 02:17:46 -0400 Subject: Better character literal parsing --- tnslc/simple.tnsl | 5 ++++- tnslc/tnslc.tnsl | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'tnslc') diff --git a/tnslc/simple.tnsl b/tnslc/simple.tnsl index b55be2a..b140c7a 100644 --- a/tnslc/simple.tnsl +++ b/tnslc/simple.tnsl @@ -1,10 +1,13 @@ {}uint8 str1 = "abcd" -{}uint8 str2 = "abcd" +{}uint8 str2 = "abce" /; main [int] /; loop (int i = 0; i < 4) [i++] /; if (str1{i} !== str2{i}) + /; if (str2{i} == 'e') + return 3 + ;/ return 1 ;/ ;/ diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 9853af6..df2eb54 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -134,6 +134,10 @@ ;return 0 ;/ + /; if (str{1} !== '\\') + ;return str{1} + ;/ + ;uint8 cmp = str{2} /; if (cmp == '\\') ;return '\\' @@ -145,8 +149,9 @@ ;return '\t' ;; else if (cmp == '0') ;return '\0' + ;; else if (cmp == '\'') + ;return '\'' ;/ - ;/ /; unquote_str({}uint8 str) [{}uint8] @@ -2427,7 +2432,7 @@ ;v.name = l ;; else if (data{0} == '\'') ;v.data_type = {1, "uint8", "", {}, {}} - ;v.location = unqote_char(tok`{start}.data) + ;v.location = unqote_char(data) ;; else if (string_equate(data, "true")) ;v.data_type = {1, "bool", "", {}, {}} ;v.location = 1 -- cgit v1.2.3