Giter Club home page Giter Club logo

xml-tools's Introduction

CircleCI Coverage Status Language grade: JavaScript styled with prettier Commitizen friendly dependentbot REUSE status

XML-Tools

XML-Tools is an npm mono-repo that contains tools & libraries for Extensible Markup Language (XML). These tools & libraries are mainly focused on capabilities for implementing Editor Services flows in IDEs, for example: Content Assist and Diagnostics.

It currently contains the following packages:

Support

Please open issues on github.

Contributing

See CONTRIBUTING.md.

xml-tools's People

Contributors

bd82 avatar dependabot-preview[bot] avatar dependabot[bot] avatar frehu avatar lidortal avatar marceloschreiber avatar michawai avatar panishvp avatar rayakoren avatar sapirpol avatar sebastianwolf-sap avatar tal-sapan avatar vadson71 avatar voicis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xml-tools's Issues

Strict XML parser

Would it be possible to have some function that builds a strict AST tree from a correct XML and make it fail on the slightest of error and so that the various XML typescript definitions are strict as well(no ? on certain props). I'm making a tool to optimize SVG files and I don't want to continue optimizing if the CST parser gives any parse errors.

Parser doesn't support line breaks in between attributes:

For example this XML doesn't give any information in the CST about the linebreaks between the attributes:

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100%" height="100%" viewBox="0 0 110 60">

  <g id="group-1">
    <circle cx="80" cy="30" r="20" fill="cornflowerblue" />
    <text x="80" y="33" text-anchor="middle" font-size="10">1</text>
  </g>

  <g id="group-1">
    <rect x="10" y="10" width="40" height="40" fill="gold" />
    <text x="30" y="33" text-anchor="middle" font-size="10">2</text>
  </g>
</svg>

Missing ranges in NameStartChar

Looks like in the lexer is missing a couple of entries in its regex for NameStartChar.

I'm seeing

"(:|[a-zA-Z]|_|\\u2070-\\u218F|\\u2C00-\\u2FEF|\\u3001-\\uD7FF|\\uF900-\\uFDCF|\\uFDF0-\\uFFFD)"
, which includes:

":" | [A-Z] | "_" | [a-z] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD]

But the spec has:

":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]

So it's missing some entries in the 1-byte form and then anything #x10000 and above.

Parser error because of BOM

I'm receiving a parser error upon parsing a file containing a Byte Order Mark(BOM) and according to XML-processors it is OK to do so. I took a glance at the spec as well but I don't quite understand it fully.

I think it would make more sense to have a lexical error or maybe no error since it looks like it's acceptable.

https://www.w3.org/TR/xml/#charencoding

Parser doesn't support whitespace before prolog

The parser fails completely, and without errors, when there is whitespace before the XML prolog.
I need to preserve positions so I can't trim those spaces; it should be possible to allow them.

{empty lines here}
<?xml version="1.0" encoding="utf-8" ?>
<component>
</component>

extension doesn't work through corporate proxy

Hi,

Excellent to see SAP taking ownership of these extensions. However the extension doesn't work through corporate proxy, even though it has been added in VS code settings and windows environment variables.

See output below

c:\Users\KjaerJ\AppData\Roaming\Code\User\globalStorage\saposs.vscode-ui5-language-assistant\ui5-resources-cache\1.71.14 will be used to cache UI5 resources
[Error - 9:46:22 am] Request textDocument/hover failed.
Message: Request textDocument/hover failed with message: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
Code: -32603
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13616) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:13616) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
[Error - 9:46:31 am] Request textDocument/hover failed.
Message: Request textDocument/hover failed with message: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
Code: -32603
[Error - 9:46:32 am] Request textDocument/completion failed.
Message: Request textDocument/completion failed with message: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
Code: -32603
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
[Error - 9:48:13 am] Request textDocument/hover failed.
Message: Request textDocument/hover failed with message: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
Code: -32603
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
[Error - 9:48:13 am] Request textDocument/completion failed.
Message: Request textDocument/completion failed with message: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
Code: -32603
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: FetchError: request to https://sapui5.hana.ondemand.com/1.71.14/test-resources/sap/ca/scfld/md/designtime/api.json failed, reason: connect ETIMEDOUT 23.48.30.95:443
at ClientRequest. (c:\Users\KjaerJ.vscode\extensions\saposs.vscode-ui5-language-assistant-1.5.1\node_modules@ui5-language-assistant\language-server\dist\server.js:48289:11)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
(node:13616) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)

Element.syntax.openBody range does not always exist for partially valid elements

The second and third propertyValue would not have an ``openBody` range.

<Record Type="UI.DataPointType">
    <PropertyValue Property="Value" Path="Price"/>
    <PropertyValue 
    <PropertyValue  attrib1="3"
</Record>

We should "guess" and approximate openBody range which continues until the next
following textual component

Perhaps we should mark that this openBody has been guessed, e.g using another property possibleOpenBody.

Context assistant does not call provider in some text node positions

Text content provider not called in positions right before opening tag and immediately following closing tag.

The following tests help to identify the problem.

  it("in position immediately following a closing tag", () => {
    const sample =
      `<person address="NY">\n` +
      `\t<firstname>Anna</firstname>⇶\n` +
      `\t<lastname>Smith</lastname>\n` +
      `</person>`;

    let providerCalled = false;
    getSampleSuggestions(sample, {
      attributeName: [
        ({ element, attribute, prefix }) => {
          expect(element.name).to.eql("person");
          expect(attribute).to.be.undefined;
          expect(prefix).to.be.undefined;
          providerCalled = true;
        }
      ]
    });
    expect(providerCalled).to.be.true;
  });

  it("in position right before an opening tag", () => {
    const sample =
      `<person address="NY">\n` +
      `\t<firstname>Anna</firstname>\n` +
      `\t⇶<lastname>Smith</lastname>\n` +
      `</person>`;

    let providerCalled = false;
    getSampleSuggestions(sample, {
      attributeName: [
        ({ element, attribute, prefix }) => {
          expect(element.name).to.eql("person");
          expect(attribute).to.be.undefined;
          expect(prefix).to.be.undefined;
          providerCalled = true;
        }
      ]
    });
    expect(providerCalled).to.be.true;
  });

Issue in latest publish of npm @xml-tools/[email protected]?

Hi, guys. I think there's been an error in publishing 1.0.8.

see https://unpkg.com/browse/@xml-tools/[email protected]/lib/

Looks like somehow lexer.js & parser.js got removed from the published package.

I see they are still on the repo and the code still references them plus dependent projects fail when building ("unable to find ./parser.js`) so I suspect this is an error.

In my case, @xml-tools/parser is not a direct dependency of my project. I've temporarily added this to fix...

"resolutions": {
  "@xml-tools/parser": "1.0.7"
}

Support for inline XML DTD

I got this report on prettier/plugin-xml.

<!-- demo.xml -->
 <!DOCTYPE example [
  <!ELEMENT example (item)*>
  <!ELEMENT item (name, price)>
  <!ELEMENT name (#PCDATA)>
  <!ELEMENT price (#PCDATA)>
]>
<example>
  <item>
    <name>Item 1</name>
    <price>$10.00</price>
  </item>
  <item>
    <name>Item 2</name>
    <price>$20.00</price>
  </item>
</example>

Honestly I would be totally fine with a temporary measure that just didn't crash on these kinds of inputs and skipped to the next balanced >. Then I could just copy the source text and not worry about formatting it.

Improve fault tolerance for abandoned closing tag

For below xml code snippet

<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
    <edmx:Reference Uri="some/uri">
        <edmx:Include Namespace="com.sap.vocabularies.UI.v1" Alias="UI" />
    </edmx:Reference>
    <edmx:Reference Uri="/here/goes/your/serviceurl/$metadata">
        <edmx:Include Namespace="ns-demo" Alias="demo" />
    </edmx:Reference>
    <edmx:DataServices>
        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="local">
            <Annotations Target="demo.demoTarget">
 		<Annotation Term="UI.LineItem" >
                    <Collection>
                        <Record Type="UI.DataField">
                            <PropertyValue Property="Value" Path="MainProductCategory"/>
                        </Record>
                        </Record> `|`
                    </Collection>
                </Annotation> 											
            </Annotations>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

where | represents the cursor position, there exits two issues.

  • XML-Tools reports diagnostic on the wrong element. Here edxm:Edmx. The diagnostic should be reported close to the element where there is an issue
  • AST seems to be wrong. Generated AST points to the wrong parent. For the above cursor position, parent should be Collection, but it is Annotations

Error reporting for attribute value without closing "

Unbalanced quotes are probably a common occurrence when writing xml and the errors about a missing EQUALS here are not clear at all. Maybe this situation could be reported more intelligently?
image
The errors are not the same if I leave an unclosed attribute before another empty attribute:
image

Content assist for attribute in invalid opening element

When creating a new element it usually is not closed and next thing that the user wants to add is an attribute, so we should provided content assist for attribute in the example below. (cursor position is |)

<Record Type="UI.DataPointType">
    <PropertyValue Property="Value" Path="Price"/>
    <PropertyValue |
</Record>

Current attribute name should be included in suggestion list

If code completion for attribute name is taking place in position of some existing attribute, content assistant should include current attribute name in completion list ( in case if it is a valid name ). Otherwise user has a feeling that current attribute is invalid.

XML is whitespace sensitive in some grammar productions.

Apparently whitespace cannot be freely used everywhere, examples:

So @xml-tools/parser is not exposing the correct syntax errors in this case.
But on the other hand this parser is fault tolerant and should be able to handle small syntax errors
such as these transparently.

The solution would likely be to manually perform checks for redundant during parsing.
and save a custom syntax error message if such WS was encountered.
These syntax errors should not affect the regular parsing flow.

Support to ignore "<" invalid syntax

Hi!
I am currently having issues with formatting XML through prettier plugin which uses your library to implement their XML formatting. We are trying to figure out if it is possible to ignore certain syntax errors and continue formatting the rest of the file.

Example:
<Text text="< Back" />

This currently fails with SyntaxError: unexpected character: ->"<- at offset: XXX skipped 1 characters. (XXX:XXX) and doesn't format that file at all. I think the issue is with the < inside of the quotes. According to the XML spec, this is invalid syntax. We are wondering if there is a flag or a feature that can be used to ignore such errors and continue formatting the rest of it.

cc: @kddnewton

Wrong CST for multi-line comments

Parser outputs wrong CST for multi line comments. It creates element node instead of comment node.
Example:

<Record Type="UI.DataPointType">
    <!--
        
    -->
</Record>

simple-schema suggestions

I am trying to use xml-tools to implement a language on top of xml (it's some kind of crossover of xsd and xslt, but this does not really matter for the purpose of these suggestions).

I believe I can work around these by implementing custom validators, but it would be nice if simple-schema supported

Recursive type definitions

I am using an xml file to describe the structure of an xml file, therefore I need recursive elements, e.g.

<element name="foo">
  <element name="bar">
    <attribute name="attr"><attribute>
  </element>
</element>

is used to represent

<foo>
  <bar attr=""/>
</foo>
const commonNodeProperties: Record<string, XSSAttribute> = {
	name: {
		key: "name",
		required: true
	},
	description: {
		key: "description",
		required: false
	},
	restriction: {
		key: "restriction",
		required: false,
	},
	mappingTarget: {
		key: "mappingTarget",
		required: false,
	},
	mapping: {
		key: "mapping",
		required: false,
	}
};


export const rootElementSchema: XSSElement = {
	name: "element",
	cardinality: "single",
	required: true,
	attributesType: "closed",
	attributes: {
		...commonNodeProperties
	},
	elements: {
		element: {
			name: "element",
			cardinality: "many",
			required: true,
			attributesType: "closed",
			attributes: {
				...commonNodeProperties
			},
			elements: {
                          // element can contain element, attribute with cardinality many
                        },
			elementsType: "open"
		},
		attribute: {
			name: "attribute",
			cardinality: "many",
			required: true,
			attributesType: "closed",
			attributes: {
				...commonNodeProperties
			},
			elements: {},
			elementsType: "open"
		}
	},
	elementsType: "open"
};

export const schema: SimpleSchema = {
	name: "ifme",
	required: true,
	require: true,
	cardinality: "single",
	attributes: {},
	attributesType: "closed",
	elements: {
		environment: environmentSchema,
		constants: constantsSchema,
		enumerations: enumerationsSchema,
		restrictions: restrictionsSchema,
		tree: {
			name: "tree",
			required: true,
			cardinality: "single",
			attributes: {},
			elements: {
				element: rootElementSchema
			},
			attributesType: "closed",
			elementsType: "closed"
		},
	},
};

but I don't think I will be able to accomplish this with simple-schema currently.

Empty attribute value validation

I can specify that an attribute is required, but it is also likely that a required attribute should have a non-empty value.

[minor] XSSElement type definitions

I wish elements and attributes were optional properties, in many cases you don't need them and you have to explicitly use empty objects.

const thatWillBeAllThanks: any = {
	attributes: {},
	elements: {}
};

const environmentSchema: XSSElement = {
	name: "environment",
	required: true,
	cardinality: "single",
	attributes: {
	},
	elements: {
		type: {
			name: "type",
			cardinality: "single",
			required: true,
			...thatWillBeAllThanks
		},
		id: {
			name: "id",
			cardinality: "single",
			required: true,
			...thatWillBeAllThanks
		},
		description: {
			name: "description",
			cardinality: "single",
			required: false,
			...thatWillBeAllThanks
		},
	},
};

Extraneous namespace prefix completion item

Namespace completion item is provided for all namespace prefixes that are available in given context even though there are no applicable elements for the given namespace.

Simple schema:

{
  "name": "Edmx",
  "namespace": "http://docs.oasis-open.org/odata/ns/edmx",
  "cardinality": "single",
  "required": true,
  "require": true,
  "attributesType": "closed",
  "elementsType": "closed",
  "elements": {
    "Example": {
      "name": "Example",
      "namespace": "http://docs.oasis-open.org/odata/ns/edm",
      "cardinality": "many",
      "required": false,
      "attributesType": "closed",
      "elementsType": "closed",
      "attributes": {
        "Uri": {
          "key": "Uri",
          "required": true
        }
      }
    }
  }
}

XML document

<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
    <|
</edmx:Edmx>

Cursor position is denoted with | symbol. If code completion is triggered there, then there will be a completion item for edmx namespace prefix, even though it can not contain any elements from that namespace.

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.