Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Meow;
- function ReplaceMix(str, find, repl, punc: string): string;
- var
- i, x: Integer;
- mat: Boolean;
- begin
- repeat
- i := PosEx(find, str, i + 1);
- if i <= 0 then
- Break;
- for x := 1 to Length(punc) do
- if not mat then
- if str[i - 1] = punc[x] then
- mat := True;
- if not mat then
- Continue;
- for x := 1 to Length(punc) do
- if not mat then
- if str[i + Length(find) + 1] = punc[x] then
- mat := True;
- if not mat then
- Continue;
- Delete(str, i, Length(find));
- Insert(repl, str, i);
- i := i + Length(repl);
- until false;
- Result := str;
- end;
- function ExportAsHTML(input: string): string;
- var
- KeyWords: TStringArray;
- header, punct: string;
- i, x, y: integer;
- begin
- punct := ' [!"%&''()*+,-./:;<=>?@[\]_`{|}~]' + #13#10;
- KeyWords := ['begin', 'end', 'else', 'try', ' except ', ' finally ', ' finally ', ' repeat ', ' until ', ' procedure ', ' function ', ' var ', ' const ', ' if ', ' string ', ' and ', ' array ', ' as ', ' case ', ' class ', ' const ', ' div ', ' do ', ' downto ', ' end ', ' for ', ' goto ', ' in ', ' is' , ' mod ', ' not ', ' object ', ' of ', ' on ', ' or ', ' procedure ', ' program ', ' record ', ' repeat ', ' set ', ' shl ', ' shr ', ' then ', ' to ', ' type ', ' while ', ' with ', ' xor ', ' forward '];
- header := '<html>' + #13#10 + ' <head>' + #13#10 + ' <title>DanCardin</title>' + #13#10 + ' <script>' + #13#10 + ' .key { font-weight: bold;}' + #13#10 + ' .string { color: fuchsia;}' + #13#10 + ' .comment { color: green;}' + #13#10 + ' </script>' + #13#10 + ' </head>' + #13#10 + ' <body>' + #13#10;
- Result := LowerCase(input);
- if (Trim(Result) = '') then
- Exit;
- Result := ' ' + Replace(Result, Chr(13) + Chr(10), ' ') + ' ';
- for i := 0 to high(keywords) do
- Result := ReplaceMix(Result, KeyWords[i], '<div class="key">' + keywords[i] + '</div>', punct);
- Result := header + Result + #13#10 + ' </body>' + #13#10 + '</html>';
- end;
- begin
- Writeln(ExportAsHTML('begin end; meow .try.'));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement