We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currently there is no way to validate if a nomnoml diagram is valid, say [hello] (valid), vs [hello (invalid).
nomnoml
[hello]
[hello
However, we can use the mlverse/duktape package as a workaround as follows:
remotes::install_github("mlverse/duktape")
Then define the following function:
nomnoml_validate <- function(diagram = "[test]") { duktape::eval( paste(c( readLines(system.file("htmlwidgets/lib/dagre/dagre.min.js", package = "nomnoml")), readLines(system.file("htmlwidgets/lib/lodash/lodash.js", package = "nomnoml")), readLines(system.file("htmlwidgets/lib/nomnoml/nomnoml.js", package = "nomnoml")), paste0("nomnoml.parse('", diagram, "')") ), collapse = "\n") ) }
And validate nomnoml syntax as follows:
nomnoml_validate("[hello]")
vs
nomnoml_validate("[hello")
Error in duktape::rcpp_eval(paste(c(readLines(system.file("htmlwidgets/lib/dagre/dagre.min.js", : Error: Parse error on line 1: [hello ------^ Expecting 'SEP', '|', ']', got 'EOF'
The text was updated successfully, but these errors were encountered:
This is great, thank you!
I tried your code, and it works great for the example provided, but I can't get it to work for multi-line diagrams, e.g:
nomnoml_validate("[hello] [world]")
results in:
Error in rcpp_eval(code) : SyntaxError: unterminated string (line 19004)
However, I was able to get the same idea to work using V8 instead of duktape:
V8
duktape
nomnoml_validate <- function(diagram = "[test]") { ct <- v8() ct$source(system.file("htmlwidgets/lib/dagre/dagre.min.js", package = "nomnoml")) ct$source(system.file("htmlwidgets/lib/lodash/lodash.js", package = "nomnoml")) ct$source(system.file("htmlwidgets/lib/nomnoml/nomnoml.js", package = "nomnoml")) ct$assign("diagram", diagram) ct$eval("nomnoml.parse(diagram)"), }
An invalid diagram:
> nomnoml_validate("[hello") <std::runtime_error in context_eval(join(src), private$context, serialize): Error: Parse error on line 1: [hello ------^ Expecting 'SEP', '|', ']', got 'EOF'>
A valid multi-line diagram:
> nomnoml_validate("[hello] + [world]") [1] "[object Object]"
Is there any disadvantage to use V8 compared to duktape?
Sorry, something went wrong.
I implemented this in #21
No branches or pull requests
Currently there is no way to validate if a
nomnoml
diagram is valid, say[hello]
(valid), vs[hello
(invalid).However, we can use the mlverse/duktape package as a workaround as follows:
Then define the following function:
And validate
nomnoml
syntax as follows:nomnoml_validate("[hello]")
vs
nomnoml_validate("[hello")
The text was updated successfully, but these errors were encountered: