use of org.mozilla.javascript.Parser in project whole by wholeplatform.
the class RhinoTransformerVisitor method transform.
public static IEntity transform(IPersistenceProvider pp) throws Exception {
CompilerEnvirons compilerEnvirons = CompilerEnvirons.ideEnvirons();
compilerEnvirons.setLanguageVersion(Context.VERSION_1_8);
Parser parser = new Parser(compilerEnvirons);
AstRoot astRoot = parser.parse(new InputStreamReader(pp.getInputStream(), pp.getEncoding()), "http://whole.sourceforge.net/test.js", 0);
ModelBuilderOperation mop = new ModelBuilderOperation();
RhinoTransformerVisitor visitor = new RhinoTransformerVisitor(mop);
astRoot.visit(visitor);
return mop.wGetResult();
}
use of org.mozilla.javascript.Parser in project pmd by pmd.
the class EcmascriptParser method parseEcmascript.
protected AstRoot parseEcmascript(final String sourceCode, final List<ParseProblem> parseProblems) throws ParseException {
final CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
compilerEnvirons.setRecordingComments(parserOptions.isRecordingComments());
compilerEnvirons.setRecordingLocalJsDocComments(parserOptions.isRecordingLocalJsDocComments());
compilerEnvirons.setLanguageVersion(parserOptions.getRhinoLanguageVersion().getVersion());
// Scope's don't appear to get set right without this
compilerEnvirons.setIdeMode(true);
compilerEnvirons.setWarnTrailingComma(true);
// see bug #1150 "EmptyExpression" for valid statements!
compilerEnvirons.setReservedKeywordAsIdentifier(true);
// TODO We should do something with Rhino errors...
final ErrorCollector errorCollector = new ErrorCollector();
final Parser parser = new Parser(compilerEnvirons, errorCollector);
// TODO Fix hardcode
final String sourceURI = "unknown";
final int beginLineno = 1;
AstRoot astRoot = parser.parse(sourceCode, sourceURI, beginLineno);
parseProblems.addAll(errorCollector.getErrors());
return astRoot;
}
use of org.mozilla.javascript.Parser in project MtgDesktopCompanion by nicho92.
the class MTGSalvationDeckSniffer method parseColor.
private String parseColor(String string) {
AstNode node = new Parser().parse(string, "", 1);
node.visit(n -> {
manajson = n.toSource();
return false;
});
manajson = manajson.substring(manajson.indexOf("series") + "series: ".length(), manajson.length() - 8);
JsonArray arr = new JsonParser().parse(manajson).getAsJsonArray();
manajson = "";
boolean hascolor = false;
for (int i = 0; i < arr.size(); i++) {
JsonObject obj = arr.get(i).getAsJsonObject();
String c = ColorParser.parse(obj.get("name").getAsString());
JsonArray tab = obj.get("data").getAsJsonArray();
hascolor = false;
for (int j = 0; j < tab.size(); j++) {
if (tab.get(j).getAsInt() > 0)
hascolor = true;
}
if (hascolor && !c.equals("{C}")) {
manajson += c;
}
}
return manajson;
}
Aggregations