checkpoint
[sbp.git] / tests / tibdoc.g
index 4a57992..7841855 100644 (file)
 //   [1] http://...
 //
 
 //   [1] http://...
 //
 
-// consider ++bold++ and **italic**?
-// \br
 // nonbreaking text?
 // nonbreaking text?
-// ellipsis detection (...)
 // degree: 15^o
 // Arrows: <- -> => <= <->
 
 // degree: 15^o
 // Arrows: <- -> => <= <->
 
@@ -39,7 +36,6 @@
 // #include
 
 // simple macros (#define) (\define)
 // #include
 
 // simple macros (#define) (\define)
-// today's date
 
 // table representation
 //  
 
 // 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 "="
 Section             = { section:: SectionHeader Paragraph* /ws }
 SectionHeader       = "==" SectionHeaderBody "=="
 SectionHeaderBody   =  "=" SectionHeaderBody "="
@@ -71,7 +67,7 @@ SectionHeaderBody   =  "=" SectionHeaderBody "="
 sp       = " "**
 blank    = !sp "\n" !sp "\n" !ws
 
 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 }
 wp           = w++
 num          = [0-9]++
 Paragraph    = blockquote:: { "\"\"" !ws  text }
@@ -81,25 +77,23 @@ Paragraph    = blockquote:: { "\"\"" !ws  text }
 onums        = nums !(". "|") ")
 any          = ~[]*
 
 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))
 
 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
 Itemx        = !ws Item
              | ()
 Item         = blockquote
              > "[]":: { ul:: uli+/ws }          Itemx
              | "[]":: { ol:: oli+/ws }          Itemx
              > "[]":: pre                       Itemx
+             > "[]":: link                      Itemx
              > "[]":: structured                Itemx
              > "[]":: structured                Itemx
-             > "[]":: structuredx               Itemx
              > "[]":: styled                    Itemx
              > "[]":: styled                    Itemx
+             > "[]":: (Chars:: alphanum++)      Itemx
              > "[]":: qtext                     Itemx
              > "[]":: qtext                     Itemx
-             > "[]":: (stringify:: alphanum++)  Itemx
              > "[]":: symbol                    Itemx
              > "[]":: symbol                    Itemx
-             > "[]":: (stringify:: sym++)       Itemx
+             > "[]":: (Symbol:: sym++)          Itemx
              > "[]":: Paragraph                 Itemx
 
 blockquote   = blockquote:: "\"\"" text "\"\""
              > "[]":: Paragraph                 Itemx
 
 blockquote   = blockquote:: "\"\"" text "\"\""
@@ -108,31 +102,32 @@ blockquote   = blockquote:: "\"\"" text "\"\""
 qtext        = quoted:: "\"" text "\""
 pre          = verbatim:: "[verbatim]" { ~[]+ } /ws   // FIXME doesn't work
 
 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 "!!"      
              | 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
 
               > email
               > url
 
-glyph        = "(r)" | "(c)" | "(tm)" | "--"  // euro symbol?
-             | today:: "\\today" -> ~[a-z]
+glyph        = euro:: "(e)" | "(r)" | "(c)" | "(tm)" | "--" | "..."
 
 
+command      = today:: "\\today"
+             | bre::   "\\br"
 
 // URLs //////////////////////////////////////////////////////////////////////////////
 
 
 // URLs //////////////////////////////////////////////////////////////////////////////
 
@@ -141,29 +136,31 @@ glyph        = "(r)" | "(c)" | "(tm)" | "--"  // euro symbol?
 // only gets parsed once
 
 urlpath      = urlchar*
 // 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]
              | "%":: "%" [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) "@"
 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])
 
 // 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 ///////////////////////////////////////////////////////////////////
 
 
 
 
 // Tokens ///////////////////////////////////////////////////////////////////
 
-word       = stringify:: alphanum++
+word       = alphanum++
            | quoted
 
 quoted     = "\"" ((~[\"\\] | escaped)+) "\""
            | quoted
 
 quoted     = "\"" ((~[\"\\] | escaped)+) "\""