From 8116da5f88b18591decd8fa53d7be8b354ec1fa9 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 26 Nov 2016 23:26:12 +0100 Subject: Strings --- ast.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/ast.cpp b/ast.cpp index 68d4d4b..f1cbcc0 100644 --- a/ast.cpp +++ b/ast.cpp @@ -113,12 +113,40 @@ public: nextat++; } return true; + } else if(source[index]=='"'){ + for(nextat=index+1;nextat='0'&&c<='9'){ + return c-'0'; + } else if(c>='a'&&c<='f'){ + return c-'a'+10; + } else if(c>='A'&&c<='F'){ + return c-'A'+10; + } else { + return -1; + } +} + AST& AST::parse(AST::Tokeniser &tokeniser){ if(tokeniser.eof()){ throw ParseError("No tokens to parse"); @@ -128,15 +156,12 @@ AST& AST::parse(AST::Tokeniser &tokeniser){ throw logic_error("Unexpected empty token from tokeniser"); } if(isdigit(token[0])||(token.size()>1&&token[0]=='-'&&isdigit(token[1]))){ - // cerr<<"AST::parse: type = number"<=(i64)token.size()-1){ + throw ParseError("Not enough characters after hexadecimal" + " escape sequence"); + } + char hex1=parseHex(token[i+2]), + hex2=parseHex(token[i+3]); + if(hex1==-1||hex2==-1){ + throw ParseError("Invalid characters in hexadecimal" + " escape sequence"); + } + strval+=(hex1<<4)|hex2; + i+=2; + break; + } + default: strval+=token[i+1]; break; + } + i++; + } else { + strval+=token[i]; + } + } } else if(token==")"){ throw ParseError("Unexpected token '"+token+"'"); } else { -- cgit v1.2.3-70-g09d2