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