stripxml.modes

1 Synopsis

These modes reads an XML or DTD input file and separate comments (<!-- ... -->) from non-comments. The start and end comment tags are removed, whereas material outside comments is placed in pre [...] sections.

2 The code

!declare-prefix @prefix[strip] @uri[http://gloss.bham.ac.uk/mv/doc/stripxml] {

!init-parameter @name[strip:data] @value[]
!init-parameter @name[strip:method] @value[cdata]
!init-parameter @name[strip:indentation] @value[]
!init-parameter @name[strip:comment-found] @value[cdata]

!mode @name[strip:main] @accept[] @type[process] @use-indentation[false]
  !default 
    !process-tokens @mode[strip:main-$\{strip:method\}]
    !return

!mode @name[strip:main-pi] @accept[] @type[process] @use-indentation[false]
  !default
    !document-fragment @encoding[UTF-8]
      !processing-instruction @target[gloss]
        !text &#x0A;
        !process-tokens @mode[strip:process]

!mode @name[strip:main-comment] @accept[] @type[process] @use-indentation[false]
  !default
    !document-fragment @encoding[UTF-8]
      !comment
        !text &#x0A;
        !process-tokens @mode[strip:process]
    !return

!mode @name[strip:main-cdata] @accept[] @type[process] @use-indentation[false]
  !default
    !document-fragment @encoding[UTF-8]
      !cdata
        !text &#x0A;
        !process-tokens @mode[strip:process]
    !return

!mode @name[strip:process] @accept[<!-- |<!--|uc|] @use-indentation[false] @type[process]
  !punc @data[<!-- ] 
    !execute @mode[strip:execute-comment]
  !punc @data[<!--] 
    !execute @mode[strip:execute-comment]
  !uc @fullname[0xa] ; ignore
  !uc @fullname[0xd] ; ignore
  !uc
    !execute @mode[strip:execute-noncomment]
  !default
    !return

!mode @name[strip:execute-comment] @accept[<!-- |<!--] @type[execute]
  !default
    !set-parameter @name[strip:data] @value[]
    !process-tokens @mode[strip:get-comment-data] @parameters[share]
    !text [$\{strip:data\}]
    !text &#x0A;
    !return

!mode @name[strip:get-comment-data] @accept[ -->|-->|uc|] @use-indentation[false] @type[process]
  !punc @data[ -->] !return
  !punc @data[-->] !return
  !uc !append-parameter @name[strip:data] @value[$v]
  !default !return

!mode @name[strip:execute-noncomment] @accept[uc] @type[execute]
  !default
    !set-parameter @name[strip:data] @value[]
    !if @test[$v] @value[\\] !append-parameter @name[strip:data] @value[\\]
    !if @test[$v] @value[\{] !append-parameter @name[strip:data] @value[\\]
    !if @test[$v] @value[\}] !append-parameter @name[strip:data] @value[\\]
    !if @test[$v] @value[\[] !append-parameter @name[strip:data] @value[\\]
    !if @test[$v] @value[\]] !append-parameter @name[strip:data] @value[\\]
    !append-parameter @name[strip:data] @value[$v]
    !process-tokens @mode[strip:get-noncomment-data] @parameters[share]
    !text [pre\[$\{strip:data\}\]]
    !text &#x0A;
    !return

!mode @name[strip:get-noncomment-data] @accept[<!-- |<!--|uc|] 
    @use-indentation[false] @type[process]
  !punc @data[<!--] !abort
  !punc @data[<!-- ] !abort
  !uc @data[\[] !append-parameter @name[strip:data] @value[\\\[]
  !uc @data[\]] !append-parameter @name[strip:data] @value[\\\]]
  !uc @data[\{] !append-parameter @name[strip:data] @value[\\\{]
  !uc @data[\}] !append-parameter @name[strip:data] @value[\\\}]
  !uc @data[\\] !append-parameter @name[strip:data] @value[\\\\]
  !uc !append-parameter @name[strip:data] @value[$v]
  !default !return
}; !declare-prefix

This file is part of the GLOSS system, Copyright Richard Kaye http://gloss.bham.ac.uk/. Usage permitted under the GPL. No Warranty.

This page is copyright. Web page design and creation by GLOSS.