1 package org.simantics.scl.compiler.parsing.documentation;
\r
8 %class DocumentationLexer
\r
10 %type DocumentationElement
\r
11 %yylexthrow DocumentationParsingException
\r
17 public static String trimW(String text) {
\r
18 int a = 0, b = text.length();
\r
20 char c = text.charAt(a);
\r
21 if(c != ' ' && c != '\t' && c != '\r' && c != '\n')
\r
26 char c = text.charAt(b-1);
\r
27 if(c != ' ' && c != '\t' && c != '\r' && c != '\n')
\r
31 return text.substring(a, b);
\r
34 public static String trimN(String text, int amount) {
\r
36 return text.substring(amount, text.length()-amount).trim();
\r
42 textStartChar = [^ \n\r*>=-]
\r
43 textLine = {whitespace}* {textStartChar} [^\n\r]* {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
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
64 . { System.err.println("At " + yychar + ": Illegal character '" + yytext() + "'."); }
\r