lexer grammar Creole; options { language=Python; } @members { out = True codeblock = False pre = False macro = 0 mstart = False mend = False mquote = False tmacro = 0 tstart = False img = False link = False sol = True list = False table = False } // Block OPEN_CODEBLOCK : {self.out and self.sol}?=> '{{{\n' {self.out = False; self.codeblock = True}; CLOSE_CODEBLOCK : {self.codeblock}?=> '\n}}}' {self.out = True; self.codeblock = True; self.sol = False}; UNORDERED_LIST_START : {self.out and not self.list and self.sol}?=> '*' {self.sol = False; self.list = True}; UNORDERED_LIST : {self.out and self.list and self.sol}?=> ('*')+ {self.sol = False}; ORDERED_LIST_START : {self.out and not self.list and self.sol}?=> '#' {self.sol = False; self.list = True}; ORDERED_LIST : {self.out and self.list and self.sol}?=> ('#')+ {self.sol = False}; HEADING : {self.out and self.sol}?=> ('=')+ { self.sol = False }; BLOCKQUOTE : {self.out and self.sol}?=> (':' | '>')+ {self.sol = False}; TABLE_HEADING : {self.out and (self.sol or self.table)}?=> '|=' { self.sol = False; self.table = True }; TABLE_CELL : {self.out and (self.sol or self.table)}?=> '|' { self.sol = False; self.table = True }; // Inline BOLD : {self.out}?=> '**' {self.sol = False}; ITALIC : {self.out}?=> '//' {self.sol = False}; MONOSPACE : {self.out}?=> '##' {self.sol = False}; SUPERSCRIPT : {self.out}?=> '^^' {self.sol = False}; SUBSCRIPT : {self.out}?=> ',,' {self.sol = False}; UNDERLINE : {self.out}?=> '__' {self.sol = False}; // STRIKE : {self.out}?=> '--' {self.sol = False}; OPEN_CODE : {self.out}?=> '{{{' { self.out = False; self.pre = True} ; CLOSE_CODE : {self.pre}?=> '}}}' { self.out = True; self.pre = False; self.sol = False }; // Macros CLOSE_MACRO_TAG_START : {self.out and self.macro > 0}?=> '< '<<' { self.macro += 1; self.out = False; self.mstart = True }; ENTITY_MACRO_TAG_END : {self.mstart and not self.mquote}?=> '/>>' { self.macro -= 1; self.out = True; self.mstart = False; self.sol = False }; INLINE_MACRO_TAG_END : {(self.mstart or self.mend) and not self.mquote}?=> '>>' { self.out = True; self.mstart = self.mend = False; self.sol = False }; MACRO_QUOTE : {(self.mstart or self.mend) and not self.mquote}?=> '"' { self.mquote = True }; MACRO_END_QUOTE : {(self.mstart or self.mend) and self.mquote}?=> '"' { self.mquote = False }; // TeX-ish syntax TEX_MACRO_START : {self.out}?=> '\\' {self.out = False; self.tstart = True}; TEX_MACRO_START_CONTENT: {self.tstart}?=> '{' { self.out = True; self.tstart = False; self.tmacro += 1 }; //TEX_MACRO_ARG_BREAK: {self.out and self.tmacro > 0}?=> '}{'; TEX_MACRO_END: {self.out and self.tmacro > 0}?=> '}' { self.tmacro -= 1 }; // Entities ESCAPE : '~' . {self.sol = False}; IMAGE_START : {self.out}?=> '{{' { self.out = False; self.img = True }; IMAGE_END : {self.img}?=> '}}' { self.out = True; self.img = False; self.sol = False }; LINK_START : {self.out}?=> '[[' { self.out = False; self.link = True }; LINK_END : {self.link}?=> ']]' { self.out = True; self.link = False; self.sol = False }; LINK_IMPLICIT_INFIX : {self.out}?=> '://' {self.sol = False}; LINK_PIPE : {self.link or self.img}?=> '|' { self.out = True; self.sol = False }; HRULE : {self.out and self.sol}?=> '----' ('-')* {self.sol = False}; LINEBREAK : {self.out}?=> '\\\\' {self.sol = False}; PARABREAK : {self.out}?=> TEXTNL (TEXTNL)+ {self.sol = True}; NL : TEXTNL {self.sol = True}; // TeX/Special Punct EM_DASH : {self.out}?=> '---' {self.sol = False}; EN_DASH : {self.out}?=> '--' {self.sol = False}; OPEN_QUOTE : {self.out}?=> '``' {self.sol = False}; CLOSE_QUOTE : {self.out}?=> '\'\'' {self.sol = False}; OPEN_SINGLE_QUOTE : {self.out}?=> '`' {self.sol = False}; CLOSE_SINGLE_QUOTE : {self.out}?=> '\'' {self.sol = False}; ELLIPSIS : {self.out}?=> '...' {self.sol = False}; DOUBLE_BOTH : {self.out}?=> '<=>' {self.sol = False}; SINGLE_BOTH : {self.out}?=> '<->' {self.sol = False}; DOUBLE_RIGHT : {self.out}?=> '=>' {self.sol = False}; SINGLE_RIGHT : {self.out}?=> '->' {self.sol = False}; DOUBLE_LEFT : {self.out}?=> '<=' {self.sol = False}; SINGLE_LEFT : {self.out}?=> '<-' {self.sol = False}; // Literals SP : (TEXTSPACE)+ ; TEXT : (TEXTCHAR)+ {self.sol = False}; PUNCT : TEXTPUNCT {self.sol = False}; // Fragments fragment URLCHAR : URLENDCHAR | '@' | '%' | ';' | '?' | '&' | '=' | '+' | '~' ; fragment URLENDCHAR : NAMECHAR | '/' | '$'; fragment NAMECHAR : LETTER | DIGIT | '.' | '-' | '_' | ':' ; fragment DIGIT : '0'..'9' ; fragment LETTER : 'a'..'z' | 'A'..'Z' ; fragment TEXTCHAR : (~ ('~' | TEXTPUNCT | TEXTSPACE | TEXTNL)) ; fragment TEXTSPACE : ( ' ' | '\t' ) ; fragment TEXTNL : ('\n') ; fragment TEXTPUNCT : ( '*' | '/' | '{' | '}' | '#' | '=' | ':' | '<' | '>' | '^' | ',' | '_' | '-' | '[' | ']' | '|' | '\\' | '`' | '.' | '"' | '\'' ) ;