Last active
November 13, 2019 14:18
-
-
Save billdenney/a5963b208fe8770de291352e759a96f6 to your computer and use it in GitHub Desktop.
Test rudolph with nmtran
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
@smouksassi, I think that you may find this interesting, too.
Hi @billdenny,
Thanks for the information. It seems like some good work.
Thanks ! helpful indeed
@guiastrennec, you may also find this interesting.
Thanks, @billdenney Looks promising.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.