Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Parse RNG directly from string? #177

Open
siefkenj opened this issue May 26, 2022 · 4 comments
Open

Parse RNG directly from string? #177

siefkenj opened this issue May 26, 2022 · 4 comments
Assignees
Labels

Comments

@siefkenj
Copy link

Is there a way to parse RNG source directly from a string? It appears that convertRNGToPattern only accepts a URL. (I am trying to use salve from the browser where I already have a string that has been fetched).

@lddubeau lddubeau self-assigned this May 26, 2022
@lddubeau
Copy link
Member

It's been over 2 years since I've worked on this code so it is not fresh in my memory. I'd expect you to be able to use a data: URL . See this documentation:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs

If that does not work, please let me know.

@siefkenj
Copy link
Author

Thanks for the reply! I just tried that, but it doesn't work in the browser. I suspect it's because of the use of the fs module...Was there any ever work to get salve to run in the browser?

@lddubeau
Copy link
Member

Salve was working in the browser. There's also this package which is made to parse DOM trees: salve-dom

I'd look here:

export async function parse(rngSource: string | Grammar,

And specifically the grammarFromSource function which is not exported. It does take a string of the RNG as input. I don't think we're exporting it, but you could write a function that works in the same way. Or use the parse function that I link to above if it does what you want. This code still uses fs but there is no reason that fs has to be used.

Otherwise, you might want to paste example code in your issue. I'm not sure I understand exactly the problem.

@siefkenj
Copy link
Author

The code I am trying is

function processRelaxNgSchema(relaxNgSource: string) {
    const url = new URL(
        URL.createObjectURL(new Blob([relaxNgSource], { type: "text" }))
    );
    console.log("SALVE", salve.convertRNGToPattern(url));
}

and I am getting an error salve__WEBPACK_IMPORTED_MODULE_3___default() is undefined which I am guessing comes from not being able to transpile the fs module.

The parse function looks like what I need! It doesn't seem to be on the default export. Is it exported somewhere else?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants