From ac07e589b3e912c704c2011d543f18b16712ff15 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 29 Dec 2018 15:27:18 -0800 Subject: 4890 - new html renderings a) Switch to a light background. b) Linkify calls in .subx files. c) Keep all colorization in the Vim colorscheme, get rid of hacky special-cases in update_html. --- html/subx/038---literal_strings.cc.html | 356 +++++++++++++++----------------- 1 file changed, 172 insertions(+), 184 deletions(-) (limited to 'html/subx/038---literal_strings.cc.html') diff --git a/html/subx/038---literal_strings.cc.html b/html/subx/038---literal_strings.cc.html index a66897db..43f995a5 100644 --- a/html/subx/038---literal_strings.cc.html +++ b/html/subx/038---literal_strings.cc.html @@ -7,27 +7,22 @@ - + @@ -132,179 +127,172 @@ if ('onhashchange' in window) { 67 } 68 } 69 - 70 line label(string s) { - 71 line result; - 72 result.words.push_back(word()); - 73 result.words.back().data = (s+":"); - 74 return result; - 75 } - 76 - 77 //: Within strings, whitespace is significant. So we need to redo our instruction - 78 //: parsing. - 79 - 80 :(scenarios parse_instruction_character_by_character) - 81 :(scenario instruction_with_string_literal) - 82 a "abc def" z # two spaces inside string - 83 +parse2: word: a - 84 +parse2: word: "abc def" - 85 +parse2: word: z - 86 # no other words - 87 $parse2: 3 - 88 - 89 :(before "End Line Parsing Special-cases(line_data -> l)") - 90 if (line_data.find('"') != string::npos) { // can cause false-positives, but we can handle them - 91 parse_instruction_character_by_character(line_data, l); - 92 continue; - 93 } - 94 - 95 :(code) - 96 void parse_instruction_character_by_character(const string& line_data, vector<line>& out) { - 97 if (line_data.find('\n') != string::npos && line_data.find('\n') != line_data.size()-1) { - 98 raise << "parse_instruction_character_by_character: should receive only a single line\n" << end(); - 99 return; -100 } -101 // parse literals -102 istringstream in(line_data); -103 in >> std::noskipws; -104 line result; -105 // add tokens (words or strings) one by one -106 while (has_data(in)) { -107 skip_whitespace(in); -108 if (!has_data(in)) break; -109 char c = in.get(); -110 if (c == '#') break; // comment; drop rest of line -111 if (c == ':') break; // line metadata; skip for now -112 if (c == '.') { -113 if (!has_data(in)) break; // comment token at end of line -114 if (isspace(in.peek())) -115 continue; // '.' followed by space is comment token; skip -116 } -117 result.words.push_back(word()); -118 if (c == '"') { -119 // slurp word data -120 ostringstream d; -121 d << c; -122 while (has_data(in)) { -123 in >> c; -124 d << c; -125 if (c == '"') break; -126 } -127 result.words.back().data = d.str(); -128 // slurp metadata -129 ostringstream m; -130 while (!isspace(in.peek()) && has_data(in)) { -131 in >> c; -132 if (c == '/') { -133 if (!m.str().empty()) result.words.back().metadata.push_back(m.str()); -134 m.str(""); -135 } -136 else { -137 m << c; -138 } -139 } -140 if (!m.str().empty()) result.words.back().metadata.push_back(m.str()); -141 } -142 else { -143 // slurp all characters until whitespace -144 ostringstream w; -145 w << c; -146 while (!isspace(in.peek()) && has_data(in)) { // peek can sometimes trigger eof(), so do it first -147 in >> c; -148 w << c; -149 } -150 parse_word(w.str(), result.words.back()); -151 } -152 trace(99, "parse2") << "word: " << to_string(result.words.back()) << end(); -153 } -154 if (!result.words.empty()) -155 out.push_back(result); + 70 //: Within strings, whitespace is significant. So we need to redo our instruction + 71 //: parsing. + 72 + 73 :(scenarios parse_instruction_character_by_character) + 74 :(scenario instruction_with_string_literal) + 75 a "abc def" z # two spaces inside string + 76 +parse2: word: a + 77 +parse2: word: "abc def" + 78 +parse2: word: z + 79 # no other words + 80 $parse2: 3 + 81 + 82 :(before "End Line Parsing Special-cases(line_data -> l)") + 83 if (line_data.find('"') != string::npos) { // can cause false-positives, but we can handle them + 84 parse_instruction_character_by_character(line_data, l); + 85 continue; + 86 } + 87 + 88 :(code) + 89 void parse_instruction_character_by_character(const string& line_data, vector<line>& out) { + 90 if (line_data.find('\n') != string::npos && line_data.find('\n') != line_data.size()-1) { + 91 raise << "parse_instruction_character_by_character: should receive only a single line\n" << end(); + 92 return; + 93 } + 94 // parse literals + 95 istringstream in(line_data); + 96 in >> std::noskipws; + 97 line result; + 98 // add tokens (words or strings) one by one + 99 while (has_data(in)) { +100 skip_whitespace(in); +101 if (!has_data(in)) break; +102 char c = in.get(); +103 if (c == '#') break; // comment; drop rest of line +104 if (c == ':') break; // line metadata; skip for now +105 if (c == '.') { +106 if (!has_data(in)) break; // comment token at end of line +107 if (isspace(in.peek())) +108 continue; // '.' followed by space is comment token; skip +109 } +110 result.words.push_back(word()); +111 if (c == '"') { +112 // slurp word data +113 ostringstream d; +114 d << c; +115 while (has_data(in)) { +116 in >> c; +117 d << c; +118 if (c == '"') break; +119 } +120 result.words.back().data = d.str(); +121 // slurp metadata +122 ostringstream m; +123 while (!isspace(in.peek()) && has_data(in)) { +124 in >> c; +125 if (c == '/') { +126 if (!m.str().empty()) result.words.back().metadata.push_back(m.str()); +127 m.str(""); +128 } +129 else { +130 m << c; +131 } +132 } +133 if (!m.str().empty()) result.words.back().metadata.push_back(m.str()); +134 } +135 else { +136 // slurp all characters until whitespace +137 ostringstream w; +138 w << c; +139 while (!isspace(in.peek()) && has_data(in)) { // peek can sometimes trigger eof(), so do it first +140 in >> c; +141 w << c; +142 } +143 parse_word(w.str(), result.words.back()); +144 } +145 trace(99, "parse2") << "word: " << to_string(result.words.back()) << end(); +146 } +147 if (!result.words.empty()) +148 out.push_back(result); +149 } +150 +151 void skip_whitespace(istream& in) { +152 while (true) { +153 if (has_data(in) && isspace(in.peek())) in.get(); +154 else break; +155 } 156 } 157 -158 void skip_whitespace(istream& in) { -159 while (true) { -160 if (has_data(in) && isspace(in.peek())) in.get(); -161 else break; +158 void skip_comment(istream& in) { +159 if (has_data(in) && in.peek() == '#') { +160 in.get(); +161 while (has_data(in) && in.peek() != '\n') in.get(); 162 } 163 } 164 -165 void skip_comment(istream& in) { -166 if (has_data(in) && in.peek() == '#') { -167 in.get(); -168 while (has_data(in) && in.peek() != '\n') in.get(); -169 } -170 } -171 -172 // helper for tests -173 void parse_instruction_character_by_character(const string& line_data) { -174 vector<line> out; -175 parse_instruction_character_by_character(line_data, out); -176 } -177 -178 :(scenario parse2_comment_token_in_middle) -179 a . z -180 +parse2: word: a -181 +parse2: word: z -182 -parse2: word: . -183 # no other words -184 $parse2: 2 -185 -186 :(scenario parse2_word_starting_with_dot) -187 a .b c -188 +parse2: word: a -189 +parse2: word: .b -190 +parse2: word: c -191 -192 :(scenario parse2_comment_token_at_start) -193 . a b -194 +parse2: word: a -195 +parse2: word: b -196 -parse2: word: . -197 -198 :(scenario parse2_comment_token_at_end) -199 a b . -200 +parse2: word: a -201 +parse2: word: b -202 -parse2: word: . -203 -204 :(scenario parse2_word_starting_with_dot_at_start) -205 .a b c -206 +parse2: word: .a -207 +parse2: word: b -208 +parse2: word: c -209 -210 :(scenario parse2_metadata) -211 .a b/c d -212 +parse2: word: .a -213 +parse2: word: b /c -214 +parse2: word: d -215 -216 :(scenario parse2_string_with_metadata) -217 a "bc def"/disp32 g -218 +parse2: word: a -219 +parse2: word: "bc def" /disp32 -220 +parse2: word: g -221 -222 :(scenario parse2_string_with_metadata_at_end) -223 a "bc def"/disp32 -224 +parse2: word: a -225 +parse2: word: "bc def" /disp32 -226 -227 :(code) -228 void test_parse2_string_with_metadata_at_end_of_line_without_newline() { -229 parse_instruction_character_by_character( -230 "68/push \"test\"/f" // no newline, which is how calls from parse() will look -231 ); -232 CHECK_TRACE_CONTENTS( -233 "parse2: word: 68 /push^D" -234 "parse2: word: \"test\" /f^D" -235 ); -236 } -237 -238 //: Make sure slashes inside strings don't trigger adding stuff from inside the -239 //: string to metadata. -240 :(scenario parse2_string_containing_slashes) -241 a "bc/def"/disp32 -242 +parse2: word: "bc/def" /disp32 +165 // helper for tests +166 void parse_instruction_character_by_character(const string& line_data) { +167 vector<line> out; +168 parse_instruction_character_by_character(line_data, out); +169 } +170 +171 :(scenario parse2_comment_token_in_middle) +172 a . z +173 +parse2: word: a +174 +parse2: word: z +175 -parse2: word: . +176 # no other words +177 $parse2: 2 +178 +179 :(scenario parse2_word_starting_with_dot) +180 a .b c +181 +parse2: word: a +182 +parse2: word: .b +183 +parse2: word: c +184 +185 :(scenario parse2_comment_token_at_start) +186 . a b +187 +parse2: word: a +188 +parse2: word: b +189 -parse2: word: . +190 +191 :(scenario parse2_comment_token_at_end) +192 a b . +193 +parse2: word: a +194 +parse2: word: b +195 -parse2: word: . +196 +197 :(scenario parse2_word_starting_with_dot_at_start) +198 .a b c +199 +parse2: word: .a +200 +parse2: word: b +201 +parse2: word: c +202 +203 :(scenario parse2_metadata) +204 .a b/c d +205 +parse2: word: .a +206 +parse2: word: b /c +207 +parse2: word: d +208 +209 :(scenario parse2_string_with_metadata) +210 a "bc def"/disp32 g +211 +parse2: word: a +212 +parse2: word: "bc def" /disp32 +213 +parse2: word: g +214 +215 :(scenario parse2_string_with_metadata_at_end) +216 a "bc def"/disp32 +217 +parse2: word: a +218 +parse2: word: "bc def" /disp32 +219 +220 :(code) +221 void test_parse2_string_with_metadata_at_end_of_line_without_newline() { +222 parse_instruction_character_by_character( +223 "68/push \"test\"/f" // no newline, which is how calls from parse() will look +224 ); +225 CHECK_TRACE_CONTENTS( +226 "parse2: word: 68 /push^D" +227 "parse2: word: \"test\" /f^D" +228 ); +229 } +230 +231 //: Make sure slashes inside strings don't trigger adding stuff from inside the +232 //: string to metadata. +233 :(scenario parse2_string_containing_slashes) +234 a "bc/def"/disp32 +235 +parse2: word: "bc/def" /disp32 -- cgit 1.4.1-2-gfad0