Vasilesk World

Язык Compressed-HTML

Василий Боднарюк

Описание языка в формате .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 
#include 
#include 
#include "Output.h"

using namespace std; 

COMPILER object 

Output_processing output;


 
 
IGNORECASE
CHARACTERS
CharInLine = ANY - '\r' - '\n'.
cr  = '\r'.
lf  = '\n'.
tab = '\t'.
AnyButDoubleQuote = CharInLine - '\"'.
TOKENS
String = '"' {AnyButDoubleQuote | "\\\""} '"'.

 
COMMENTS FROM "/*" TO "*/" NESTED
COMMENTS FROM "//" TO cr lf
 
IGNORE cr + lf + tab
 
PRODUCTIONS

	object = "{" [tag {"," tag}] "}".

	tag =  unpaired_tag |
		paired_tag |
		text_tag.

	unpaired_tag = unpaired_list
		(.
			output.write ("<");
			output.write_tag_buffer();
		.)
		 [":" "[" attributes "]"]
		(.

			output.write (">");
		.).

	paired_tag = paired_list
		(.
			output.write ("<");
			output.write_tag_buffer();
		.)
		":" ["[" attributes "]"]
		(.
			output.write (">");
		.)
		object
		(.
			output.write ("");
		.).

	text_tag = "#" ":" String (. output.write_without_quotes (t->val); .).

	attributes = String (. output.write (" ");output.write_without_quotes (t->val); .) 
		":" (. output.write ("="); .)
		String 
			(. output.write (t->val); .)
		{"," String
			(. output.write (" ");output.write_without_quotes (t->val); .)
		":"  (. output.write ("="); .)
		String
			(. output.write (t->val); .)}.



	paired_list = "a" (. output.push_paired_tag ("a"); .) |
		"b" (. output.push_paired_tag ("b"); .) |
		"body" (. output.push_paired_tag ("body"); .) |
		"form" (. output.push_paired_tag ("form"); .) |
		"head" (. output.push_paired_tag ("head"); .) |
		"html" (. output.push_paired_tag ("html"); .) |
		"p" (. output.push_paired_tag ("p"); .) |
		"div" (. output.push_paired_tag ("div"); .) .

	unpaired_list = "br" (. output.push_unpaired_tag ("br"); .) |
		"hr" (. output.push_unpaired_tag ("hr"); .) |
		"img" (. output.push_unpaired_tag ("img"); .) |
		"input" (. output.push_unpaired_tag ("input"); .) |
		"link" (. output.push_unpaired_tag ("link"); .) |
		"meta" (. output.push_unpaired_tag ("meta"); .) .

END object .


Пример входного файла
{
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>

Этот и другие примеры в архиве здесь.



A PHP Error was encountered

Severity: Core Warning

Message: Module 'pgsql' already loaded

Filename: Unknown

Line Number: 0

Backtrace: