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