--- /dev/null
+package org.simantics.scl.compiler.parsing.documentation;\r
+\r
+%%\r
+\r
+%public\r
+%char\r
+%unicode\r
+%class DocumentationLexer\r
+%function nextToken\r
+%type DocumentationElement\r
+%yylexthrow DocumentationParsingException\r
+%eofval{\r
+ return null;\r
+%eofval}\r
+\r
+%{\r
+ public static String trimW(String text) {\r
+ int a = 0, b = text.length();\r
+ while(a < b) {\r
+ char c = text.charAt(a);\r
+ if(c != ' ' && c != '\t' && c != '\r' && c != '\n')\r
+ break;\r
+ ++a;\r
+ }\r
+ while(a < b) {\r
+ char c = text.charAt(b-1);\r
+ if(c != ' ' && c != '\t' && c != '\r' && c != '\n')\r
+ break;\r
+ --b;\r
+ }\r
+ return text.substring(a, b);\r
+ }\r
+\r
+ public static String trimN(String text, int amount) { \r
+ text = trimW(text);\r
+ return text.substring(amount, text.length()-amount).trim();\r
+ }\r
+%}\r
+\r
+whitespace = [ \t]\r
+eol = "\n" | "\r\n"\r
+textStartChar = [^ \n\r*>=-]\r
+textLine = {whitespace}* {textStartChar} [^\n\r]* {eol}\r
+emptyLine = {eol}\r
+h1 = "=" [^\n\r=][^\n\r]*[^\n\r=] "=" {whitespace}* {eol}\r
+h2 = "==" [^\n\r=][^\n\r]*[^\n\r=] "==" {whitespace}* {eol}\r
+h3 = "===" [^\n\r=][^\n\r]*[^\n\r=] "===" {whitespace}* {eol}\r
+h3 = "===" [^\n\r=][^\n\r]*[^\n\r=] "===" {whitespace}* {eol}\r
+listItem = [*#]+ [^\n\r]* {eol}\r
+birdTrack = ">" [^\n\r]* {eol}\r
+entityRef = "-" [^\n\r]* {eol}\r
+%%\r
+\r
+<YYINITIAL> {\r
+ {textLine}+ { return new Paragraph(yytext().trim()); }\r
+ {birdTrack}+ { return new Preformatted(yytext()); }\r
+ {h1} { return new Header(1, trimN(yytext(), 1)); }\r
+ {h2} { return new Header(2, trimN(yytext(), 2)); }\r
+ {h3} { return new Header(3, trimN(yytext(), 3)); }\r
+ {listItem} { return new ListItem(trimW(yytext())); }\r
+ {entityRef} { return new EntityRef(trimW(yytext().substring(1))); }\r
+ {emptyLine} { } \r
+ {whitespace}+ { }\r
+ . { System.err.println("At " + yychar + ": Illegal character '" + yytext() + "'."); }\r
+}\r