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