katydid / relaxng Goto Github PK
View Code? Open in Web Editor NEWTranslates RelaxNG to Relapse
Home Page: http://katydid.github.io/relaxng/play/
License: Apache License 2.0
Translates RelaxNG to Relapse
Home Page: http://katydid.github.io/relaxng/play/
License: Apache License 2.0
Adding namespaces has three problems.
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.
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.
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.
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`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.