diff options
| Commit | 9557d0cb5a1b3aa9466ddc504be004b5449ce9f2 (patch) | |
|---|---|---|
| Author | 2018-11-03 15:22:53 +0200 | |
| Committer | 2018-11-03 15:22:53 +0200 | |
| Files | 296b007f8913f4ecda3b790af94b04cc329407ce /homework/81281/c2html/print.pl | |
| IPL-9557d0cb5a1b3aa9466ddc504be004b5449ce9f2.tar IPL-9557d0cb5a1b3aa9466ddc504be004b5449ce9f2.tar.gz IPL-9557d0cb5a1b3aa9466ddc504be004b5449ce9f2.zip | ||
| Parent | 113598bd4636b65720df6af87ea5a94661907c8c (diff) | |
Added prettifier and control structure collapse. (#19)
* Create README.md
* Initial commit
* Initial commit
* Create README.md
* Rename homework/81281/c2html.pl to homework/81281/c2html/c2html.pl
* Rename homework/81281/test.c to homework/81281/c2html/test.c
* Update README.md
* Update README.md
* Update c2html.pl
* Update c2html.pl
* Update c2html.pl
* Update README.md
* Update c2html.pl
* Update test.c
* Create executeProgram.sh
* Update README.md
* Update c2html.pl
* Initial commit of updated code + prettify C
* Rename secret.c to messyCode.c
* Update and rename test.c to initialTest.c
* Update README.md
* Update README.md
* Update README.md
* Update README.md
* Rename executeProgram.sh to c2htmlrun.sh
* Update README.md
* Update prettify.pl
* Update prettify.pl
* Update messyCode.c
* Fixed some bugs.
* Update README.md
* Update c2html.pl
* Added collapse and fixed matrix representation.
* Updated flatten and added predicate for function identification.
* Update initialTest.c
* Update messyCode.c
* Bug fixing, added is_functionAndBody predicate.
* Update print.pl
* Result after applying prettify and added collapse functions
* Can identify structures and collapse them too
* Can identify structures and collapse them too
* Can identify structures and collapse them too
* Can identify structures and collapse them too
* Can identify structures and collapse them too
* Update messyCode.c
* Update README.md
* Update prettify.pl
* Update README.md
* Update prettify.pl
* Update messyCode.c
* Update messyCode.c
* Update page.html
* Fix bug typedef
* Update page.html
* Added choices
* Update c2html.pl
* Update prettify.pl
* Update prettify.pl
* Update README.md
* Update README.md
* Update c2html.pl
* Update c2html.pl
* Added forgotten do-while structure format
* Update messyCode.c
* Removing unknown tokens from stream
* Rename homework/81281/c2html/page.html to homework/81281/c2html/exampleCodeAndTestPage/page.html
* Rename homework/81281/c2html/messyCode.c to homework/81281/c2html/exampleCodeAndTestPage/messyCode.c
* Rename homework/81281/c2html/initialTest.c to homework/81281/c2html/exampleCodeAndTestPage/initialTest.c
* Update prettify.pl
* Can collapse all control structures and fixed comment /**/
* Can collapse all control structures and fixed comment /**/
* Can collapse all control structures and fixed comment /**/
* Can collapse all control structures and fixed comment /**/
* Can collapse all control structures and fixed comment /**/
* Fixed named of predicates
* Update messyCode.c
* Update page.html
* Update README.md
* Changed execTAB to "\s\s\s\s"
* Changed execTAB to "\s\s\s\s"
* Changed execTAB to "\s\s\s\s"
* Update page.html
* Added new tokens (forgotten operators) and added rules for them
* Added new tokens (forgotten operators) and fixed some old predicates
* Fixed bug with "else '\n' if (..)" in addNewLines predicate
* Fixed regular expression for a string and removed token ttypesPrintF
* Added clauses for handling enum and fixed handling of chars
* Fixed typos
* Added forgotten token to clause
* Fixed "case smt :'\n'" where smt is more than one char
* Fixed some bugs and divided code in modules
* New code module and fixed bugs
* Fixed some bugs with tabulation
* Divided code in modules
1 files changed, 103 insertions, 0 deletions
| -rw-r--r-- | homework/81281/c2html/print.pl | 103 |
diff --git a/homework/81281/c2html/print.pl b/homework/81281/c2html/print.pl new file mode 100644 index 0000000..d115e46 --- /dev/null +++ b/homework/81281/c2html/print.pl @@ -0,0 +1,103 @@ +%% Writing to html file the stream of tokens +tohtmlfile(_, []):- !. + +tohtmlfile(Stream, [H|T]) :- is_identifier(H), H = [_,Lexem], + write(Stream, '<span class=\"identifier\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_string(H), H = [_,Lexem], + write(Stream, '<span class=\"string\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_function(H), H = [_, Lexem], + write(Stream, '<span class=\"function\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_header(H), H = [_,Lexem], + write(Stream, '<span class=\"string\"><'), + write(Stream, Lexem), + write(Stream,'></span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_keyWord(H), H = [_,Lexem], + write(Stream, '<span class=\"keyword\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_number(H), H = [_,Lexem], + write(Stream, '<span class=\"number\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_operator(H), H = [_,Lexem], + write(Stream, '<span class=\"operator\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_parenth(H), H = [_,Lexem], + write(Stream, '<span class=\"parenthese\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_quotation(H), H = [_,Lexem], + write(Stream, '<span class=\"quotation\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_unknown(H), H = [_,Lexem], + write(Stream, '<span class=\"unknown\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_comment(H), H = [_,Lexem], + write(Stream, '<span class=\"comment\">'), + write(Stream, Lexem), + write(Stream,'</span>'), + !, + tohtmlfile(Stream, T). + +tohtmlfile(Stream, [H|T]) :- is_controlStructureBody(H), + write(Stream, '<button class=\"collapsible\">'), + H = [H1|T1], + tohtmlfile(Stream, H1), + write(Stream, '</span></button>'), nl(Stream), + write(Stream, '<div class=\"content\">'), + helper(Stream, T1), + write(Stream,'</div>'), + !, + tohtmlfile(Stream, T). + + +tohtmlfile(Stream, [H|T]) :- is_blank(H), H = [_,Lexem], + write(Stream, Lexem), + !, + tohtmlfile(Stream, T). + + + +helper(_, []). +helper(Stream, L):- append(A, [H|B], L), is_controlStructureBody(H), + helper(Stream,A), tohtmlfile(Stream, [H]), helper(Stream,B). +helper(Stream, [H|T]):- tohtmlfile(Stream, H), helper(Stream, T). |
