GithubHelp home page GithubHelp logo

katydid / relaxng Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 0.0 1.69 MB

Translates RelaxNG to Relapse

Home Page: http://katydid.github.io/relaxng/play/

License: Apache License 2.0

Go 67.59% Shell 1.41% Makefile 0.46% JavaScript 9.35% HTML 21.19%
relaxng relaxng-grammar translates-relaxng validation xml

relaxng's Introduction

Katydid

Katydid is a toolkit for trees.

GoDoc Build Status

Katydid Logo

Currently there are three tools in the katydid toolkit:

  • Relapse: a regular expression type language for trees that matches up to 1000000s of records per second,
  • A collection of parsers (protobuf, json, xml, reflected go structures, yaml) which are easily extendable, and
  • A collection of encoders (protobuf, json, xml, reflected go structures) which are useful for dynamic transcoding.

more...

relaxng's People

Contributors

awalterschulze avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

relaxng's Issues

namespaces are not supported

Adding namespaces has three problems.

  1. Currently the xml parser does not return the namespaces. This can be fixed with this diff
diff --git a/parser/xml/parser.go b/parser/xml/parser.go
index d63e9bb..4e40e18 100644
--- a/parser/xml/parser.go
+++ b/parser/xml/parser.go
@@ -196,14 +196,21 @@ func (p *xmlParser) Bool() (bool, error) {

 func (p *xmlParser) String() (string, error) {
        if p.tok == nil && p.attrIndex < len(p.attrs) {
+               a := p.attrs[p.attrIndex]
                if p.attrValue {
-                       return p.textPrefix + p.attrs[p.attrIndex].Value, nil
+                       return p.textPrefix + a.Value, nil
                } else {
-                       return p.attrPrefix + p.attrs[p.attrIndex].Name.Local, nil
+                       if len(a.Name.Space) == 0 {
+                               return p.attrPrefix + a.Name.Local, nil
+                       }
+                       return p.attrPrefix + a.Name.Space + ":" + a.Name.Local, nil
                }
        }
        if s, ok := p.tok.(StartElement); ok {
-               return p.elemPrefix + s.Name.Local, nil
+               if len(s.Name.Space) == 0 {
+                       return p.elemPrefix + s.Name.Local, nil
+               }
+               return p.elemPrefix + s.Name.Space + ":" + s.Name.Local, nil
        }
        if c, ok := p.tok.(CharData); ok {
                return p.textPrefix + string(c), nil

This is so easy because the golang xml parsing library already resolves the namespaces for us. Probably with a preparse phase, which is technically some sort of cheating, because now we don't need to keep any state in the validator, this state is kept in the parser for us by the golang xml parser.

  1. nsName in relaxNG only matches the namespace and not the element name, so in this case relapse will need to be able match prefixes on names. The hardest part about this would be to design the syntax and thinking about whether names should allow all types of functions and not just a very constrained subset.

  2. Also xmlns attributes would need to be matched which is currently conveniently done as an optional attribute with any value. When namespaces are returned by the parser their name will also require a more complex and specific pattern.

No build with fresh katydid/katydid

With fresh katydid/katydid/relapse/* have next errors:

go test -v .
./funcs.go:35:74: cannot use token literal (type *token) as type *ast.Expr in argument to combinator.Value
./funcs.go:135:53: cannot use whitespace literal (type *whitespace) as type *ast.Expr in argument to combinator.Value
./funcs.go:139:53: cannot use whitespace literal (type *whitespace) as type *ast.Expr in argument to combinator.Value
./funcs.go:143:50: cannot use anytext literal (type *anytext) as type *ast.Expr in argument to combinator.Value
./funcs.go:147:77: cannot use text literal (type *text) as type *ast.Expr in argument to combinator.Value
./funcs.go:223:73: cannot use list literal (type *list) as type *ast.Expr in argument to combinator.Value`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.