Presentation is loading. Please wait.

Presentation is loading. Please wait.

Xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 401 xsugar Dual Syntax for XML Languages Claus Brabrand Anders Møller Michael Schwartzbach.

Similar presentations


Presentation on theme: "Xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 401 xsugar Dual Syntax for XML Languages Claus Brabrand Anders Møller Michael Schwartzbach."— Presentation transcript:

1 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 401 xsugar Dual Syntax for XML Languages Claus Brabrand Anders Møller Michael Schwartzbach {brabrand,amoeller,mis}@brics.dk BRICS, Department of Computer Science University of Aarhus, Denmark

2 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 402 // Abstract “xsugar: Reversible Stylesheets” XSLT stylesheets may be used to provide an alternative and more legible syntax for XML documents. However, such transformations are not reversible since no tool exists to automatically parse the alternative syntax back into XML. We present xsugar, which is a reversible stylesheet language for XML. An xsugar specification is built around a context-free grammar for the alternative syntax and gives a template-based translation into XML. The xsugar tool can then provide three services: 1) a static guarantee that all XML documents generated from alternative syntax are valid according to a given XML schema; 2) a translation from alternative syntax into XML; and 3) a reverse translation from XML into alternative syntax (provided certain injectivity requirements are satisfied). The well-formedness of both translations are statically checked. Thus, xsugar is useful for providing an XML syntax for an existing language or for providing an alternative syntax for an existing XML language. This is joint on-going work with Anders Møller and Michael I. Schwartzbach. XSLT stylesheets may be used to provide an alternative and more legible syntax for XML documents. However, such transformations are not reversible since no tool exists to automatically parse the alternative syntax back into XML. We present xsugar, which is a reversible stylesheet language for XML. An xsugar specification is built around a context-free grammar for the alternative syntax and gives a template-based translation into XML. The xsugar tool can then provide three services: 1) a static guarantee that all XML documents generated from alternative syntax are valid according to a given XML schema; 2) a translation from alternative syntax into XML; and 3) a reverse translation from XML into alternative syntax (provided certain injectivity requirements are satisfied). The well-formedness of both translations are statically checked. Thus, xsugar is useful for providing an XML syntax for an existing language or for providing an alternative syntax for an existing XML language. This is joint on-going work with Anders Møller and Michael I. Schwartzbach.

3 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 403 // Outline (3 parts) Introduction xsugar Syntax and Semantics Unifying Syntax Tree Validation Analysis DTDs & Summary Graphs Schema Languages Reversibility Analysis Info Preservation Unambiguity Teleportation More Examples Related & Future Work Assessment Conclusion Introduction (xsugar) Static Analyses Assessment 1 2 3

4 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 404 Validation Analysis DTDs & Summary Graphs Schema Languages // Part 1: Introduction Introduction xsugar Syntax and Semantics Unifying Syntax Tree Reversibility Analysis Info Preservation Unambiguity Teleportation More Examples Related & Future Work Assessment Conclusion Introduction (xsugar) Static Analyses Assessment 1 2 3

5 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 405 Relax NG: // Motivation Relax RNGRelax RNC correspondence ? maintenance ? reversibility ? validity (XML) ? termination ? RNC-to-RNG: Python script (1,478 lines) RNG-to-RNC: XSLT stylesheet (894 lines) Dynamic issues :

6 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 406 XQuery: // Motivation (cont’d) XQueryXXQuery correspondence ? maintenance ? reversibility ? validity (XML) ? termination ? XQuery-to-XQueryX: Non-existent...! XQueryX-to-XQuery: XSLT stylesheet (845 lines) Dynamic issues :

7 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 407 One stylesheet produces: // xsugar XL correspondence ! maintenance ! reversibility ! validity (XML) ! termination ! Static guarantees: L2X: Transformation: L  X X2L: Reverse transformation: X  L xsugar s : L  X

8 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 408 // Example: Transformation… Claus Brabrand brabrand@brics.dk Claus Brabrand (brabrand@brics.dk) 19920539 Name = {... } Email = {... } Id = { [0-9]+ } student : [Name n] ( [Email e] ) [Id id] \n = { } [Name n][Email e][Id id] s: L  X parsing unparsing parsing unparsing transformation x: l :

9 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 409 // …and Reverse Transformation Claus Brabrand brabrand@brics.dk Claus Brabrand (brabrand@brics.dk) 19920539 Name = {... } Email = {... } Id = { [0-9]+ } student : [Name n] ( [Email e] ) [Id id] \n = { } s: L  X unparsing parsing unparsing parsing reverse transformation x: l : [Id id][Name n][Email e]

10 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4010 Nfinite set of unifying nonterminals  finite alphabet of terminals s  Nstart unifying nonterminal Ufinite set of unification names  : N  P(E*  E*),unifying production function, E = (N  U)   // Unifying Grammar student : [Name n] ( [Email e] ) [Id id] \n = { } G =  N, , s, U,   unification: 2 right-hand sides

11 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4011 // Regular Nonterminal Shorthand Regular expressions (convenient short-hand) for regular nonterminals (w/ identity unification): student : [Name n] ( [Email e] ) [Id id] \n = { } Id = { [0-9]+ } id : [num n] [id i] = { } : [num n] = { } num : 0 = { 0 } … : 9 = { 9 } desugaring

12 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4012 // (A)symmetric Unification Unification is symmetric: Grammar for both L and X However ( XML-induced asymmetry ): X (XML) contains lots of structure  typically impervious to grammatical structure Thus, one can “think of G as grammar for L” Asymmetry reflected syntactically:  : N  P(E*  E*) unification: 2 right-hand sides student : [Name n] ( [Email e] ) [Id id] \n = { }

13 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4013 // Syntactic Constituents (L) L:L: ConstructionName UST foo token [] [N a] nonterminal [a  ] [N] ignoreable [] Name = { [^(\n]+ } Email = { [^,) ]+ } Id = { [0-9]+ } student : [Name n] ( [Email e] ) [Id id] \n = { }

14 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4014 // Syntactic Constituents (X) X:X: ConstructionName UST ‘ ’ (XML) whitespace [] foo text (“PC data”) [] … element (w/ attributes) … gap [a  ] …</… attribute gap Name = { [^(\n]+ } Email = { [^,) ]+ } Id = { [0-9]+ } student : [Name n] ( [Email e] ) [Id id] \n = { }

15 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4015 AST L (ordered tree): AST X (partially ordered): // AST L and AST X [id] 19920539 [n] Claus Brabrand student prod: #1 student prod #1 [e] brabrand@brics.dk student : [Name n] ( [Email e] ) [Id id] \n = { } [e] brabrand@brics.dk [n] Claus Brabrand Attr [id] 19920539 [] [ ] } {,,,

16 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4016 Unifying Syntax Tree (UST) UST (L/X) (unordered tree): // UST (“Unifying Syntax Tree”) student : [Name n] ( [Email e] ) [Id id] \n = { } [n] Claus Brabrand student prod: #1 [e] brabrand@brics.dk [id] 19920539 {},,

17 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4017 Reversible ? (i.e.  ): Parsing / Unparsing (i.e.  ): Grammar Ambiguity ? Transformation (i.e.  ): Information Preservation ? // “The Big Picture” UST AST L / ~ L AST X / ~ XML... transformation LX L  X Ordered tree Unordered tree Partially Ordered Legend: Canonical: l  L Canonical: x  X 1-1 un-/parsing transformation un-/parsing 1-1/~ L ? 1-1/~ XML ? 1-1?. 1-1.....

18 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4018 Validation Analysis DTDs & Summary Graphs Schema Languages // Part 1: Introduction Introduction xsugar Syntax and Semantics Unifying Syntax Tree Reversibility Analysis Info Preservation Unambiguity Teleportation More Examples Related & Future Work Assessment Conclusion Introduction (xsugar) Static Analyses Assessment 1 2 3

