Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81319 / golang2html_code_fold / lexer.lex
diff options
context:
space:
mode:
Commitceb31e1ce115a7c9a6f0cc365beeb1214b246622 (patch)
Author
 Georgi Stefanov <geosteffanov@gmail.com>
2018-11-03 22:13:19 +0200
Committer
 Martin Dobrev <martindobrev0@gmail.com>
2018-11-03 22:13:19 +0200
Files6341efed7f3f5a0208279ac0207d138503fa5e2a /homework/81319/golang2html_code_fold/lexer.lex
IPL-ceb31e1ce115a7c9a6f0cc365beeb1214b246622.tar
IPL-ceb31e1ce115a7c9a6f0cc365beeb1214b246622.tar.gz
IPL-ceb31e1ce115a7c9a6f0cc365beeb1214b246622.zip
Parent9557d0cb5a1b3aa9466ddc504be004b5449ce9f2 (diff)
Add foldable blocks in Golang 2 highlighter (#33)
* initial commit * Add implementation using concatenation * Added block collapsing * Finish block collapsing * Fix nested blocks and + -> - when collapsing * Remove unnecessary files. * Add readme
1 files changed, 100 insertions, 0 deletions
-rw-r--r--homework/81319/golang2html_code_fold/lexer.lex100
diff --git a/homework/81319/golang2html_code_fold/lexer.lex b/homework/81319/golang2html_code_fold/lexer.lex
new file mode 100644
index 0000000..33f27c9
--- /dev/null
+++ b/homework/81319/golang2html_code_fold/lexer.lex
@@ -0,0 +1,100 @@
+
+%{
+#include "parser.tab.h"
+#include <stdlib.h>
+int current_line = 0;
+#define YY_NO_UNISTD_H
+%}
+
+
+digit [0-9]
+id [a-zA-Z_][a-zA-Z0-9_]*
+strq '([^\']|(\\\'))*'
+strdq \"([^\"]|(\\\"))*\"
+number [1-9]{number}*
+fnumber {digit}+"."{digit}*
+
+
+%%
+
+
+{digit}+|{digit}+"."{digit}* {
+ yylval.strval = yytext;
+ return NUMBER;
+}
+
+break|default|func|interface|select|case|defer|go|map|struct {
+ yylval.strval = yytext;
+ return KEYWORD;
+}
+
+chan|else|goto|package|switch|const|fallthrough|if|range|type|continue|for|import|return|var {
+ yylval.strval = yytext;
+ return KEYWORD;
+}
+
+{id} {
+ yylval.strval = yytext;
+ return IDENTIFIER;
+}
+
+{strq} {
+ yylval.strval = yytext;
+ return STRING;
+}
+
+{strdq} {
+ yylval.strval = yytext;
+ return STRING_DQ;
+}
+
+
+"+"|"&"|"+="|"&="|"&&"|"=="|"!="|"-"|"|"|"-="|"|="|"||"|"<" {
+ yylval.strval = yytext;
+ return OPERATOR;
+}
+
+"<="|"["|"]"|"*"|"^"|"*="|"^="|"<-"|">"|">="|"/"|"<<"|"/=" {
+ yylval.strval = yytext;
+ return OPERATOR;
+}
+
+"<<="|"++"|"="|":="|","|";"|"%"|">>"|"%="|">>="|"--"|"!"|"..."|"."|":"|"&^"|"&^=" {
+ yylval.strval = yytext;
+ return OPERATOR;
+}
+
+[;()? \t]+ {
+ yylval.strval = yytext;
+ return MISC;
+}
+
+"{" {
+ yylval.strval = yytext;
+ return LCURLY;
+}
+
+"}" {
+ yylval.strval = yytext;
+ return RCURLY;
+}
+
+\n {
+ ++current_line;
+ yylval.strval = yytext;
+ return MISC;
+}
+
+. {
+ yylval.strval = yytext;
+ return UNRECOGNIZED;
+}
+
+
+%%
+
+int yywrap()
+{
+ return 1;
+}
+