X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Ftibdoc.g;h=7841855bf13bbbafab769f6ab9b70341fca04f1e;hp=4a57992c91a84656583c074375a770fd63d62975;hb=45d799349e635f1a99e3974e4504a43d5a7aaf33;hpb=95c87aa402977de2b96c48bd14c439b46ad49777 diff --git a/tests/tibdoc.g b/tests/tibdoc.g index 4a57992..7841855 100644 --- a/tests/tibdoc.g +++ b/tests/tibdoc.g @@ -19,10 +19,7 @@ // [1] http://... // -// consider ++bold++ and **italic**? -// \br // nonbreaking text? -// ellipsis detection (...) // degree: 15^o // Arrows: <- -> => <= <-> @@ -39,7 +36,6 @@ // #include // simple macros (#define) (\define) -// today's date // table representation // @@ -58,11 +54,11 @@ nw = ~[\r\n\ ] ////////////////////////////////////////////////////////////////////////////// -s = top:: Doc +s = Doc -Doc = doc:: {Header} Body /ws -Header = header:: "header" { kv */ ws } /ws -Body = body:: Section*/ws +Doc = Doc:: head:{Header} body:Body /ws +Header = Header:: "header" attrs:{ kv */ ws } /ws +Body = sections:Section*/ws Section = { section:: SectionHeader Paragraph* /ws } SectionHeader = "==" SectionHeaderBody "==" SectionHeaderBody = "=" SectionHeaderBody "=" @@ -71,7 +67,7 @@ SectionHeaderBody = "=" SectionHeaderBody "=" sp = " "** blank = !sp "\n" !sp "\n" !ws -kv = kv1:: word "=" text /ws +kv = kv:: key:word "=" val:text /ws wp = w++ num = [0-9]++ Paragraph = blockquote:: { "\"\"" !ws text } @@ -81,25 +77,23 @@ Paragraph = blockquote:: { "\"\"" !ws text } onums = nums !(". "|") ") any = ~[]* -uli = li:: "* " (!ws text &~ any (oli|uli)) +uli = li:: "* " (!ws text &~ any (oli|uli)) oli = li:: ("# "|onums) (!ws text &~ any (oli|uli)) -// - -text = text:: Item +text = Item Itemx = !ws Item | () Item = blockquote > "[]":: { ul:: uli+/ws } Itemx | "[]":: { ol:: oli+/ws } Itemx > "[]":: pre Itemx + > "[]":: link Itemx > "[]":: structured Itemx - > "[]":: structuredx Itemx > "[]":: styled Itemx + > "[]":: (Chars:: alphanum++) Itemx > "[]":: qtext Itemx - > "[]":: (stringify:: alphanum++) Itemx > "[]":: symbol Itemx - > "[]":: (stringify:: sym++) Itemx + > "[]":: (Symbol:: sym++) Itemx > "[]":: Paragraph Itemx blockquote = blockquote:: "\"\"" text "\"\"" @@ -108,31 +102,32 @@ blockquote = blockquote:: "\"\"" text "\"\"" qtext = quoted:: "\"" text "\"" pre = verbatim:: "[verbatim]" { ~[]+ } /ws // FIXME doesn't work -styled = underline:: "__" text "__" - | footnote:: "((" text "))" - | ( tt:: "[[" text "]]" - | citation:: "[" text "]" - ) +styled = underline:: "__" text "__" + | footnote:: "((" text "))" + | tt:: "[[" text "]]" + | citation:: "[" word "]" | strikethrough:: "!!" text "!!" - | superscript:: "^^" (word|block) - | subscript:: ",," (word|block) - | smallcap:: "\\sc" block - | bold:: "**" text "**" - | keyword:: "!" (word|block) - > it:: "*" text "*" + | superscript:: "^^" (word|block) + | subscript:: ",," (word|block) + | smallcap:: "\\sc" block + | bold:: "++" text "++" + | keyword:: "!" (word|block) + | Italic:: "**" text "**" -// +block = { text } + +link = link:: text:({ text }) "->" href:(url|email) + > link:: text:alphanum++ !ws "->" href:(url|email) -block = { text } -structured = link:: { text } "->" (url|email) - //> alphanum++ "->" (url|email) => link -structuredx = glyph +structured = command & "\\" [a-zA-Z0-9]++ block? + > glyph > email > url -glyph = "(r)" | "(c)" | "(tm)" | "--" // euro symbol? - | today:: "\\today" -> ~[a-z] +glyph = euro:: "(e)" | "(r)" | "(c)" | "(tm)" | "--" | "..." +command = today:: "\\today" + | bre:: "\\br" // URLs ////////////////////////////////////////////////////////////////////////////// @@ -141,29 +136,31 @@ glyph = "(r)" | "(c)" | "(tm)" | "--" // euro symbol? // only gets parsed once urlpath = urlchar* -username = stringify:: [a-zA-Z0-9;/?:&=$\-_.+]++ -password = stringify:: [a-zA-Z0-9;/?:&=$\-_.+]++ -urlchar = [a-zA-Z0-9;/?:&=$\-_.+@] +username = [a-zA-Z0-9;/?:&=$\-_.+]++ +password = [a-zA-Z0-9;/?:&=$\-_.+]++ +urlc = [a-zA-Z0-9;/?:&=$\-_.+@] +urlv = urlc | [%] +urlchar = urlc | "%":: "%" [0-9] [0-9] -url = "mailto" ":" email - > url:: method "://" url_login? host (":" nums)? ("/" urlpath)? +url = "mailto" ":" email -> ~urlv + > method:method "://" url_login? host:host port:(":" nums)? path:("/" urlpath)? -> ~urlv url_login = login:: username (":" password) "@" -method = stringify:: [+\-.a-z0-9]+ -domain = domain:: (part +/ ".") -> ~"." -part = stringify:: [a-zA-Z0-9\-]++ +method = [+\-.a-z0-9]+ +domain = (part +/ ".") -> ~"." +part = [a-zA-Z0-9\-]++ // interesting use of boolean grammars // &~ ([\-0-9] ~[]* | ~[]* [\-0-9]) -email = emailaddr:: username "@" host -> ~[.] -nums = stringify:: [0-9]++ -host = ip:: nums "." nums "." nums "." nums - | domain +email = user:username "@" host:host -> ~[.] +nums = [0-9]++ +host = IP:: nums "." nums "." nums "." nums + | DNS:: domain // Tokens /////////////////////////////////////////////////////////////////// -word = stringify:: alphanum++ +word = alphanum++ | quoted quoted = "\"" ((~[\"\\] | escaped)+) "\""