19 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4019 // Part 2: Static Analyses Introduction xsugar Syntax and Semantics Unifying Syntax Tree Validation Analysis DTDs & Summary Graphs Schema Languages Reversibility Analysis Grammar Unambiguity Information Preservation Teleportation More Examples Related & Future Work Assessment Conclusion Introduction (xsugar) Static Analyses Assessment 1 2 3

20 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4020 // Motivating Example (Ex. cont’d) Anders Moeller amoeller@brics.dk sugardaddy@hotmail.com Anders Moeller (amoeller@brics.dk,sugardaddy@hotmail.com) 19940392 Name = { [^(\n]+ } Email = { [^,) ]+ } Id = { [0-9]+ } student : [Name n] ( [emails es] ) [Id id] \n = { } emails : [Email e] = { } : [Email e], [emails es] = { } 

21 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4021 // Motivating Example (cont’d 2 ) Name = { [^(\n]+ } Email = { [^,) ]+ } Id = { [0-9]+ } student : [Name n] [opt_emails e] [Id id] \n = { } opt_emails : = {} : ( [email e] ) = { } : ( [email e], [emails es] ) = { } emails : [email e] = { } : [email e], [emails es] = { } email : [Email e] = { } // -- sequence of students ----- start : [students ss] = { } students : [student s] = { } : [student s] [students ss] = { }

22 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4022 // Example (cont’d) Claus Brabrand brabrand@brics.dk Anders Moeller amoeller@brics.dk sugardaddy@hotmail.com Michael Schwartzbach 1879139 Claus Brabrand (brabrand@brics.dk) 19920539 Anders Moeller (amoeller@brics.dk,sugardaddy@hotmail.com) 19940392 Michael Schwartzbach 18791398

23 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4023 // Example (cont’d) Claus Brabrand brabrand@brics.dk Anders Moeller amoeller@brics.dk sugardaddy@hotmail.com Michael Schwartzbach 1879139 Claus Brabrand (brabrand@brics.dk) 19920539 Anders Moeller (amoeller@brics.dk,sugardaddy@hotmail.com) 19940392 Michael Schwartzbach 18791398 Ambiguous grammar !

24 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4024 Unparsing: [N]  representative induces: ~ L (equiv. rel.) “only different wrt. [N]” // Reversibility: Un-/Parsing AST L / ~ L. L.  Parsing: Grammar ambiguity ? Undecidable! However… AST L / ~ L. L. .

25 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4025 // Approximating CFG Ambiguity Undecidable ?: However…!: : Safe (over-)approximation: G unambiguous, if: G horizontally unambiguous: G vertically unambiguous: unambiguous ambiguous Yes!. No?.. unambiguous ambiguous ? G G Grammar-level error messages (over-)approximation Black-box

26 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4026 // Horizontal Ambiguity Horizontal ambiguity (L): Horizontal ambiguity (X): n : [Id i1] [Id i2] = { : } abxy <= ab:xy  m : [Id i1] “:” [Id i2] = { } L abxy => abx:y ab:xy => abxy  abx:y <= abxy X  

27 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4027 // Vertical Ambiguity Vertical ambiguity (L): Vertical ambiguity (X): n : x [Id i] = { ! } : xx [Id i] = { !! } xxy <= !xy  m : ! [Id i] = { x } : !! [Id i] = { xx } X xxy => !!y !xy => xxy  !!y <= xxy L  

28 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4028 // Information Preservation “Never throw away or duplicate information”: i.e. all named arguments must be used exactly once! UST AST L / ~ L.. L  X UST AST L / ~ L.. L  X

29 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4029 // Information Preservation Information preservation (L): Information preservation (X): m : bar = { } foo (abc) => foo (???) n : foo ( [Id i] ) = { } bar abc bar => ???   X L

30 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4030 // Reversible Stylesheets! AST L / ~ L AST X / ~ XML... LX L  X xsugar: 1-1 ! 1-1 ! un-/parsing transformation 1-1 ! transformation 1-1 ! un-/parsing  xsugar 1-1 ! Reversibility (proof): Assume: L X LX s s ss L s X s...

