X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fparsing%2Fdocumentation%2FDocumentationLexer.flex;h=9ed5a2e0e62ab7341f4f9f29b4e6336ce6decefb;hb=refs%2Fchanges%2F38%2F238%2F2;hp=d57c3556c057b21e5bc85b081f6137ec98f8d839;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/documentation/DocumentationLexer.flex b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/documentation/DocumentationLexer.flex index d57c3556c..9ed5a2e0e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/documentation/DocumentationLexer.flex +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/documentation/DocumentationLexer.flex @@ -1,65 +1,65 @@ -package org.simantics.scl.compiler.parsing.documentation; - -%% - -%public -%char -%unicode -%class DocumentationLexer -%function nextToken -%type DocumentationElement -%yylexthrow DocumentationParsingException -%eofval{ - return null; -%eofval} - -%{ - public static String trimW(String text) { - int a = 0, b = text.length(); - while(a < b) { - char c = text.charAt(a); - if(c != ' ' && c != '\t' && c != '\r' && c != '\n') - break; - ++a; - } - while(a < b) { - char c = text.charAt(b-1); - if(c != ' ' && c != '\t' && c != '\r' && c != '\n') - break; - --b; - } - return text.substring(a, b); - } - - public static String trimN(String text, int amount) { - text = trimW(text); - return text.substring(amount, text.length()-amount).trim(); - } -%} - -whitespace = [ \t] -eol = "\n" | "\r\n" -textStartChar = [^ \n\r*>=-] -textLine = {whitespace}* {textStartChar} [^\n\r]* {eol} -emptyLine = {eol} -h1 = "=" [^\n\r=][^\n\r]*[^\n\r=] "=" {whitespace}* {eol} -h2 = "==" [^\n\r=][^\n\r]*[^\n\r=] "==" {whitespace}* {eol} -h3 = "===" [^\n\r=][^\n\r]*[^\n\r=] "===" {whitespace}* {eol} -h3 = "===" [^\n\r=][^\n\r]*[^\n\r=] "===" {whitespace}* {eol} -listItem = [*#]+ [^\n\r]* {eol} -birdTrack = ">" [^\n\r]* {eol} -entityRef = "-" [^\n\r]* {eol} -%% - - { - {textLine}+ { return new Paragraph(yytext().trim()); } - {birdTrack}+ { return new Preformatted(yytext()); } - {h1} { return new Header(1, trimN(yytext(), 1)); } - {h2} { return new Header(2, trimN(yytext(), 2)); } - {h3} { return new Header(3, trimN(yytext(), 3)); } - {listItem} { return new ListItem(trimW(yytext())); } - {entityRef} { return new EntityRef(trimW(yytext().substring(1))); } - {emptyLine} { } - {whitespace}+ { } - . { System.err.println("At " + yychar + ": Illegal character '" + yytext() + "'."); } -} +package org.simantics.scl.compiler.parsing.documentation; + +%% + +%public +%char +%unicode +%class DocumentationLexer +%function nextToken +%type DocumentationElement +%yylexthrow DocumentationParsingException +%eofval{ + return null; +%eofval} + +%{ + public static String trimW(String text) { + int a = 0, b = text.length(); + while(a < b) { + char c = text.charAt(a); + if(c != ' ' && c != '\t' && c != '\r' && c != '\n') + break; + ++a; + } + while(a < b) { + char c = text.charAt(b-1); + if(c != ' ' && c != '\t' && c != '\r' && c != '\n') + break; + --b; + } + return text.substring(a, b); + } + + public static String trimN(String text, int amount) { + text = trimW(text); + return text.substring(amount, text.length()-amount).trim(); + } +%} + +whitespace = [ \t] +eol = "\n" | "\r\n" +textStartChar = [^ \n\r*>=-] +textLine = {whitespace}* {textStartChar} [^\n\r]* {eol} +emptyLine = {eol} +h1 = "=" [^\n\r=][^\n\r]*[^\n\r=] "=" {whitespace}* {eol} +h2 = "==" [^\n\r=][^\n\r]*[^\n\r=] "==" {whitespace}* {eol} +h3 = "===" [^\n\r=][^\n\r]*[^\n\r=] "===" {whitespace}* {eol} +h3 = "===" [^\n\r=][^\n\r]*[^\n\r=] "===" {whitespace}* {eol} +listItem = [*#]+ [^\n\r]* {eol} +birdTrack = ">" [^\n\r]* {eol} +entityRef = "-" [^\n\r]* {eol} +%% + + { + {textLine}+ { return new Paragraph(yytext().trim()); } + {birdTrack}+ { return new Preformatted(yytext()); } + {h1} { return new Header(1, trimN(yytext(), 1)); } + {h2} { return new Header(2, trimN(yytext(), 2)); } + {h3} { return new Header(3, trimN(yytext(), 3)); } + {listItem} { return new ListItem(trimW(yytext())); } + {entityRef} { return new EntityRef(trimW(yytext().substring(1))); } + {emptyLine} { } + {whitespace}+ { } + . { System.err.println("At " + yychar + ": Illegal character '" + yytext() + "'."); } +}