Описание языка в формате .doc можно скачать здесь.
Описание языка Compressed-HTML
1 Общие сведения
Язык Compressed-HTML создан для хранения документов, позднее преобразуемых программными средствами в подмножество элементов языка HTML. Заимствуя принципы языка JSON, Compressed-HTML является более экономным с точки зрения занимаемой памяти форматом по сравнению с HTML.
Автор: Боднарюк Василий Васильевич (Vasilii V. Bodnariuk)
Лицензия MIT.
2 Элементы языка
2.1 Описание лексики
Исходный документ содержит в себе некоторую последовательность символов: букв латинского и русского алфавитов, цифр и прочих символов, представимых в кодировке ascii.
Будем называть строкой последовательность допустимых символов (за исключением двойных кавычек), в том числе пустую , заключенную в двойные кавычки.
В конструкциях языка присутствуют строки, фигурные и квадратные скобки, двоеточия, символы решетки, запятые, а также служебные слова a, b, body, form, head, html, p, div, br, hr, img, input, link, meta.Символы табуляции, переноса строки и возврата каретки игнорируются.
2.2 Описание синтаксиса
Описание синтаксиса приводится в формате РБНФ, где последовательность терминальных символов заключается в кавычки.
Содержимым документа на языке Compressed-HTML должен являться объект.
object = "{" [tag {"," tag}] "}" .
tag = unpaired_tag |
paired_tag |
text_tag .
unpaired_tag = unpaired_list [":" "[" attributes "]"] .
paired_tag = paired_list ":" ["[" attributes "]"] object .
text_tag = "#" ":" String .
attributes = String ":" String {"," String ":" String } .
paired_list = "a" |
"b" |
"body" |
"form" |
"head" |
"html" |
"p" |
"div" .
unpaired_list = "br" |
"hr" |
"img" |
"input" |
"link" |
"meta" .
Скачать архив с исходниками программы, которая переводит текст из Compressed-HTML в HTML, можно здесь (если Вы желаете только ознакомиться с моим кодом, достаточно будет посмотреть фрагменты ниже).
Файлы compressed-html.cpp
, Output.cpp
, Output.h
написаны мною, файлы Parser.cpp
, Parser.h
, Scanner.cpp
, Scanner.h
генерируются с помощью генератора компиляторов Coco/R из файла compressed-html_object.atg
, также написанного мною.
Написанный мною код
compressed-html.cpp
//============================================================================
// Name : compressed-html.cpp
// Author : Vasilii Bodnariuk
// Version :
// Copyright : The MIT License (MIT). Copyright (c) 2015 Bodnariuk Vasilii
// Description : compressed-html to html in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstdlib>
#include <wchar.h>
#include "Scanner.h"
#include "Parser.h"
using namespace std;
int main(int argc, char **argv)
{
try
{
wchar_t dst[100];
mbstowcs(dst, argv[1], 100);
Scanner *scanner = new Scanner(dst);
Parser *parser = new Parser(scanner);
parser->Parse();
delete parser;
delete scanner;
cout << argv[1] << " check succeed."<< endl;
}
catch (...)
{
cout << "Smth went wrong. Check your PC existence." << endl;
}
return 0;
}
Output.h
/*
* Output.h
*
* Created on: 15 мая 2015 г.
* Author: vasilesk
*/
#ifndef OUTPUT_H_
#define OUTPUT_H_
#include <string>
#include <iostream>
#include <fstream>
#include <stack>
class Output_processing
{
public:
Output_processing ();
~Output_processing ();
void write (std::string str_to_write);
void write (wchar_t *str_to_write);
void write_without_quotes (wchar_t *str_to_write);
void push_unpaired_tag (std::string tag_to_push);
void push_paired_tag (std::string tag_to_push);
void set_text_buffer (std::string str_to_set);
void write_tag_buffer ();
void write_text_buffer ();
private:
std::ofstream output_file;
std::string tag_buffer;
std::string text_buffer;
std::stack<std::string> tag_stack;
};
#endif /* OUTPUT_H_ */
Output.cpp
/*
* Output.cpp
*
* Created on: 15 мая 2015 г.
* Author: vasilesk
*/
#include <string>
#include <iostream>
#include <fstream>
#include "Output.h"
using namespace std;
Output_processing::Output_processing ()
{
output_file.open("output.html");
}
Output_processing::~Output_processing ()
{
output_file.close();
}
void Output_processing::write (std::string str_to_write)
{
output_file << str_to_write;
}
void Output_processing::write (wchar_t* str_to_write)
{
wstring ws(str_to_write);
string str(ws.begin(), ws.end());
output_file << str;
}
void Output_processing::write_without_quotes (wchar_t *str_to_write)
{
wstring ws(str_to_write);
string str(ws.begin(), ws.end());
output_file << str.substr(1,str.length()-2);
}
void Output_processing::push_unpaired_tag (std::string tag_to_push)
{
tag_stack.push(tag_to_push);
}
void Output_processing::push_paired_tag (std::string tag_to_push)
{
tag_stack.push(tag_to_push);
tag_stack.push(tag_to_push);
}
void Output_processing::set_text_buffer (std::string str_to_set)
{
text_buffer = str_to_set;
}
void Output_processing::write_tag_buffer ()
{
tag_buffer = tag_stack.top();
tag_stack.pop();
output_file << tag_buffer;
}
void Output_processing::write_text_buffer ()
{
output_file << text_buffer;
}
compressed-html_object.atg
#include
{ html: [ "xmlns":"http://www.w3.org/1999/xhtml", "xml:lang":"ru" ] { head: { #:"" }, body: { #:"text one ", a: [ "href":"#" ] { #:"click here" }, br, b: { #:"bold text" }, br, form: { input: [ "placeholder":"your name here" ], #:" ", input: [ "type":"button", "value":"Click this button" ] }, p: { #:"text in paragraph", hr, #:"text after line" } } } }
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru"><head></head><body>text one <a href="#">click here</a><br><b>bold text</b><br><form><input placeholder="your name here"> <input type="button" value="Click this button"></form><p>text in paragraph<hr>text after line</p></body></html>
Этот и другие примеры в архиве здесь.