Browse Source

Sol Part 68: And Now For A Feature We Hope You'll Really Enjoy!

Graham Northup 2 years ago
parent
commit
118c45826a
Signed by: Graham Northup <grissess@nexusg.org> GPG Key ID: 5D000E6F539376FB
4 changed files with 267 additions and 84 deletions
  1. 1
    0
      ast.h
  2. 169
    82
      lex.yy.c
  3. 9
    1
      solrun.c
  4. 88
    1
      tokenizer.lex

+ 1
- 0
ast.h View File

@@ -306,6 +306,7 @@ sol_object_t *sol_new_exprnode(sol_state_t *, expr_node *);
306 306
 stmt_node *sol_compile(const char *);
307 307
 stmt_node *sol_compile_buffer(const char *, size_t);
308 308
 stmt_node *sol_compile_file(FILE *);
309
+void sol_write_html(FILE *);
309 310
 expr_node *sol_comp_as_expr(stmt_node *);
310 311
 void sol_compile_free(stmt_node *);
311 312
 

+ 169
- 82
lex.yy.c View File

@@ -580,6 +580,7 @@ int yywrap(void);
580 580
 char *str, *curptr;
581 581
 int cursz, chars;
582 582
 #define SZMUL 128
583
+int writing_html = 0;
583 584
 
584 585
 void str_init(void) {
585 586
 	str = malloc(SZMUL);
@@ -621,9 +622,83 @@ static void update_loc(YYLTYPE *yylloc, char *yytext){
621 622
   yylloc->last_column = curr_col-1;
622 623
 }
623 624
 
624
-#define YY_USER_ACTION update_loc(yylloc, yytext);
625
+char *FONTS[] = {
626
+	"Adobe Courier",
627
+	"Adobe Helvetica",
628
+	"Adobe New Century Schoolbook",
629
+	"Adobe Times",
630
+	"Andale Mono",
631
+	"Arial",
632
+	"Arial Black",
633
+	"C059",
634
+	"Cantarell",
635
+	"Century Schoolbook L",
636
+	"Comic Sans MS",
637
+	"Courier New",
638
+	"cursor.pcf",
639
+	"D050000L",
640
+	"DejaVu Math TeX Gyre",
641
+	"DejaVu Sans",
642
+	"DejaVu Sans,DejaVu Sans Condensed",
643
+	"DejaVu Sans,DejaVu Sans Light",
644
+	"DejaVu Sans Mono",
645
+	"DejaVu Serif",
646
+	"DejaVu Serif,DejaVu Serif Condensed",
647
+	"Denemo",
648
+	"Dingbats",
649
+	"Emmentaler",
650
+	"feta26",
651
+	"Georgia",
652
+	"GNU Unifont",
653
+	"GNU Unifont CSUR",
654
+	"GNU Unifont Sample",
655
+	"Impact",
656
+	"Misc Fixed",
657
+	"Misc Fixed Wide",
658
+	"Nimbus Mono L",
659
+	"Nimbus Mono PS",
660
+	"Nimbus Roman",
661
+	"Nimbus Roman No9 L",
662
+	"NimbusSans",
663
+	"Nimbus Sans",
664
+	"Nimbus Sans L",
665
+	"Nimbus Sans Narrow",
666
+	"P052",
667
+	"Standard Symbols L",
668
+	"Standard Symbols PS",
669
+	"Times New Roman",
670
+	"Trebuchet MS",
671
+	"Unifont",
672
+	"Unifont CSUR",
673
+	"Unifont Sample",
674
+	"Unifont Upper",
675
+	"URW Bookman",
676
+	"URW Bookman L",
677
+	"URW Chancery L",
678
+	"URW Gothic",
679
+	"URW Gothic L",
680
+	"URW Palladio L",
681
+	"Verdana",
682
+	"Webdings",
683
+	"Z003",
684
+};
685
+
686
+static void write_html(char *yytext) {
687
+	if(writing_html) {
688
+		printf("<span style=\"font-family: %s;%s%s%s%s\">%s</span>",
689
+			FONTS[rand() % (sizeof(FONTS) / sizeof(*FONTS))],
690
+			rand() & 1 ? "font-weight: bold;" : "",
691
+			rand() & 1 ? "font-style: italic;" : "",
692
+			rand() & 1 ? "text-decoration: underline;" : "",
693
+			rand() & 1 ? "font-variant: small-caps;" : "",
694
+			yytext
695
+		);
696
+	}
697
+}
625 698
 
626
-#line 626 "lex.yy.c"
699
+#define YY_USER_ACTION update_loc(yylloc, yytext); write_html(yytext);
700
+
701
+#line 701 "lex.yy.c"
627 702
 /* This is the right way to do it, but it keeps generating token $undefined.
628 703
 
629 704
 %x STRING
@@ -639,7 +714,7 @@ static void update_loc(YYLTYPE *yylloc, char *yytext){
639 714
 <STRING>. { str_putc(*yytext); }
640 715
 
641 716
 */
642
-#line 642 "lex.yy.c"
717
+#line 717 "lex.yy.c"
643 718
 
644 719
 #define INITIAL 0
645 720
 
@@ -877,10 +952,10 @@ YY_DECL
877 952
 		}
878 953
 
879 954
 	{
880
-#line 85 "tokenizer.lex"
955
+#line 160 "tokenizer.lex"
881 956
 
882 957
 
883
-#line 883 "lex.yy.c"
958
+#line 958 "lex.yy.c"
884 959
 
885 960
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
886 961
 		{
@@ -940,381 +1015,381 @@ do_action:	/* This label is used only to access EOF actions. */
940 1015
 
941 1016
 case 1:
942 1017
 YY_RULE_SETUP
943
-#line 87 "tokenizer.lex"
1018
+#line 162 "tokenizer.lex"
944 1019
 { *yylval = malloc(sizeof(double)); *((double *) *yylval) = atof(yytext); return FLOAT; }
945 1020
 	YY_BREAK
946 1021
 case 2:
947 1022
 YY_RULE_SETUP
948
-#line 89 "tokenizer.lex"
1023
+#line 164 "tokenizer.lex"
949 1024
 { *yylval = malloc(sizeof(long)); *((long *) *yylval) = atol(yytext); return INT; }
950 1025
 	YY_BREAK
951 1026
 case 3:
952 1027
 /* rule 3 can match eol */
953
-#line 92 "tokenizer.lex"
1028
+#line 167 "tokenizer.lex"
954 1029
 case 4:
955 1030
 /* rule 4 can match eol */
956 1031
 YY_RULE_SETUP
957
-#line 92 "tokenizer.lex"
1032
+#line 167 "tokenizer.lex"
958 1033
 { *yylval = malloc(sizeof(unsigned long) + (yyleng - 2) * sizeof(char)); *((unsigned long *) *yylval) = yyleng - 2; memcpy(((char *) *yylval) + sizeof(unsigned long), yytext + 1, yyleng - 2); return STRING; }
959 1034
 	YY_BREAK
960 1035
 case 5:
961 1036
 YY_RULE_SETUP
962
-#line 94 "tokenizer.lex"
1037
+#line 169 "tokenizer.lex"
963 1038
 { return IF; }
964 1039
 	YY_BREAK
965 1040
 case 6:
966 1041
 YY_RULE_SETUP
967
-#line 96 "tokenizer.lex"
1042
+#line 171 "tokenizer.lex"
968 1043
 { return THEN; }
969 1044
 	YY_BREAK
970 1045
 case 7:
971 1046
 YY_RULE_SETUP
972
-#line 98 "tokenizer.lex"
1047
+#line 173 "tokenizer.lex"
973 1048
 { return ELSE; }
974 1049
 	YY_BREAK
975 1050
 case 8:
976 1051
 YY_RULE_SETUP
977
-#line 100 "tokenizer.lex"
1052
+#line 175 "tokenizer.lex"
978 1053
 { return ELSEIF; }
979 1054
 	YY_BREAK
980 1055
 case 9:
981 1056
 YY_RULE_SETUP
982
-#line 102 "tokenizer.lex"
1057
+#line 177 "tokenizer.lex"
983 1058
 { return WHILE; }
984 1059
 	YY_BREAK
985 1060
 case 10:
986 1061
 YY_RULE_SETUP
987
-#line 104 "tokenizer.lex"
1062
+#line 179 "tokenizer.lex"
988 1063
 { return FOR; }
989 1064
 	YY_BREAK
990 1065
 case 11:
991 1066
 YY_RULE_SETUP
992
-#line 106 "tokenizer.lex"
1067
+#line 181 "tokenizer.lex"
993 1068
 { return IN; }
994 1069
 	YY_BREAK
995 1070
 case 12:
996 1071
 YY_RULE_SETUP
997
-#line 108 "tokenizer.lex"
1072
+#line 183 "tokenizer.lex"
998 1073
 { return DO; }
999 1074
 	YY_BREAK
1000 1075
 case 13:
1001 1076
 YY_RULE_SETUP
1002
-#line 110 "tokenizer.lex"
1077
+#line 185 "tokenizer.lex"
1003 1078
 { return FUNC; }
1004 1079
 	YY_BREAK
1005 1080
 case 14:
1006 1081
 YY_RULE_SETUP
1007
-#line 112 "tokenizer.lex"
1082
+#line 187 "tokenizer.lex"
1008 1083
 { return MACRO; }
1009 1084
 	YY_BREAK
1010 1085
 case 15:
1011 1086
 YY_RULE_SETUP
1012
-#line 114 "tokenizer.lex"
1087
+#line 189 "tokenizer.lex"
1013 1088
 { return LAMBDA; }
1014 1089
 	YY_BREAK
1015 1090
 case 16:
1016 1091
 YY_RULE_SETUP
1017
-#line 116 "tokenizer.lex"
1092
+#line 191 "tokenizer.lex"
1018 1093
 { return RETURN; }
1019 1094
 	YY_BREAK
1020 1095
 case 17:
1021 1096
 YY_RULE_SETUP
1022
-#line 118 "tokenizer.lex"
1097
+#line 193 "tokenizer.lex"
1023 1098
 { return BREAK; }
1024 1099
 	YY_BREAK
1025 1100
 case 18:
1026 1101
 YY_RULE_SETUP
1027
-#line 120 "tokenizer.lex"
1102
+#line 195 "tokenizer.lex"
1028 1103
 { return CONTINUE; }
1029 1104
 	YY_BREAK
1030 1105
 case 19:
1031 1106
 YY_RULE_SETUP
1032
-#line 122 "tokenizer.lex"
1107
+#line 197 "tokenizer.lex"
1033 1108
 { return END; }
1034 1109
 	YY_BREAK
1035 1110
 case 20:
1036 1111
 YY_RULE_SETUP
1037
-#line 124 "tokenizer.lex"
1112
+#line 199 "tokenizer.lex"
1038 1113
 { return NONE; }
1039 1114
 	YY_BREAK
1040 1115
 case 21:
1041 1116
 YY_RULE_SETUP
1042
-#line 126 "tokenizer.lex"
1117
+#line 201 "tokenizer.lex"
1043 1118
 { return PLUS; }
1044 1119
 	YY_BREAK
1045 1120
 case 22:
1046 1121
 YY_RULE_SETUP
1047
-#line 128 "tokenizer.lex"
1122
+#line 203 "tokenizer.lex"
1048 1123
 { return MINUS; }
1049 1124
 	YY_BREAK
1050 1125
 case 23:
1051 1126
 YY_RULE_SETUP
1052
-#line 130 "tokenizer.lex"
1127
+#line 205 "tokenizer.lex"
1053 1128
 { return STAR; }
1054 1129
 	YY_BREAK
1055 1130
 case 24:
1056 1131
 YY_RULE_SETUP
1057
-#line 132 "tokenizer.lex"
1132
+#line 207 "tokenizer.lex"
1058 1133
 { return SLASH; }
1059 1134
 	YY_BREAK
1060 1135
 case 25:
1061 1136
 YY_RULE_SETUP
1062
-#line 134 "tokenizer.lex"
1137
+#line 209 "tokenizer.lex"
1063 1138
 { return PERCENT; }
1064 1139
 	YY_BREAK
1065 1140
 case 26:
1066 1141
 YY_RULE_SETUP
1067
-#line 136 "tokenizer.lex"
1142
+#line 211 "tokenizer.lex"
1068 1143
 { return PERCENT; }
1069 1144
 	YY_BREAK
1070 1145
 case 27:
1071 1146
 YY_RULE_SETUP
1072
-#line 138 "tokenizer.lex"
1147
+#line 213 "tokenizer.lex"
1073 1148
 { return DSTAR; }
1074 1149
 	YY_BREAK
1075 1150
 case 28:
1076 1151
 YY_RULE_SETUP
1077
-#line 140 "tokenizer.lex"
1152
+#line 215 "tokenizer.lex"
1078 1153
 { return BAND; }
1079 1154
 	YY_BREAK
1080 1155
 case 29:
1081 1156
 YY_RULE_SETUP
1082
-#line 142 "tokenizer.lex"
1157
+#line 217 "tokenizer.lex"
1083 1158
 { return BOR; }
1084 1159
 	YY_BREAK
1085 1160
 case 30:
1086 1161
 YY_RULE_SETUP
1087
-#line 144 "tokenizer.lex"
1162
+#line 219 "tokenizer.lex"
1088 1163
 { return BXOR; }
1089 1164
 	YY_BREAK
1090 1165
 case 31:
1091 1166
 YY_RULE_SETUP
1092
-#line 146 "tokenizer.lex"
1167
+#line 221 "tokenizer.lex"
1093 1168
 { return BNOT; }
1094 1169
 	YY_BREAK
1095 1170
 case 32:
1096 1171
 YY_RULE_SETUP
1097
-#line 148 "tokenizer.lex"
1172
+#line 223 "tokenizer.lex"
1098 1173
 { return LAND; }
1099 1174
 	YY_BREAK
1100 1175
 case 33:
1101 1176
 YY_RULE_SETUP
1102
-#line 150 "tokenizer.lex"
1177
+#line 225 "tokenizer.lex"
1103 1178
 { return LAND; }
1104 1179
 	YY_BREAK
1105 1180
 case 34:
1106 1181
 YY_RULE_SETUP
1107
-#line 152 "tokenizer.lex"
1182
+#line 227 "tokenizer.lex"
1108 1183
 { return LOR; }
1109 1184
 	YY_BREAK
1110 1185
 case 35:
1111 1186
 YY_RULE_SETUP
1112
-#line 154 "tokenizer.lex"
1187
+#line 229 "tokenizer.lex"
1113 1188
 { return LOR; }
1114 1189
 	YY_BREAK
1115 1190
 case 36:
1116 1191
 YY_RULE_SETUP
1117
-#line 156 "tokenizer.lex"
1192
+#line 231 "tokenizer.lex"
1118 1193
 { return LNOT; }
1119 1194
 	YY_BREAK
1120 1195
 case 37:
1121 1196
 YY_RULE_SETUP
1122
-#line 158 "tokenizer.lex"
1197
+#line 233 "tokenizer.lex"
1123 1198
 { return LNOT; }
1124 1199
 	YY_BREAK
1125 1200
 case 38:
1126 1201
 YY_RULE_SETUP
1127
-#line 160 "tokenizer.lex"
1202
+#line 235 "tokenizer.lex"
1128 1203
 { *yylval = malloc(sizeof(long)); *((long *) *yylval) = 1; return INT;  }
1129 1204
 	YY_BREAK
1130 1205
 case 39:
1131 1206
 YY_RULE_SETUP
1132
-#line 162 "tokenizer.lex"
1207
+#line 237 "tokenizer.lex"
1133 1208
 { *yylval = malloc(sizeof(long)); *((long *) *yylval) = 1; return INT;  }
1134 1209
 	YY_BREAK
1135 1210
 case 40:
1136 1211
 YY_RULE_SETUP
1137
-#line 164 "tokenizer.lex"
1212
+#line 239 "tokenizer.lex"
1138 1213
 { *yylval = malloc(sizeof(long)); *((long *) *yylval) = 0; return INT;  }
1139 1214
 	YY_BREAK
1140 1215
 case 41:
1141 1216
 YY_RULE_SETUP
1142
-#line 166 "tokenizer.lex"
1217
+#line 241 "tokenizer.lex"
1143 1218
 { *yylval = malloc(sizeof(long)); *((long *) *yylval) = 0; return INT;  }
1144 1219
 	YY_BREAK
1145 1220
 case 42:
1146 1221
 YY_RULE_SETUP
1147
-#line 168 "tokenizer.lex"
1222
+#line 243 "tokenizer.lex"
1148 1223
 { return ASSIGN; }
1149 1224
 	YY_BREAK
1150 1225
 case 43:
1151 1226
 YY_RULE_SETUP
1152
-#line 170 "tokenizer.lex"
1227
+#line 245 "tokenizer.lex"
1153 1228
 { return ASSIGNPLUS; }
1154 1229
 	YY_BREAK
1155 1230
 case 44:
1156 1231
 YY_RULE_SETUP
1157
-#line 172 "tokenizer.lex"
1232
+#line 247 "tokenizer.lex"
1158 1233
 { return ASSIGNMINUS; }
1159 1234
 	YY_BREAK
1160 1235
 case 45:
1161 1236
 YY_RULE_SETUP
1162
-#line 174 "tokenizer.lex"
1237
+#line 249 "tokenizer.lex"
1163 1238
 { return ASSIGNSTAR; }
1164 1239
 	YY_BREAK
1165 1240
 case 46:
1166 1241
 YY_RULE_SETUP
1167
-#line 176 "tokenizer.lex"
1242
+#line 251 "tokenizer.lex"
1168 1243
 { return ASSIGNSLASH; }
1169 1244
 	YY_BREAK
1170 1245
 case 47:
1171 1246
 YY_RULE_SETUP
1172
-#line 178 "tokenizer.lex"
1247
+#line 253 "tokenizer.lex"
1173 1248
 { return ASSIGNDSTAR; }
1174 1249
 	YY_BREAK
1175 1250
 case 48:
1176 1251
 YY_RULE_SETUP
1177
-#line 180 "tokenizer.lex"
1252
+#line 255 "tokenizer.lex"
1178 1253
 { return ASSIGNBAND; }
1179 1254
 	YY_BREAK
1180 1255
 case 49:
1181 1256
 YY_RULE_SETUP
1182
-#line 182 "tokenizer.lex"
1257
+#line 257 "tokenizer.lex"
1183 1258
 { return ASSIGNBOR; }
1184 1259
 	YY_BREAK
1185 1260
 case 50:
1186 1261
 YY_RULE_SETUP
1187
-#line 184 "tokenizer.lex"
1262
+#line 259 "tokenizer.lex"
1188 1263
 { return ASSIGNBXOR; }
1189 1264
 	YY_BREAK
1190 1265
 case 51:
1191 1266
 YY_RULE_SETUP
1192
-#line 186 "tokenizer.lex"
1267
+#line 261 "tokenizer.lex"
1193 1268
 { return EQUAL; }
1194 1269
 	YY_BREAK
1195 1270
 case 52:
1196 1271
 YY_RULE_SETUP
1197
-#line 188 "tokenizer.lex"
1272
+#line 263 "tokenizer.lex"
1198 1273
 { return NEQUAL; }
1199 1274
 	YY_BREAK
1200 1275
 case 53:
1201 1276
 YY_RULE_SETUP
1202
-#line 190 "tokenizer.lex"
1277
+#line 265 "tokenizer.lex"
1203 1278
 { return LESS; }
1204 1279
 	YY_BREAK
1205 1280
 case 54:
1206 1281
 YY_RULE_SETUP
1207
-#line 192 "tokenizer.lex"
1282
+#line 267 "tokenizer.lex"
1208 1283
 { return GREATER; }
1209 1284
 	YY_BREAK
1210 1285
 case 55:
1211 1286
 YY_RULE_SETUP
1212
-#line 194 "tokenizer.lex"
1287
+#line 269 "tokenizer.lex"
1213 1288
 { return LESSEQ; }
1214 1289
 	YY_BREAK
1215 1290
 case 56:
1216 1291
 YY_RULE_SETUP
1217
-#line 196 "tokenizer.lex"
1292
+#line 271 "tokenizer.lex"
1218 1293
 { return GREATEREQ; }
1219 1294
 	YY_BREAK
1220 1295
 case 57:
1221 1296
 YY_RULE_SETUP
1222
-#line 198 "tokenizer.lex"
1297
+#line 273 "tokenizer.lex"
1223 1298
 { return RSHIFT; }
1224 1299
 	YY_BREAK
1225 1300
 case 58:
1226 1301
 YY_RULE_SETUP
1227
-#line 200 "tokenizer.lex"
1302
+#line 275 "tokenizer.lex"
1228 1303
 { return LSHIFT; }
1229 1304
 	YY_BREAK
1230 1305
 case 59:
1231 1306
 YY_RULE_SETUP
1232
-#line 202 "tokenizer.lex"
1307
+#line 277 "tokenizer.lex"
1233 1308
 { return LBRACE; }
1234 1309
 	YY_BREAK
1235 1310
 case 60:
1236 1311
 YY_RULE_SETUP
1237
-#line 204 "tokenizer.lex"
1312
+#line 279 "tokenizer.lex"
1238 1313
 { return RBRACE; }
1239 1314
 	YY_BREAK
1240 1315
 case 61:
1241 1316
 YY_RULE_SETUP
1242
-#line 206 "tokenizer.lex"
1317
+#line 281 "tokenizer.lex"
1243 1318
 { return LBRACKET; }
1244 1319
 	YY_BREAK
1245 1320
 case 62:
1246 1321
 YY_RULE_SETUP
1247
-#line 208 "tokenizer.lex"
1322
+#line 283 "tokenizer.lex"
1248 1323
 { return RBRACKET; }
1249 1324
 	YY_BREAK
1250 1325
 case 63:
1251 1326
 YY_RULE_SETUP
1252
-#line 210 "tokenizer.lex"
1327
+#line 285 "tokenizer.lex"
1253 1328
 { return BLPAREN; } /* "Breaking" paren, not allowed to introduce a call_expr */
1254 1329
 	YY_BREAK
1255 1330
 case 64:
1256 1331
 YY_RULE_SETUP
1257
-#line 212 "tokenizer.lex"
1332
+#line 287 "tokenizer.lex"
1258 1333
 { return LPAREN; } 
1259 1334
 	YY_BREAK
1260 1335
 case 65:
1261 1336
 YY_RULE_SETUP
1262
-#line 214 "tokenizer.lex"
1337
+#line 289 "tokenizer.lex"
1263 1338
 { return RPAREN; }
1264 1339
 	YY_BREAK
1265 1340
 case 66:
1266 1341
 YY_RULE_SETUP
1267
-#line 216 "tokenizer.lex"
1342
+#line 291 "tokenizer.lex"
1268 1343
 { return DOT; }
1269 1344
 	YY_BREAK
1270 1345
 case 67:
1271 1346
 YY_RULE_SETUP
1272
-#line 218 "tokenizer.lex"
1347
+#line 293 "tokenizer.lex"
1273 1348
 { return COLON; }
1274 1349
 	YY_BREAK
1275 1350
 case 68:
1276 1351
 YY_RULE_SETUP
1277
-#line 220 "tokenizer.lex"
1352
+#line 295 "tokenizer.lex"
1278 1353
 { return SEMICOLON; }
1279 1354
 	YY_BREAK
1280 1355
 case 69:
1281 1356
 YY_RULE_SETUP
1282
-#line 222 "tokenizer.lex"
1357
+#line 297 "tokenizer.lex"
1283 1358
 { return COMMA; }
1284 1359
 	YY_BREAK
1285 1360
 case 70:
1286 1361
 YY_RULE_SETUP
1287
-#line 224 "tokenizer.lex"
1362
+#line 299 "tokenizer.lex"
1288 1363
 { return POUND; }
1289 1364
 	YY_BREAK
1290 1365
 case 71:
1291 1366
 YY_RULE_SETUP
1292
-#line 226 "tokenizer.lex"
1367
+#line 301 "tokenizer.lex"
1293 1368
 { return TBANG; }
1294 1369
 	YY_BREAK
1295 1370
 case 72:
1296 1371
 YY_RULE_SETUP
1297
-#line 228 "tokenizer.lex"
1372
+#line 303 "tokenizer.lex"
1298 1373
 { *yylval = (void *) strdup(yytext); return IDENT; }
1299 1374
 	YY_BREAK
1300 1375
 case 73:
1301 1376
 /* rule 73 can match eol */
1302 1377
 YY_RULE_SETUP
1303
-#line 230 "tokenizer.lex"
1378
+#line 305 "tokenizer.lex"
1304 1379
 /* Skip comments */
1305 1380
 	YY_BREAK
1306 1381
 case 74:
1307 1382
 /* rule 74 can match eol */
1308 1383
 YY_RULE_SETUP
1309
-#line 232 "tokenizer.lex"
1384
+#line 307 "tokenizer.lex"
1310 1385
 /* Skip whitespace */
1311 1386
 	YY_BREAK
1312 1387
 case 75:
1313 1388
 YY_RULE_SETUP
1314
-#line 234 "tokenizer.lex"
1389
+#line 309 "tokenizer.lex"
1315 1390
 ECHO;
1316 1391
 	YY_BREAK
1317
-#line 1317 "lex.yy.c"
1392
+#line 1392 "lex.yy.c"
1318 1393
 case YY_STATE_EOF(INITIAL):
1319 1394
 	yyterminate();
1320 1395
 
@@ -2322,7 +2397,7 @@ void yyfree (void * ptr )
2322 2397
 
2323 2398
 #define YYTABLES_NAME "yytables"
2324 2399
 
2325
-#line 234 "tokenizer.lex"
2400
+#line 309 "tokenizer.lex"
2326 2401
 
2327 2402
 
2328 2403
 int yywrap(void) {
@@ -2362,3 +2437,15 @@ stmt_node *sol_compile_file(FILE *prgfile) {
2362 2437
     return program;
2363 2438
 }
2364 2439
 
2440
+void sol_write_html(FILE *prgfile) {
2441
+	stmt_node *program = NULL;
2442
+	YY_BUFFER_STATE buf = yy_create_buffer(prgfile, YY_BUF_SIZE);
2443
+	writing_html = 1;
2444
+	printf("<html><head><title>Sol Source File</title></head><body style=\"white-space: pre-wrap;\">\n");
2445
+	yy_switch_to_buffer(buf);
2446
+	yyparse(&program);
2447
+	yy_delete_buffer(buf);
2448
+	//stmt_free(program);
2449
+	printf("</body></html>\n");
2450
+}
2451
+

+ 9
- 1
solrun.c View File

@@ -12,7 +12,7 @@ int main(int argc, char **argv) {
12 12
 	char *c;
13 13
 	int printtree = 0, clean = 1, argidx = 2;
14 14
 	FILE *prgstream = stdin, *compstream = NULL;
15
-	int result = 0, compile = 0, compiled = 0;
15
+	int result = 0, compile = 0, compiled = 0, html = 0;
16 16
 
17 17
 	state.features = 0;
18 18
 
@@ -79,6 +79,10 @@ int main(int argc, char **argv) {
79 79
 							printf("- $HOME%s\n", sol_HomeInitPaths[i]);
80 80
 					return 0;
81 81
 					break;
82
+
83
+				case 'H':
84
+					html = 1;
85
+					break;
82 86
 			}
83 87
 			c++;
84 88
 		}
@@ -92,6 +96,10 @@ int main(int argc, char **argv) {
92 96
 	if(compiled) {
93 97
 		program = sol_deser_stmt(prgstream);
94 98
 	} else {
99
+		if(html) {
100
+			sol_write_html(prgstream);
101
+			return;
102
+		}
95 103
 		program = sol_compile_file(prgstream);
96 104
 	}
97 105
 	

+ 88
- 1
tokenizer.lex View File

@@ -14,6 +14,7 @@ int yywrap(void);
14 14
 char *str, *curptr;
15 15
 int cursz, chars;
16 16
 #define SZMUL 128
17
+int writing_html = 0;
17 18
 
18 19
 void str_init(void) {
19 20
 	str = malloc(SZMUL);
@@ -55,7 +56,81 @@ static void update_loc(YYLTYPE *yylloc, char *yytext){
55 56
   yylloc->last_column = curr_col-1;
56 57
 }
57 58
 
58
-#define YY_USER_ACTION update_loc(yylloc, yytext);
59
+char *FONTS[] = {
60
+	"Adobe Courier",
61
+	"Adobe Helvetica",
62
+	"Adobe New Century Schoolbook",
63
+	"Adobe Times",
64
+	"Andale Mono",
65
+	"Arial",
66
+	"Arial Black",
67
+	"C059",
68
+	"Cantarell",
69
+	"Century Schoolbook L",
70
+	"Comic Sans MS",
71
+	"Courier New",
72
+	"cursor.pcf",
73
+	"D050000L",
74
+	"DejaVu Math TeX Gyre",
75
+	"DejaVu Sans",
76
+	"DejaVu Sans,DejaVu Sans Condensed",
77
+	"DejaVu Sans,DejaVu Sans Light",
78
+	"DejaVu Sans Mono",
79
+	"DejaVu Serif",
80
+	"DejaVu Serif,DejaVu Serif Condensed",
81
+	"Denemo",
82
+	"Dingbats",
83
+	"Emmentaler",
84
+	"feta26",
85
+	"Georgia",
86
+	"GNU Unifont",
87
+	"GNU Unifont CSUR",
88
+	"GNU Unifont Sample",
89
+	"Impact",
90
+	"Misc Fixed",
91
+	"Misc Fixed Wide",
92
+	"Nimbus Mono L",
93
+	"Nimbus Mono PS",
94
+	"Nimbus Roman",
95
+	"Nimbus Roman No9 L",
96
+	"NimbusSans",
97
+	"Nimbus Sans",
98
+	"Nimbus Sans L",
99
+	"Nimbus Sans Narrow",
100
+	"P052",
101
+	"Standard Symbols L",
102
+	"Standard Symbols PS",
103
+	"Times New Roman",
104
+	"Trebuchet MS",
105
+	"Unifont",
106
+	"Unifont CSUR",
107
+	"Unifont Sample",
108
+	"Unifont Upper",
109
+	"URW Bookman",
110
+	"URW Bookman L",
111
+	"URW Chancery L",
112
+	"URW Gothic",
113
+	"URW Gothic L",
114
+	"URW Palladio L",
115
+	"Verdana",
116
+	"Webdings",
117
+	"Z003",
118
+};
119
+
120
+static void write_html(char *yytext) {
121
+	if(writing_html) {
122
+		printf("<span style=\"font-family: %s;%s%s%s%s\">%s</span>",
123
+			FONTS[rand() % (sizeof(FONTS) / sizeof(*FONTS))],
124
+			rand() & 1 ? "font-weight: bold;" : "",
125
+			rand() & 1 ? "font-style: italic;" : "",
126
+			rand() & 1 ? "text-decoration: underline;" : "",
127
+			rand() & 1 ? "font-variant: small-caps;" : "",
128
+			yytext
129
+		);
130
+	}
131
+}
132
+
133
+#define YY_USER_ACTION update_loc(yylloc, yytext); write_html(yytext);
59 134
 
60 135
 %}
61 136
 
@@ -269,3 +344,15 @@ stmt_node *sol_compile_file(FILE *prgfile) {
269 344
     yy_delete_buffer(buf);
270 345
     return program;
271 346
 }
347
+
348
+void sol_write_html(FILE *prgfile) {
349
+	stmt_node *program = NULL;
350
+	YY_BUFFER_STATE buf = yy_create_buffer(prgfile, YY_BUF_SIZE);
351
+	writing_html = 1;
352
+	printf("<html><head><title>Sol Source File</title></head><body style=\"white-space: pre-wrap;\">\n");
353
+	yy_switch_to_buffer(buf);
354
+	yyparse(&program);
355
+	yy_delete_buffer(buf);
356
+	//stmt_free(program);
357
+	printf("</body></html>\n");
358
+}

Loading…
Cancel
Save