]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/documentation/DocumentationLexer.flex
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / parsing / documentation / DocumentationLexer.flex
1 package org.simantics.scl.compiler.parsing.documentation;\r
2 \r
3 %%\r
4 \r
5 %public\r
6 %char\r
7 %unicode\r
8 %class DocumentationLexer\r
9 %function nextToken\r
10 %type DocumentationElement\r
11 %yylexthrow DocumentationParsingException\r
12 %eofval{\r
13     return null;\r
14 %eofval}\r
15 \r
16 %{\r
17     public static String trimW(String text) {\r
18         int a = 0, b = text.length();\r
19         while(a < b) {\r
20             char c = text.charAt(a);\r
21             if(c != ' ' && c != '\t' && c != '\r' && c != '\n')\r
22                 break;\r
23             ++a;\r
24         }\r
25         while(a < b) {\r
26             char c = text.charAt(b-1);\r
27             if(c != ' ' && c != '\t' && c != '\r' && c != '\n')\r
28                 break;\r
29             --b;\r
30         }\r
31         return text.substring(a, b);\r
32     }\r
33 \r
34     public static String trimN(String text, int amount) {        \r
35         text = trimW(text);\r
36         return text.substring(amount, text.length()-amount).trim();\r
37     }\r
38 %}\r
39 \r
40 whitespace      = [ \t]\r
41 eol             = "\n" | "\r\n"\r
42 textStartChar   = [^ \n\r*>=-]\r
43 textLine        = {whitespace}* {textStartChar} [^\n\r]* {eol}\r
44 emptyLine       = {eol}\r
45 h1              = "=" [^\n\r=][^\n\r]*[^\n\r=] "=" {whitespace}* {eol}\r
46 h2              = "==" [^\n\r=][^\n\r]*[^\n\r=] "==" {whitespace}* {eol}\r
47 h3              = "===" [^\n\r=][^\n\r]*[^\n\r=] "===" {whitespace}* {eol}\r
48 h3              = "===" [^\n\r=][^\n\r]*[^\n\r=] "===" {whitespace}* {eol}\r
49 listItem        = [*#]+ [^\n\r]* {eol}\r
50 birdTrack       = ">" [^\n\r]* {eol}\r
51 entityRef       = "-" [^\n\r]* {eol}\r
52 %%\r
53 \r
54 <YYINITIAL> {\r
55     {textLine}+   { return new Paragraph(yytext().trim()); }\r
56     {birdTrack}+  { return new Preformatted(yytext()); }\r
57     {h1}          { return new Header(1, trimN(yytext(), 1)); }\r
58     {h2}          { return new Header(2, trimN(yytext(), 2)); }\r
59     {h3}          { return new Header(3, trimN(yytext(), 3)); }\r
60     {listItem}    { return new ListItem(trimW(yytext())); }\r
61     {entityRef}   { return new EntityRef(trimW(yytext().substring(1))); }\r
62     {emptyLine}   { }    \r
63     {whitespace}+ { }\r
64      .            { System.err.println("At " + yychar + ": Illegal character '" + yytext() + "'."); }\r
65 }\r