private String parseInclude(InputReader reader) throws InvalidSyntaxException, ParserException { String inputFileName = reader.nextWord().asBareString(); File inputFile = new File(baseDir, inputFileName); String statement; if (excludeFiles.contains(inputFileName) || excludeFiles.contains(inputFile.getAbsolutePath())) { // Handle excluded file logger.info(reader, "Include file '" + inputFileName + "' omitted being marked as excluded."); String outputFileName = MakeBridleNSIS.convertToBridleFilename(inputFileName); File outputFile = new File(outDir, outputFileName); copyFile(inputFile, outputFile, reader.getLinesRead()); statement = NSISStatements.include(reader.getIndent(), outputFileName); } else if (!inputFile.exists()) { // Include file not found logger.debug( reader, "Include file '" + inputFileName + "' not found, assuming it's found by NSIS."); statement = reader.getCurrentStatement(); } else { // Parse include file logger.debug(reader, "Follow include: " + inputFile.getAbsolutePath()); String outputFileName = MakeBridleNSIS.convertToBridleFilename(inputFileName); try (BufferedWriter writer = getOutputWriter(outputFileName)) { parseFile(inputFile, writer); } catch (IOException e) { throw new InvalidSyntaxException(e.getMessage(), e); } statement = NSISStatements.include(reader.getIndent(), outputFileName); } return statement; }
protected String parseStatement(InputReader reader) throws InvalidSyntaxException, EnvironmentException, ParserException { if (!reader.hasNextWord()) { return reader.getCurrentStatement(); } Word word = reader.nextWord(); String keyword = word.asName(); WordTail tail = reader.getWordTail(); if (tail.isCompilerCommand()) { String command = reader.nextWord().asName(); if (command.equals("include")) { return parseInclude(reader); } else if (command.equals("macro")) { insideMacro = true; return reader.getCurrentStatement(); } else if (command.equals("macroend")) { insideMacro = false; return reader.getCurrentStatement(); } } if (insideMacro) { return reader.getCurrentStatement(); } else if (tail.isAssignment()) { return statementParser.parseVarAssign(word, reader); } else if (tail.isFunctionArgsOpen()) { return statementParser.parseCall(word, null, reader); } else if (keyword.equals("var")) { return statementParser.parseVarDeclare(reader); } else if (keyword.equals("function")) { return statementParser.parseFunctionBegin(reader); } else if (keyword.equals("return")) { return statementParser.parseFunctionReturn(reader); } else if (keyword.equals("functionend")) { return statementParser.parseFunctionEnd(reader); } else if (keyword.equals("if") || keyword.equals("elseif")) { return statementParser.parseIf(word, reader); } else if (keyword.equals("else")) { return NSISStatements.logicLibDefine(reader.getIndent(), "Else"); } else if (keyword.equals("endif")) { return NSISStatements.logicLibDefine(reader.getIndent(), "EndIf"); } else if (keyword.equals("do")) { return statementParser.parseDoLoop("Do", reader); } else if (keyword.equals("continue")) { return NSISStatements.logicLibDefine(reader.getIndent(), "Continue"); } else if (keyword.equals("break")) { return NSISStatements.logicLibDefine(reader.getIndent(), "Break"); } else if (keyword.equals("loop")) { return statementParser.parseDoLoop("Loop", reader); } return reader.getCurrentStatement(); }
public void parse(String inputFileName, String outputFileName) throws IOException, ParserException { insideMacro = false; File inputFile = new File(baseDir, inputFileName); logger.debug("Begin parse file: " + inputFile.getAbsolutePath()); try (BufferedWriter writer = getOutputWriter(outputFileName)) { writer.write(NSISStatements.nullDefine()); parseFile(inputFile, writer); } }