mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-08-10 17:55:44 +00:00
ough
ough
This commit is contained in:
parent
3bccdef311
commit
434d95b545
@ -8,13 +8,13 @@ import com.hbm.tileentity.network.RTTYSystem.RTTYChannel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* MSES1-FEIS: Machine Script, Equestrian Standard - First Extended Instruction Set (v1.1)
|
* MSES1-FEIS: Machine Script, Equestrian Standard - First Extended Instruction Set (v1.1)
|
||||||
*
|
*
|
||||||
* Additions compared to v1 Standard:
|
* Additions compared to v1 Standard:
|
||||||
* * Support for splitter chars, splitting and split count
|
* * Support for splitter chars, splitting and split count
|
||||||
* * Support for the stack, a secondary buffer that can push, pop and peek
|
* * Support for the stack, a secondary buffer that can push, pop and peek
|
||||||
* * Support for getting string length and substring using first and last
|
* * Support for getting string length and substring using first and last
|
||||||
* * Support for listening only to recent RoR signals using poll
|
* * Support for listening only to recent RoR signals using poll
|
||||||
*
|
*
|
||||||
* @author hbm
|
* @author hbm
|
||||||
*/
|
*/
|
||||||
public class ParseMSES1Ext1 extends ParseMSES1 {
|
public class ParseMSES1Ext1 extends ParseMSES1 {
|
||||||
@ -22,7 +22,7 @@ public class ParseMSES1Ext1 extends ParseMSES1 {
|
|||||||
@Override
|
@Override
|
||||||
public EnumStatementReturn eval(ParseContext ctx, String line) {
|
public EnumStatementReturn eval(ParseContext ctx, String line) {
|
||||||
String lower = line.toLowerCase(Locale.US);
|
String lower = line.toLowerCase(Locale.US);
|
||||||
|
|
||||||
// sets the splitter char
|
// sets the splitter char
|
||||||
if(lower.startsWith("splitter ")) {
|
if(lower.startsWith("splitter ")) {
|
||||||
if(line.length() <= 9) return EnumStatementReturn.PARAMETER_ERROR;
|
if(line.length() <= 9) return EnumStatementReturn.PARAMETER_ERROR;
|
||||||
@ -30,12 +30,13 @@ public class ParseMSES1Ext1 extends ParseMSES1 {
|
|||||||
ctx.splitString = splitter;
|
ctx.splitString = splitter;
|
||||||
return EnumStatementReturn.OK;
|
return EnumStatementReturn.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// grabs a fragment based on index
|
// grabs a fragment based on index
|
||||||
if(lower.startsWith("split ")) {
|
if(lower.startsWith("split ")) {
|
||||||
if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR;
|
if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR;
|
||||||
try {
|
try {
|
||||||
int index = Integer.parseInt(line.substring(6));
|
String statement = substitute(ctx, line.substring(6), true);
|
||||||
|
int index = Integer.parseInt(statement);
|
||||||
if(index < 1) return EnumStatementReturn.PARAMETER_ERROR;
|
if(index < 1) return EnumStatementReturn.PARAMETER_ERROR;
|
||||||
String[] frags = ctx.readBuffer().split(Pattern.quote(ctx.splitString));
|
String[] frags = ctx.readBuffer().split(Pattern.quote(ctx.splitString));
|
||||||
if(index > frags.length) return EnumStatementReturn.PARAMETER_ERROR;
|
if(index > frags.length) return EnumStatementReturn.PARAMETER_ERROR;
|
||||||
@ -43,7 +44,7 @@ public class ParseMSES1Ext1 extends ParseMSES1 {
|
|||||||
return EnumStatementReturn.OK;
|
return EnumStatementReturn.OK;
|
||||||
} catch(Throwable ex) { return EnumStatementReturn.PARAMETER_ERROR; }
|
} catch(Throwable ex) { return EnumStatementReturn.PARAMETER_ERROR; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// counts the amount of fragments in this string
|
// counts the amount of fragments in this string
|
||||||
if(lower.equals("splitcount")) {
|
if(lower.equals("splitcount")) {
|
||||||
if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR;
|
if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR;
|
||||||
@ -51,21 +52,21 @@ public class ParseMSES1Ext1 extends ParseMSES1 {
|
|||||||
ctx.writeBuffer(frags.length + "");
|
ctx.writeBuffer(frags.length + "");
|
||||||
return EnumStatementReturn.OK;
|
return EnumStatementReturn.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pushes the buffer to stack
|
// pushes the buffer to stack
|
||||||
if(lower.equals("push")) {
|
if(lower.equals("push")) {
|
||||||
if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR;
|
if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR;
|
||||||
boolean succ = ctx.push(ctx.readBuffer());
|
boolean succ = ctx.push(ctx.readBuffer());
|
||||||
return succ ? EnumStatementReturn.OK : EnumStatementReturn.STACK_EXCEEDED;
|
return succ ? EnumStatementReturn.OK : EnumStatementReturn.STACK_EXCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pushes the supplied value (or variable) to stack
|
// pushes the supplied value (or variable) to stack
|
||||||
if(lower.startsWith("push ")) {
|
if(lower.startsWith("push ")) {
|
||||||
if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR;
|
if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR;
|
||||||
boolean succ = ctx.push(substitute(ctx, line.substring(5), false));
|
boolean succ = ctx.push(substitute(ctx, line.substring(5), false));
|
||||||
return succ ? EnumStatementReturn.OK : EnumStatementReturn.STACK_EXCEEDED;
|
return succ ? EnumStatementReturn.OK : EnumStatementReturn.STACK_EXCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes the most recent element from stack and writes it to the buffer
|
// removes the most recent element from stack and writes it to the buffer
|
||||||
if(lower.equals("pop")) {
|
if(lower.equals("pop")) {
|
||||||
String val = ctx.pop();
|
String val = ctx.pop();
|
||||||
@ -73,7 +74,7 @@ public class ParseMSES1Ext1 extends ParseMSES1 {
|
|||||||
ctx.writeBuffer(val);
|
ctx.writeBuffer(val);
|
||||||
return EnumStatementReturn.OK;
|
return EnumStatementReturn.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// writes the most recent element to the buffer
|
// writes the most recent element to the buffer
|
||||||
if(lower.equals("peek")) {
|
if(lower.equals("peek")) {
|
||||||
String val = ctx.peek();
|
String val = ctx.peek();
|
||||||
@ -81,13 +82,13 @@ public class ParseMSES1Ext1 extends ParseMSES1 {
|
|||||||
ctx.writeBuffer(val);
|
ctx.writeBuffer(val);
|
||||||
return EnumStatementReturn.OK;
|
return EnumStatementReturn.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// figures out buffer string's length
|
// figures out buffer string's length
|
||||||
if(lower.equals("length")) {
|
if(lower.equals("length")) {
|
||||||
ctx.writeBuffer("" + ctx.readBuffer().length());
|
ctx.writeBuffer("" + ctx.readBuffer().length());
|
||||||
return EnumStatementReturn.OK;
|
return EnumStatementReturn.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// grabs the first x characters from the buffer and writes them back to the buffer
|
// grabs the first x characters from the buffer and writes them back to the buffer
|
||||||
if(lower.startsWith("first ")) {
|
if(lower.startsWith("first ")) {
|
||||||
if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR;
|
if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR;
|
||||||
@ -111,7 +112,7 @@ public class ParseMSES1Ext1 extends ParseMSES1 {
|
|||||||
return EnumStatementReturn.OK;
|
return EnumStatementReturn.OK;
|
||||||
} catch(Exception x) { return EnumStatementReturn.PARAMETER_ERROR; }
|
} catch(Exception x) { return EnumStatementReturn.PARAMETER_ERROR; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// listens to an RoR signal using the supplied channel name and saves it to the buffer
|
// listens to an RoR signal using the supplied channel name and saves it to the buffer
|
||||||
if(lower.startsWith("poll ")) {
|
if(lower.startsWith("poll ")) {
|
||||||
if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR;
|
if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR;
|
||||||
@ -119,13 +120,13 @@ public class ParseMSES1Ext1 extends ParseMSES1 {
|
|||||||
if(chan != null && chan.timeStamp >= ctx.world.getTotalWorldTime() - 1) ctx.writeBuffer(chan.signal + "");
|
if(chan != null && chan.timeStamp >= ctx.world.getTotalWorldTime() - 1) ctx.writeBuffer(chan.signal + "");
|
||||||
return EnumStatementReturn.OK;
|
return EnumStatementReturn.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// writes the total world time to the buffer
|
// writes the total world time to the buffer
|
||||||
if(lower.equals("worldtime")) {
|
if(lower.equals("worldtime")) {
|
||||||
ctx.writeBuffer("" + ctx.world.getTotalWorldTime());
|
ctx.writeBuffer("" + ctx.world.getTotalWorldTime());
|
||||||
return EnumStatementReturn.OK;
|
return EnumStatementReturn.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.eval(ctx, line);
|
return super.eval(ctx, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user