Skip to content

Instantly share code, notes, and snippets.

@billdenney
Last active November 13, 2019 14:18
Show Gist options
  • Save billdenney/a5963b208fe8770de291352e759a96f6 to your computer and use it in GitHub Desktop.
Save billdenney/a5963b208fe8770de291352e759a96f6 to your computer and use it in GitHub Desktop.
Test rudolph with nmtran
if (!requireNamespace("rudolph")) {
devtools::install_github("billdenney/rudolph/r/rudolph")
}
library(rudolph)
nmtrancpp_dir <- "c:/git/Not_my_repositories/nmtranprocessorcpp"
grammar_path <- file.path(nmtrancpp_dir, "grammar/")
compiled_path <- file.path(grammar_path, "rudolph/")
if (!dir.exists(nmtrancpp_dir)) {
dir.create(nmtrancpp_dir, showWarnings=FALSE, recursive=TRUE)
git2r::clone(
url="https://github.com/EightPillars/nmtranprocessorcpp.git",
local_path=nmtrancpp_dir
)
} else {
git2r::pull(repo=nmtrancpp_dir)
}
dir.create(compiled_path, showWarnings=FALSE, recursive=TRUE)
# Add the path to javac to the main path (omit if javac is already on the path)
Sys.setenv(PATH=paste0(Sys.getenv("PATH"), "C:\\Program Files\\Java\\jdk-13.0.1\\bin;"))
grammarFiles <-
list.files(
pattern="g4$",
path=grammar_path,
full.names=TRUE
)
elf <- Elf(
# where to save the generated compiled parser/lexer files
destinationDirectory = compiled_path,
grammarFiles = grammarFiles,
parserPrefix="NmtranParser",
lexerPrefix="NmtranLexer"
)
generateAndCompile(elf)
rudolph <- Rudolph(
grammarFiles = grammarFiles,
rootNode = "nmModel",
sourceDirectory = compiled_path,
parserPrefix="NmtranParser",
lexerPrefix="NmtranLexer"
)
model <- readLines("c:/nm74g64/examples/example1.ctl")
ast <- getAST(rudolph, paste(model, collapse="\n"))
print(ast)
@billdenney
Copy link
Author

billdenney commented Nov 3, 2019

@dpastoor, @mattfidler, @stumoodie, @EightPillars, @MikeKSmith, @kylebaron, @vjd, @TomTensfeldt, @rfaelens:

I think that I've mentioned this antlr - R interface to you each. Here is an example of it in practice (using @EightPillars's grammar, thanks!). If you know others who may be interested, please let them know and/or tag them here.

@billdenney
Copy link
Author

@smouksassi, I think that you may find this interesting, too.

@mattfidler
Copy link

Hi @billdenny,

Thanks for the information. It seems like some good work.

@smouksassi
Copy link

Thanks ! helpful indeed

@billdenney
Copy link
Author

@guiastrennec, you may also find this interesting.

@kylebaron
Copy link

kylebaron commented Nov 13, 2019

Thanks, @billdenney Looks promising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment