Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81030 / rust2html.flex
diff options
context:
space:
mode:
Commit5729bc0ea96fc0b944c243230910c537d692bcad (patch)
Author
 Radoslav Georgiev <rgeorgiev583@gmail.com>
2018-11-17 19:11:03 +0200
Committer
 dtrendafilov <trendafilov.dn@gmail.com>
2018-11-17 19:11:02 +0200
Files43db75a7acf93c6c2c8e07c3a87590fe14fb4e4f /homework/81030/rust2html.flex
IPL-5729bc0ea96fc0b944c243230910c537d692bcad.tar
IPL-5729bc0ea96fc0b944c243230910c537d692bcad.tar.gz
IPL-5729bc0ea96fc0b944c243230910c537d692bcad.zip
Parent9420791a9335fc174627bea5f2a25f434bbe7ae5 (diff)
implement the second homework assignment (#39)
* Rust syntax highlighter: fix some issues with the implementation of the first homework assignment * Rust syntax highlighter: pretty-printer: implement the second homework assignment
1 files changed, 0 insertions, 115 deletions
-rw-r--r--homework/81030/rust2html.flex115
diff --git a/homework/81030/rust2html.flex b/homework/81030/rust2html.flex
deleted file mode 100644
index 6684d82..0000000
--- a/homework/81030/rust2html.flex
+++ /dev/null
@@ -1,115 +0,0 @@
-/* scanner for the Rust programming language */
-
-%{
-#define YY_NO_UNISTD_H
-%}
-
-NONEOL_CHAR [^\n]
-DEC_DIGIT 0|{NONZERO_DEC_DIGIT}
-NONZERO_DEC_DIGIT [1-9]
-OCT_DIGIT [0-7]
-HEX_DIGIT {DEC_DIGIT}|[a-fA-F]
-
-IDENTIFIER {IDENTIFIER_FIRST_CHAR}({DEC_DIGIT}|{IDENTIFIER_FIRST_CHAR})*
-IDENTIFIER_FIRST_CHAR [A-Za-z_]
-
-COMMENT {BLOCK_COMMENT}|{LINE_COMMENT}
-BLOCK_COMMENT "/*".*"*/"
-LINE_COMMENT "//"{NONEOL_CHAR}*
-
-KEYWORD _|abstract|alignof|as|become|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|offsetof|override|priv|proc|pub|pure|ref|return|Self|self|sizeof|static|struct|super|trait|true|type|typeof|unsafe|unsized|use|virtual|where|while|yield
-
-ESCAPE {COMMON_ESCAPE}|{UNICODE_ESCAPE}
-COMMON_ESCAPE \\|n|r|t|0|x{HEX_DIGIT}{2}
-UNICODE_ESCAPE "u{"{HEX_DIGIT}{6}"}"
-
-CHAR_LITERAL '{CHAR_BODY}'
-CHAR_BODY [^']|(\\('|{ESCAPE}))
-STRING_LITERAL \"{STRING_BODY}*\"
-STRING_BODY [^\"]|(\\(\"|{ESCAPE}))
-BYTE_CHAR_LITERAL b'{BYTE_CHAR_BODY}'
-BYTE_CHAR_BODY [^']|(\\('|{COMMON_ESCAPE}))
-BYTE_STRING_LITERAL b\"{BYTE_STRING_BODY}*\"
-BYTE_STRING_BODY [^\"]|(\\(\"|{ESCAPE}))
-
-NUMBER_LITERAL {NONZERO_DEC_DIGIT}{DEC_DIGIT}*{FLOAT_SUFFIX}?|(0{DEC_DIGIT_LITERAL}*{FLOAT_SUFFIX}?|b[10_]+|o{OCT_DIGIT_LITERAL}+|x{HEX_DIGIT_LITERAL}+)
-FLOAT_SUFFIX {EXPONENT}|"."{DEC_DIGIT_LITERAL}+{EXPONENT}?
-EXPONENT [Ee][-+]?{DEC_DIGIT_LITERAL}+
-DEC_DIGIT_LITERAL {DEC_DIGIT}|_
-HEX_DIGIT_LITERAL {HEX_DIGIT}|_
-OCT_DIGIT_LITERAL {OCT_DIGIT}|_
-
-SYMBOL "::"|"->"|"#"|"["|"]"|"("|")"|"{"|"}"|","|";"
-
-%%
-
-{SYMBOL} {
- printf("<span class=\"symbol\">%s</span>", yytext);
-}
-
-{KEYWORD} {
- printf("<span class=\"keyword\">%s</span>", yytext);
-}
-
-{NUMBER_LITERAL} {
- printf("<span class=\"number\">%s</span>", yytext);
-}
-
-{IDENTIFIER} {
- printf("<span class=\"identifier\">%s</span>", yytext);
-}
-
-{CHAR_LITERAL}|{STRING_LITERAL}|{BYTE_CHAR_LITERAL}|{BYTE_STRING_LITERAL} {
- printf("<span class=\"string\">%s</span>", yytext);
-}
-
-{COMMENT} {
- printf("<span class=\"comment\">%s</span>", yytext);
-}
-
-. {
- printf("%s", yytext); /* echo the rest */
-}
-
-%%
-
-int yywrap() {
- return 1;
-}
-
-int main(int argc, const char* argv[]) {
- yyin = argc > 1 ? fopen(argv[1], "r") : stdin;
-
- puts(
- "<!DOCTYPE html>"
- "<html>"
- "<head>"
- " <style>"
- " .comment {"
- " color: gray;"
- " }"
- " .keyword {"
- " color: red;"
- " }"
- " .string {"
- " color: green;"
- " }"
- " .number {"
- " color: blue;"
- " }"
- " .symbol {"
- " font-weight: bold;"
- " }"
- " </style>"
- "</head>"
- "<body>"
- " <pre class=\"code\">"
- );
- yylex();
- puts(
- " </pre>"
- "</body>"
- "</html>");
-
- return 0;
-}