31 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4031 Given DTD, D : // Validation Analysis  l  L : x(l)  L (D) L (X)  L (D)   SG(X)  L (D) Black-box “Static Validation of Dynamically Generated HTML” [ Claus Brabrand | Anders Møller | Michael Schwartzbach ] PASTE, 2001

32 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4032 Id = { [0-9]+ } Name = { [^(\n]+ } Email = { [^,) ]+ } student : [Name n] ( [emails es] ) [Id id] \n = { } emails : [Email e] = { } : [Email e], [emails es] = { } // Summary Graphs [0-9]+ [^(\n]+ [^,) ]+ SG(X)  L (D) Black-box “Static Validation of Dynamically Generated HTML” [ Claus Brabrand | Anders Møller | Michael Schwartzbach ] PASTE, 2001

33 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4033 // Part 2: Static Analyses Introduction xsugar Syntax and Semantics Unifying Syntax Tree Validation Analysis DTDs & Summary Graphs Schema Languages Reversibility Analysis Grammar Unambiguity Information Preservation Teleportation More Examples Related & Future Work Assessment Conclusion Introduction (xsugar) Static Analyses Assessment 1 2 3

34 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4034 Validation Analysis DTDs & Summary Graphs Schema Languages // Part 3: Assessment Introduction xsugar Syntax and Semantics Unifying Syntax Tree Reversibility Analysis Info Preservation Unambiguity Teleportation More Examples Related & Future Work Assessment Conclusion Introduction (xsugar) Static Analyses Assessment 1 2 3

35 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4035 // Teleportation ( non-local xformat° ) Int = { [0-9]+ } Str = { “\”” [^\“]+ “\”” } start : [list l] = { } list : [Int n] [list l] = { } : [Str s] = {} } abc 87 42 l start l l { { { { } } } } abc 87 42 l start l l { { { } },,,,, abc 1-1

36 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4036 // FW: Teleportation (cont’d) Reversibility?: UST AST L / ~ L AST X / ~ XML... transformation LX L  X un-/parsing transformation un-/parsing 1-1/~ L ! 1-1/~ XML ! 1-1! teleportation Int = { [0-9]+ } Str = { “\”” [^\“]+ “\”” } start : [list l] = { } list : [Int n] [list l] = { } : [Str s] = {}

37 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4037 // Related Work “XSLT” (aka. XSL Stylesheets): However, only one direction “Presenting XML”: “Java web application framework for presenting HTML, PDF, WML etc., in a device independent manner”. “It aims to achieve a complete separation of content and presentation”. Relax RNGRelax RNC P2P2 P1P1

38 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4038 For “Relax NG”: // Assessment lines Conciseness: [ 1 / 12+ ] correspondence ? vs ! maintenance ? vs ! reversibility ? vs ! validity (XML) ? vs ! termination ? vs ! Static guarantees:

39 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4039 xsugar: Reversible Stylesheets // Conclusion XL correspondence ! maintenance ! reversibility ! validity (XML) ! termination ! Static guarantees: L2X: Stylesheet: L  X X2L: Reverse stylesheet: X  L xsugar s : L  X

40 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4040 Questions please… /

41 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4041 // Schema Languages The xsugar Schema Language ® : Generalization (from Regexps to CFGs): Full CFG structure for PCDATA Full CFG structure for attribute values x  L (X) ?

42 xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 4042 // More Examples: “ Nice.xsg ” a xx yyy b n : a [xs x_s] [ys y_s] b = { } xs : = {} : x [xs x_s] = { } // X: sequence ys : = {} : y [ys y_s] = { } // Y: nested 


Download ppt "Xsugar: Dual Syntax for XML LanguagesTōkyō Daigaku [ July 15, 2005 ] / 401 xsugar Dual Syntax for XML Languages Claus Brabrand Anders Møller Michael Schwartzbach."

Similar presentations


Ads by Google