Add Stream fromString
This commit is contained in:
@@ -60,7 +60,7 @@ class EmbeddedScript {
|
||||
classFields.push(field);
|
||||
}
|
||||
|
||||
Reader.readAndProcess(new Stream(scriptFile), k, (nextExp) -> {
|
||||
Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> {
|
||||
var field = Kiss.readerExpToField(nextExp, k, false);
|
||||
if (field != null) {
|
||||
classFields.push(field);
|
||||
|
@@ -94,7 +94,7 @@ class Kiss {
|
||||
public static function build(kissFile:String, ?k:KissState, useClassFields = true):Array<Field> {
|
||||
return _try(() -> {
|
||||
var classFields:Array<Field> = if (useClassFields) Context.getBuildFields() else [];
|
||||
var stream = new Stream(kissFile);
|
||||
var stream = Stream.fromFile(kissFile);
|
||||
|
||||
// (load... ) relative to the original file
|
||||
var loadingDirectory = Path.directory(kissFile);
|
||||
|
@@ -42,19 +42,29 @@ class Stream {
|
||||
|
||||
public var startOfLine = true;
|
||||
|
||||
public function new(file:String) {
|
||||
// Banish ye Windows line-endings
|
||||
content = File.getContent(file);
|
||||
public static function fromFile(file:String) {
|
||||
return new Stream(file, File.getContent(file));
|
||||
}
|
||||
|
||||
public static function fromString(content:String) {
|
||||
return new Stream("string", content);
|
||||
}
|
||||
|
||||
private function new(file:String, content:String) {
|
||||
this.file = file;
|
||||
|
||||
// Banish ye Windows line-endings
|
||||
if (content.indexOf('\r') >= 0) {
|
||||
absolutePerNewline = 2;
|
||||
content = content.replace('\r', '');
|
||||
}
|
||||
|
||||
this.content = content;
|
||||
|
||||
// Life is easier with a trailing newline
|
||||
if (content.charAt(content.length - 1) != "\n")
|
||||
content += "\n";
|
||||
|
||||
this.file = file;
|
||||
line = 1;
|
||||
column = 1;
|
||||
absoluteChar = 0;
|
||||
|
Reference in New Issue
Block a user