From 12eeefcdba1ee392f033f51e6b9826eaae3c4de6 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 13 Jun 2016 23:16:54 +0300 Subject: Add tokenizer, parser and support for certain operations --- main/core/CommandLineArgumentContainer.java | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 main/core/CommandLineArgumentContainer.java (limited to 'main/core/CommandLineArgumentContainer.java') diff --git a/main/core/CommandLineArgumentContainer.java b/main/core/CommandLineArgumentContainer.java new file mode 100644 index 0000000..9ca0b5e --- /dev/null +++ b/main/core/CommandLineArgumentContainer.java @@ -0,0 +1,56 @@ +package com.jantuomi.interpreter.main.core; + +import org.kohsuke.args4j.Option; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +/** + * Created by jan on 10.6.2016. + */ + +public class CommandLineArgumentContainer { + + private CommandLineArgumentContainer() {} + + private static final CommandLineArgumentContainer instance = new CommandLineArgumentContainer(); + private File srcFile; + + @Option(name="-f", usage="Execute script in file FILE.") + public void setFile(File file) { + this.srcFile = file; + } + + public static CommandLineArgumentContainer getInstance() { + return instance; + } + + public String getSourceFileContents() { + if (srcFile == null) { + return null; + } + + BufferedReader br; + String contents = null; + try { + br = new BufferedReader(new FileReader(srcFile)); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + + while (line != null) { + sb.append(line); + sb.append(System.lineSeparator()); + line = br.readLine(); + } + contents = sb.toString(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } finally { + // Add a newline at the end for comment rows to terminate nicely + return contents + "\n"; + } + } +} -- cgit v1.3