Skip to content

Commit 8082d54

Browse files
committed
Apply manual syntax highlighting to EBNF in docstr
To me it seems like a bit of fun to add semantic highlighting to the EBNF in the docstring. It's not like we're going to get actual EBNF highlighting in Julia soon.
1 parent 527a985 commit 8082d54

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

src/styledmarkup.jl

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -917,33 +917,33 @@ the {link={https://en.wikipedia.org/wiki/Laziness}:lazy} dog"
917917
918918
This macro can be described by the following EBNF grammar:
919919
920-
```ebnf
921-
styledstring = { styled | interpolated | escaped | plain } ;
920+
```styled
921+
{julia_identifier:styledstring} {julia_assignment:=} {julia_type:\\{} styled {julia_operator:|} interpolated {julia_operator:|} escaped {julia_operator:|} plain {julia_type:\\}} {julia_comment:;}
922922
923-
specialchar = '{' | '}' | '\$' | '\\\"' ;
924-
anychar = [\\u0-\\u1fffff] ;
925-
plain = { anychar - specialchar } ;
926-
escaped = '\\\\', specialchar ;
923+
{julia_identifier:specialchar} {julia_assignment:=} {julia_string:'\\{'} {julia_operator:|} {julia_string:'\\}'} {julia_operator:|} {julia_string:'\$'} {julia_operator:|} {julia_string:'\\\"'} {julia_comment:;}
924+
{julia_identifier:anychar} {julia_assignment:=} [{julia_char:\\u0{julia_operator:-}\\u1fffff}] {julia_comment:;}
925+
{julia_identifier:plain} {julia_assignment:=} {julia_type:\\{} anychar {julia_operator:-} specialchar {julia_type:\\}} {julia_comment:;}
926+
{julia_identifier:escaped} {julia_assignment:=} {julia_string:'\\\\'}{light:,} specialchar {julia_comment:;}
927927
928-
interpolated = '\$', ? expr ? | '\$(', ? expr ?, ')' ;
928+
{julia_identifier:interpolated} {julia_assignment:=} {julia_string:'\$'}{light:,} {julia_macro:? expr ?} {julia_operator:|} {julia_string:'\$('}{light:,} {julia_macro:? expr ?}{light:,} {julia_string:')'} {julia_comment:;}
929929
930-
styled = '{', ws, annotations, ':', content, '}' ;
931-
content = { interpolated | plain | escaped | styled } ;
932-
annotations = annotation | annotations, ws, ',', ws, annotation ;
933-
annotation = face | inlineface | keyvalue ;
934-
ws = { ' ' | '\\t' | '\\n' } ; (* whitespace *)
930+
{julia_identifier:styled} {julia_assignment:=} {julia_string:'\\{'}{light:,} ws{light:,} annotations{light:,} {julia_string:':'}{light:,} content{light:,} {julia_string:'\\}'} {julia_comment:;}
931+
{julia_identifier:content} {julia_assignment:=} {julia_type:\\{} interpolated {julia_operator:|} plain {julia_operator:|} escaped {julia_operator:|} styled {julia_type:\\}} {julia_comment:;}
932+
{julia_identifier:annotations} {julia_assignment:=} annotation {julia_operator:|} annotations{light:,} ws{light:,} {julia_string:','}{light:,} ws{light:,} annotation {julia_comment:;}
933+
{julia_identifier:annotation} {julia_assignment:=} face {julia_operator:|} inlineface {julia_operator:|} keyvalue {julia_comment:;}
934+
{julia_identifier:ws} {julia_assignment:=} {julia_type:\\{} {julia_string:' '} {julia_operator:|} {julia_string:'\\t'} {julia_operator:|} {julia_string:'\\n'} {julia_type:\\}} {julia_comment:; (* whitespace *)}
935935
936-
face = facename | interpolated ;
937-
facename = [A-Za-z0-9_]+ ;
936+
{julia_identifier:face} {julia_assignment:=} facename {julia_operator:|} interpolated {julia_comment:;}
937+
{julia_identifier:facename} {julia_assignment:=} [{julia_char:A{julia_operator:-}Za{julia_operator:-}z0{julia_operator:-}9_}]{julia_operator:+} {julia_comment:;}
938938
939-
inlineface = '(', ws, [ faceprop ], { ws, ',', faceprop }, ws, ')' ;
940-
faceprop = [a-z]+, ws, '=', ws, ( [^,)]+ | interpolated) ;
939+
{julia_identifier:inlineface} {julia_assignment:=} {julia_string:'('}{light:,} ws{light:,} {julia_type:[} faceprop {julia_type:]}{light:,} {julia_type:\\{} ws{light:,} {julia_string:','}{light:,} faceprop {julia_type:\\}}{light:,} ws{light:,} {julia_string:')'} {julia_comment:;}
940+
{julia_identifier:faceprop} {julia_assignment:=} [{julia_char:a{julia_operator:-}z}]{julia_operator:+}{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} [{julia_operator:^}{julia_char:,)}]{julia_operator:+} {julia_operator:|} interpolated {julia_type:)} {julia_comment:;}
941941
942-
keyvalue = key, ws, '=', ws, value ;
943-
key = ( [^\\0\${}=,:], [^\\0=,:]* ) | interpolated ;
944-
value = simplevalue | curlybraced | interpolated ;
945-
curlybraced = '{' { escaped | plain } '}' ;
946-
simplevalue = [^\${},:], [^,:]* ;
942+
{julia_identifier:keyvalue} {julia_assignment:=} key{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} value {julia_comment:;}
943+
{julia_identifier:key} {julia_assignment:=} {julia_type:(} [{julia_operator:^}{julia_char:\\0\$\\{\\}=,:}]{light:,} [{julia_operator:^}{julia_char:\\0=,:}]{julia_operator:*} {julia_type:)} {julia_operator:|} interpolated {julia_comment:;}
944+
{julia_identifier:value} {julia_assignment:=} simplevalue {julia_operator:|} curlybraced {julia_operator:|} interpolated {julia_comment:;}
945+
{julia_identifier:curlybraced} {julia_assignment:=} {julia_string:'\\{'} {julia_type:\\{} escaped {julia_operator:|} plain {julia_type:\\}} {julia_string:'\\}'} {julia_comment:;}
946+
{julia_identifier:simplevalue} {julia_assignment:=} [{julia_operator:^}{julia_char:\$\\{\\},:}]{light:,} [{julia_operator:^}{julia_char:,:}]{julia_operator:*} {julia_comment:;}
947947
```
948948
949949
An extra stipulation not encoded in the above grammar is that `plain` should be
@@ -952,30 +952,30 @@ a valid input to [`unescape_string`](@ref), with `specialchar` kept.
952952
The above grammar for `inlineface` is simplified, as the actual implementation
953953
is a bit more sophisticated. The full behaviour is given below.
954954
955-
```ebnf
956-
faceprop = ( 'face', ws, '=', ws, ( ? string ? | interpolated ) ) |
957-
( 'height', ws, '=', ws, ( ? number ? | interpolated ) ) |
958-
( 'weight', ws, '=', ws, ( symbol | interpolated ) ) |
959-
( 'slant', ws, '=', ws, ( symbol | interpolated ) ) |
960-
( ( 'foreground' | 'fg' | 'background' | 'bg' ),
961-
ws, '=', ws, ( simplecolor | interpolated ) ) |
962-
( 'underline', ws, '=', ws, ( underline | interpolated ) ) |
963-
( 'strikethrough', ws, '=', ws, ( bool | interpolated ) ) |
964-
( 'inverse', ws, '=', ws, ( bool | interpolated ) ) |
965-
( 'inherit', ws, '=', ws, ( inherit | interpolated ) ) ;
966-
967-
nothing = 'nothing' ;
968-
bool = 'true' | 'false' ;
969-
symbol = [^ ,)]+ ;
970-
hexcolor = ('#' | '0x'), [0-9a-f]{6} ;
971-
simplecolor = hexcolor | symbol | nothing ;
972-
973-
underline = nothing | bool | simplecolor | underlinestyled;
974-
underlinestyled = '(', ws, ('' | nothing | simplecolor | interpolated), ws,
975-
',', ws, ( symbol | interpolated ), ws ')' ;
976-
977-
inherit = ( '[', inheritval, { ',', inheritval }, ']' ) | inheritval;
978-
inheritval = ws, ':'?, symbol ;
955+
```styled
956+
{julia_identifier:faceprop} {julia_assignment:=} {julia_type:(} {julia_string:'face'}{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} {julia_macro:? string ?} {julia_operator:|} interpolated {julia_type:)} {julia_type:)} {julia_operator:|}
957+
{julia_type:(} {julia_string:'height'}{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} {julia_macro:? number ?} {julia_operator:|} interpolated {julia_type:)} {julia_type:)} {julia_operator:|}
958+
{julia_type:(} {julia_string:'weight'}{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} symbol {julia_operator:|} interpolated {julia_type:)} {julia_type:)} {julia_operator:|}
959+
{julia_type:(} {julia_string:'slant'}{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} symbol {julia_operator:|} interpolated {julia_type:)} {julia_type:)} {julia_operator:|}
960+
{julia_type:(} {julia_type:(} {julia_string:'foreground'} {julia_operator:|} {julia_string:'fg'} {julia_operator:|} {julia_string:'background'} {julia_operator:|} {julia_string:'bg'} {julia_type:)},
961+
ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} simplecolor {julia_operator:|} interpolated {julia_type:)} {julia_type:)} {julia_operator:|}
962+
{julia_type:(} {julia_string:'underline'}{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} underline {julia_operator:|} interpolated {julia_type:)} {julia_type:)} {julia_operator:|}
963+
{julia_type:(} {julia_string:'strikethrough'}{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} bool {julia_operator:|} interpolated {julia_type:)} {julia_type:)} {julia_operator:|}
964+
{julia_type:(} {julia_string:'inverse'}{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} bool {julia_operator:|} interpolated {julia_type:)} {julia_type:)} {julia_operator:|}
965+
{julia_type:(} {julia_string:'inherit'}{light:,} ws{light:,} {julia_string:'='}{light:,} ws{light:,} {julia_type:(} inherit {julia_operator:|} interpolated {julia_type:)} {julia_type:)} {julia_comment:;}
966+
967+
{julia_identifier:nothing} {julia_assignment:=} {julia_string:'nothing'} {julia_comment:;}
968+
{julia_identifier:bool} {julia_assignment:=} {julia_string:'true'} {julia_operator:|} {julia_string:'false'} {julia_comment:;}
969+
{julia_identifier:symbol} {julia_assignment:=} [{julia_operator:^}{julia_char: ,)}]{julia_operator:+} {julia_comment:;}
970+
{julia_identifier:hexcolor} {julia_assignment:=} {julia_type:(} {julia_string:'#'} {julia_operator:|} {julia_string:'0x'} {julia_type:)}{light:,} [{julia_char:0{julia_operator:-}9a{julia_operator:-}f}]{6} {julia_comment:;}
971+
{julia_identifier:simplecolor} {julia_assignment:=} hexcolor {julia_operator:|} symbol {julia_operator:|} nothing {julia_comment:;}
972+
973+
{julia_identifier:underline} {julia_assignment:=} nothing {julia_operator:|} bool {julia_operator:|} simplecolor {julia_operator:|} underlinestyled {julia_comment:;}
974+
{julia_identifier:underlinestyled} {julia_assignment:=} {julia_string:'('}{light:,} ws{light:,} {julia_type:(} {julia_string:''} {julia_operator:|} nothing {julia_operator:|} simplecolor {julia_operator:|} interpolated {julia_type:)}{light:,} ws,
975+
{julia_string:','}{light:,} ws{light:,} {julia_type:(} symbol {julia_operator:|} interpolated {julia_type:)}{light:,} ws {julia_string:')'} {julia_comment:;}
976+
977+
{julia_identifier:inherit} {julia_assignment:=} {julia_type:(} {julia_string:'['}{light:,} inheritval{light:,} {julia_type:\\{} {julia_string:','}{light:,} inheritval {julia_type:\\}}{light:,} {julia_string:']'} {julia_type:)} {julia_operator:|} inheritval {julia_comment:;}
978+
{julia_identifier:inheritval} {julia_assignment:=} ws{light:,} {julia_string:':'}{julia_operator:?}{light:,} symbol {julia_comment:;}
979979
```
980980
"""
981981
macro styled_str(raw_content::String)

0 commit comments

Comments
 (0)