Create a gist now

Instantly share code, notes, and snippets.

@221V /bbcodeslex.xrl Secret
Created Jan 8, 2018

What would you like to do?
leex is crazyyyy ))
%% leex file structure
Definitions.
%W = [A-za-zА-Яа-я0-9]
%L = [A-za-zА-Яа-я0-9.]
%E = [.]
Rules.
\[code\].*?\[/code\] : {token, {code, TokenLen, TokenChars}}.
\[b\] : {token, {b, open}}.
\[/b\] : {token, {b, close}}.
\[i\] : {token, {i, open}}.
\[/i\] : {token, {i, close}}.
\[u\] : {token, {u, open}}.
\[/u\] : {token, {u, close}}.
\[s\] : {token, {s, open}}.
\[/s\] : {token, {s, close}}.
\[sub\] : {token, {sub, open}}.
\[/sub\] : {token, {sub, close}}.
\[sup\] : {token, {sup, open}}.
\[/sup\] : {token, {sup, close}}.
\[left\] : {token, {left, open}}.
\[/left\] : {token, {left, close}}.
\[center\] : {token, {center, open}}.
\[/center\] : {token, {center, close}}.
\[right\] : {token, {right, open}}.
\[/right\] : {token, {right, close}}.
\[justify\] : {token, {justify, open}}.
\[/justify\] : {token, {justify, close}}.
\[table\] : {token, {table, open}}.
\[/table\] : {token, {table, close}}.
\[tr\] : {token, {tr, open}}.
\[/tr\] : {token, {tr, close}}.
\[td\] : {token, {td, open}}.
\[/td\] : {token, {td, close}}.
\[hr\] : {token, {hr, open}}.
[\n] : {token, {br, open}}.
\[quote\] : {token, {quote, open}}.
\[/quote\] : {token, {quote, close}}.
\[rtl\] : {token, {rtl, open}}.
\[/rtl\] : {token, {rtl, close}}.
\[ltr\] : {token, {ltr, open}}.
\[/ltr\] : {token, {ltr, close}}.
\[ul\] : {token, {ul, open}}.
\[/ul\] : {token, {ul, close}}.
\[ol\] : {token, {ol, open}}.
\[/ol\] : {token, {ol, close}}.
\[li\] : {token, {li, open}}.
\[/li\] : {token, {li, close}}.
\[font=[A-Za-z\s\-]+?\] : {token, {font_open, TokenLen, TokenChars}}.
\[/font\] : {token, {font, close}}.
\[size=[0-9]+?\] : {token, {size_open, TokenLen, TokenChars}}.
\[/size\] : {token, {size, close}}.
\[color=#[0-9A-Fa-f]+?\] : {token, {color_open, TokenLen, TokenChars}}.
\[/color\] : {token, {color, close}}.
\[img[a-z0-9\s\=]+?\].+?\[/img\] : {token, {img, TokenLen, TokenChars}}.
\[img\] : {token, {img, open}}.
\[/img\] : {token, {img, close}}.
\[email=[A-Za-z0-9\@\.]+?\] : {token, {email_open, TokenLen, TokenChars}}.
\[/email\] : {token, {email, close}}.
\[url=[A-Za-z0-9\@\.\/\:\-\_]+?\].+?\[/url\] : {token, {url, TokenLen, TokenChars}}.
\[youtube\].+?\[/youtube\] : {token, {youtube, TokenLen, TokenChars}}.
:\) : {token, {smile, 1}}.
:angel: : {token, {smile, 2}}.
:angry: : {token, {smile, 3}}.
8-\) : {token, {smile, 4}}.
:'\( : {token, {smile, 5}}.
:ermm: : {token, {smile, 6}}.
:D : {token, {smile, 7}}.
<3 : {token, {smile, 8}}.
:\( : {token, {smile, 9}}.
:O : {token, {smile, 10}}.
:P : {token, {smile, 11}}.
;\) : {token, {smile, 12}}.
:alien: : {token, {smile, 13}}.
:blink: : {token, {smile, 14}}.
:blush: : {token, {smile, 15}}.
:cheerful: : {token, {smile, 16}}.
:devil: : {token, {smile, 17}}.
:dizzy: : {token, {smile, 18}}.
:getlost: : {token, {smile, 19}}.
:happy: : {token, {smile, 20}}.
:kissing: : {token, {smile, 21}}.
:ninja: : {token, {smile, 22}}.
:pinch: : {token, {smile, 23}}.
:pouty: : {token, {smile, 24}}.
:sick: : {token, {smile, 25}}.
:sideways: : {token, {smile, 26}}.
:silly: : {token, {smile, 27}}.
:sleeping: : {token, {smile, 28}}.
:unsure: : {token, {smile, 29}}.
:woot: : {token, {smile, 30}}.
:wassat: : {token, {smile, 31}}.
[\t]+ : {token, {any_text, TokenLen, TokenChars}}.
[\s]+ : {token, {any_text, TokenLen, TokenChars}}.
%{W}+ : {token, {any_text, TokenLen, TokenChars}}.
%{L}+ : {token, {any_text, TokenLen, TokenChars}}.
%{E}+ : {token, {any_text, TokenLen, TokenChars}}.
[^\[]+ : {token, {any_text, TokenLen, TokenChars}}.
[\\\[]+ : {token, {any_text, TokenLen, TokenChars}}.
[\\\]]+ : {token, {any_text, TokenLen, TokenChars}}.
Erlang code.
20> leex:file(bbcodeslex).
{ok,"./bbcodeslex.erl"}
21> c(bbcodeslex).
{ok,bbcodeslex}
22> bbcodeslex:string("test:ninja::Otest:alien:").
{ok,[{any_text,24,"test:ninja::Otest:alien:"}],1}

rvirding commented Jan 9, 2018

This was discussed and solved in the Elixir forum. The longest matching pattern wins and you any_test patterns basically match everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment