-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterpreter.cs
More file actions
142 lines (137 loc) · 4.48 KB
/
Interpreter.cs
File metadata and controls
142 lines (137 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace RPGNet
{
class Interpreter
{
public static String getContent(String FileLoc)
{
List<String> Output = new List<String>();
String Line = "";
foreach (String L in File.ReadAllLines(FileLoc))
{
Line = L.Trim();
if (Line.StartsWith("*") || Line.Trim().StartsWith("//"))
{
//Do nothing..
}
else if (Line.StartsWith("/COPY"))
{
Line = Line.Substring(5).Trim();
Output.Add(getContent(Line));
Errors.throwNotice("Copied in " + Line);
}
else
{
Output.Add(Line);
}
}
return String.Join(" ", Output);
}
public static String[] toParts(String In)
{
List<String> Parts = new List<String>();
String Current_Part = "";
Boolean Inside_Speech = false;
foreach (Char c in In.ToCharArray())
{
switch (c)
{
case ';':
if (Inside_Speech == true)
{
Current_Part += c;
}
else
{
Parts.Add(Current_Part.Trim());
Current_Part = "";
}
break;
default:
if (c == '\'')
{
Inside_Speech = !Inside_Speech;
}
Current_Part += c;
break;
}
}
if (Current_Part.Trim() != "")
{
Parts.Add(Current_Part.Trim());
}
return Parts.ToArray();
}
public static Piece[] getPieces(String Part)
{
//This gets the pieces for a statement - not BIFS or procs.
//See issue #6
List<Piece> Pieces = new List<Piece>();
String Current = "";
Boolean SPEECH = false;
int BracketScope = 0;
foreach (Char c in Part.ToCharArray())
{
switch (c)
{
case '\'':
SPEECH = !SPEECH;
Current += c;
break;
case '(':
BracketScope++;
Current += c;
break;
case ')':
BracketScope--;
Current += c;
break;
case ' ':
if (SPEECH == false && BracketScope == 0)
{
Pieces.Add(new Piece(Current));
Current = "";
}
else
{
Current += c;
}
break;
default:
Current += c;
break;
}
}
if (Current != "") Pieces.Add(new Piece(Current));
return Pieces.ToArray();
}
public static Piece[] StringBuilder(Piece[] Input, int Start, int End)
{
List<Piece> Output = new List<Piece>();
for (int Index = Start; Index < End; Index++)
{
Output.Add(Input[Index]);
}
return Output.ToArray();
}
public static String[] parseCall(String Value)
{
String[] Out = new String[2];
int Start, End;
Start = Value.IndexOf('(') + 1;
End = Value.LastIndexOf(')');
if (Start < 0 || End < 0 || (Start - 1) < 0)
{
Errors.throwError("Trying to parse a call/BIF but seems to be failing: " + Value);
}
Out[1] = Value.Substring(Start, int.Parse(Math.Abs(Start - End).ToString())).Trim(); //Params
Out[0] = Value.Substring(0, Start - 1).Trim(); //Name
return Out;
}
}
}