BadScript 2
Loading...
Searching...
No Matches
BadScript2.Parser.BadSourceParser Class Reference

The Parser of the Language. It turns Source Code into an Expression Tree. More...

Public Member Functions

 BadSourceParser (BadSourceReader sourceReader, BadOperatorTable operators)
 Constructor of the Parser.
 
List< BadExpressionParseGenericArguments ()
 
BadExpression ParseExpression (BadExpression? left=null, int precedence=int.MaxValue)
 Parses an Expression with a precedence greater than the given precedence. Moves the reader to the next token.
 
IEnumerable< BadExpressionParse ()
 Parses the File from start to end.
 

Static Public Member Functions

static BadSourceParser Create (string fileName, string source)
 Creates a BadSourceParser Instance based on the source and filename provided.
 
static BadSourceParser Create (string fileName, string source, int start, int end)
 Creates a BadSourceParser Instance based on the source and filename provided.
 
static IEnumerable< BadExpressionParse (string fileName, string source)
 Parses a BadExpression from the Source Reader.
 

Properties

BadSourceReader Reader [get]
 The Source Reader.
 

Private Member Functions

BadExpressionParsePrefix (int precedence)
 Parses a Prefix Expression that has precedence greater than the provided precedence. Moves the Reader to the next Token.
 
BadExpression ParseSwitch ()
 
BadExpression ParseIf ()
 Parses an If Expression. Moves the Reader to the Next Token.
 
BadExpression ParseForEach ()
 Parses a For Each Expression. Moves the Reader to the Next Token.
 
BadExpression ParseLock ()
 Parses a Lock Expression. Moves the Reader to the Next Token.
 
BadExpression ParseFor ()
 Parses a For Loop Expression. Moves the Reader to the Next Token.
 
void ParseMeta ()
 Parses the MetaData of the current expression.
 
BadExpression ParseValue (int precedence)
 Parses a Value Expression or a Prefix Function with precedence greater than the provided precedence. Moves the Reader to the Next Token.
 
BadStringExpression ParseMultiLineFormatString ()
 Parses a Multiline Format string expression. Moves the reader to the next token.
 
BadStringExpression ParseFormatString ()
 Parses a Format Expression. Moves the reader to the next token.
 
BadWhileExpression ParseWhile ()
 Parses a While Loop. Moves the reader to the next token.
 
List< BadExpressionParseBlock (out bool isSingleLine)
 Parses a Block Expression. Moves the reader to the next token.
 
List< BadExpressionParseFunctionBlock (int start, out bool isSingleLine)
 Parses a Block. Moves the reader to the next token.
 
BadExpression ParseUsingStatement (int start)
 Parses a Using Statement Expression. Moves the reader to the next token.
 
BadExpression ParseUsing ()
 Parses a Using Block or Statement. Moves the reader to the next token.
 
BadExpression ParseTry ()
 Parses a Try Catch Block. Moves the reader to the next token.
 
BadNewExpression ParseNew ()
 Parses a New Expression. Moves the reader to the next token.
 
BadInterfaceConstraint ParseInterfaceConstraint ()
 Parses an Interface Constraint. Moves the reader to the next token.
 
List< BadWordTokenParseGenericParameters ()
 
BadInterfacePrototypeExpression ParseInterface ()
 Parses an Interface prototype. Moves the reader to the next token.
 
BadClassPrototypeExpression ParseClass ()
 Parses a Class Structure. Moves the reader to the next token.
 
BadFunctionParameter ParseParameter ()
 Parses a Function Parameter. Moves the reader to the next token.
 
List< BadFunctionParameterParseParameters (int start)
 Parses a Function Parameter List. Moves the reader to the next token.
 
BadFunctionExpression ParseFunction (int start, string? functionName, BadExpression? functionReturn, bool isConstant, bool isStatic, BadFunctionCompileLevel compileLevel, List< BadFunctionParameter > parameters)
 Parses a Function Definition. Moves the reader to the next token.
 
BadFunctionExpression ParseFunction (bool isConstant, bool isStatic, BadFunctionCompileLevel compileLevel)
 Parses a function definition. Moves the reader to the next token.
 

Static Private Member Functions

static bool RequireSemicolon (BadExpression expr)
 Returns true if the given expression requires a semicolon.
 

Private Attributes

readonly BadOperatorTable m_Operators
 The Operator Table that is used to parse the Source Code.
 
BadMetaDatam_MetaData
 The Meta Data of the current expression.
 

Detailed Description

The Parser of the Language. It turns Source Code into an Expression Tree.

Definition at line 32 of file BadSourceParser.cs.

Constructor & Destructor Documentation

◆ BadSourceParser()

BadScript2.Parser.BadSourceParser.BadSourceParser ( BadSourceReader  sourceReader,
BadOperatorTable  operators 
)

Constructor of the Parser.

Parameters
sourceReaderThe Source Reader
operatorsThe Operator Table that is used to parse the Source Code

Definition at line 49 of file BadSourceParser.cs.

50 {
51 Reader = sourceReader;
52 m_Operators = operators;
53 }
BadSourceReader Reader
The Source Reader.
readonly BadOperatorTable m_Operators
The Operator Table that is used to parse the Source Code.

Member Function Documentation

◆ Create() [1/2]

static BadSourceParser BadScript2.Parser.BadSourceParser.Create ( string  fileName,
string  source 
)
static

Creates a BadSourceParser Instance based on the source and filename provided.

Parameters
fileNameFile Name of the Source File
sourceContents of the Source File
Returns
BadSourceParser Instance

Definition at line 66 of file BadSourceParser.cs.

67 {
68 return new BadSourceParser(new BadSourceReader(fileName, source), BadOperatorTable.Instance);
69 }
BadSourceParser(BadSourceReader sourceReader, BadOperatorTable operators)
Constructor of the Parser.
Implements the Operator Table used by the Parser.
static BadOperatorTable Instance
The Operator Table Instance.
Implements the Source Code Reader.

◆ Create() [2/2]

static BadSourceParser BadScript2.Parser.BadSourceParser.Create ( string  fileName,
string  source,
int  start,
int  end 
)
static

Creates a BadSourceParser Instance based on the source and filename provided.

Parameters
fileNameFile Name of the Source File
sourceContents of the Source File
startStart Index of the Source File
endEnd Index of the Source File
Returns
BadSourceParser Instance

Definition at line 79 of file BadSourceParser.cs.

80 {
81 return new BadSourceParser(new BadSourceReader(fileName, source, start, end), BadOperatorTable.Instance);
82 }

◆ Parse() [1/2]

IEnumerable< BadExpression > BadScript2.Parser.BadSourceParser.Parse ( )

Parses the File from start to end.

Returns
Returns an Enumerable of BadExpressions

Definition at line 2432 of file BadSourceParser.cs.

2433 {
2434 Reader.SkipNonToken();
2435
2436 while (!Reader.IsEof())
2437 {
2438 Reader.SkipNonToken();
2440 Reader.SkipNonToken();
2441
2442 if (!RequireSemicolon(expr))
2443 {
2444 Reader.SkipNonToken();
2445
2446 yield return expr;
2447
2448 continue;
2449 }
2450
2452 Reader.SkipNonToken();
2453
2454 yield return expr;
2455 }
2456 }
Contains Static Data for the BadScript Language.
static bool RequireSemicolon(BadExpression expr)
Returns true if the given expression requires a semicolon.
BadExpression ParseExpression(BadExpression? left=null, int precedence=int.MaxValue)
Parses an Expression with a precedence greater than the given precedence. Moves the reader to the nex...
Base Implementation for all Expressions used inside the Script.
bool IsEof(int offset=0)
Returns true if the reader is at the end of the source code.
BadSourcePosition Eat(char c)
Asserts that the current character matches the specified character.

◆ Parse() [2/2]

static IEnumerable< BadExpression > BadScript2.Parser.BadSourceParser.Parse ( string  fileName,
string  source 
)
static

Parses a BadExpression from the Source Reader.

Parameters
fileNameFile Name of the Source File
sourceContents of the Source File
Returns
The Parsed Expression

Definition at line 90 of file BadSourceParser.cs.

91 {
92 return Create(fileName, source).Parse();
93 }
static BadSourceParser Create(string fileName, string source)
Creates a BadSourceParser Instance based on the source and filename provided.
static IEnumerable< BadExpression > Parse(string fileName, string source)
Parses a BadExpression from the Source Reader.

◆ ParseBlock()

List< BadExpression > BadScript2.Parser.BadSourceParser.ParseBlock ( out bool  isSingleLine)
private

Parses a Block Expression. Moves the reader to the next token.

Parameters
isSingleLineIndicates if the Block is in single line format.
Returns
List of Parsed Expressions

Definition at line 1436 of file BadSourceParser.cs.

1437 {
1438 Reader.SkipNonToken();
1439
1440 List<BadExpression> block = new List<BadExpression>();
1441
1442 if (Reader.Is('{'))
1443 {
1444 isSingleLine = false;
1445 Reader.Eat('{');
1446 Reader.SkipNonToken();
1447
1449 {
1450 Reader.SkipNonToken();
1452 block.Add(expr);
1453 Reader.SkipNonToken();
1454
1455 if (!RequireSemicolon(expr))
1456 {
1457 continue;
1458 }
1459
1461 Reader.SkipNonToken();
1462 }
1463
1465 }
1466 else
1467 {
1468 isSingleLine = true;
1470
1471 if (RequireSemicolon(expr))
1472 {
1474 }
1475
1476 Reader.SkipNonToken();
1477 block.Add(expr);
1478 }
1479
1480 Reader.SkipNonToken();
1481
1482 return block;
1483 }
bool Is(char c, int offset=0)
Returns true if the current character matches the specified character.

◆ ParseClass()

BadClassPrototypeExpression BadScript2.Parser.BadSourceParser.ParseClass ( )
private

Parses a Class Structure. Moves the reader to the next token.

Returns
Instance of a BadClassPrototypeExpression

Definition at line 1900 of file BadSourceParser.cs.

1901 {
1902 BadMetaData? meta = m_MetaData;
1903 m_MetaData = null;
1904 int start = Reader.CurrentIndex;
1906 Reader.SkipNonToken();
1907 BadWordToken name = Reader.ParseWord();
1908 Reader.SkipNonToken();
1909 List<BadWordToken> genericParameters = ParseGenericParameters();
1910
1911 List<BadFunctionParameter>? primaryConstructor = null;
1912 List<BadExpression>? baseInvocationParameters = null;
1913 BadSourcePosition? primaryConstructorPosition = null;
1914 BadSourcePosition? baseInvocationParametersPosition = null;
1915 List<BadExpression> members = new List<BadExpression>();
1916 List<BadExpression> staticMembers = new List<BadExpression>();
1917 if (Reader.Is('('))
1918 {
1919 int ctorStart = Reader.CurrentIndex;
1920 primaryConstructor = ParseParameters(start);
1921 primaryConstructorPosition = Reader.MakeSourcePosition(ctorStart, Reader.CurrentIndex - ctorStart);
1922 Reader.SkipNonToken();
1923 }
1924
1925 List<BadExpression> baseClasses = new List<BadExpression>();
1926
1927 if (Reader.Is(':'))
1928 {
1929 Reader.Eat(':');
1930
1931 while (!Reader.IsEof())
1932 {
1933 Reader.SkipNonToken();
1934 BadExpression baseExpr = ParseExpression();
1935 if (baseClasses.Count == 0)
1936 {
1937 if (baseExpr is BadInvocationExpression baseInvoc)
1938 {
1939 baseInvocationParameters = baseInvoc.Arguments.ToList();
1940 baseInvocationParametersPosition = baseInvoc.Position;
1941 baseExpr = baseInvoc.Left;
1942 }
1943 }
1944 else if (baseExpr is BadInvocationExpression)
1945 {
1946 throw new BadParserException(
1947 "Base Class Invocation must be the first base class",
1948 baseExpr.Position
1949 );
1950 }
1951
1952 baseClasses.Add(baseExpr);
1953 Reader.SkipNonToken();
1954
1955 if (!Reader.Is(','))
1956 {
1957 break;
1958 }
1959
1960 Reader.Eat(',');
1961 Reader.SkipNonToken();
1962 }
1963 }
1964
1966 {
1967 Reader.Eat('{');
1968 Reader.SkipNonToken();
1969
1970 List<BadExpression> attributeExpressions = new List<BadExpression>();
1971
1972 while (!Reader.Is('}'))
1973 {
1974 Reader.SkipNonToken();
1975
1976 bool isAttribute = false;
1977 if (Reader.Is('@') && !Reader.Is('|', 1))
1978 {
1979 Reader.Eat('@');
1980 isAttribute = true;
1981 }
1983 if (isAttribute)
1984 {
1985 attributeExpressions.Add(expr);
1986 Reader.SkipNonToken();
1987 continue;
1988 }
1989
1990 if (expr is BadFunctionExpression
1991 {
1992 IsStatic: true,
1993 })
1994 {
1995 staticMembers.Add(expr);
1996 }
1997 else if (expr is BadFunctionExpression fExpr && fExpr.Name?.Text == name.Text)
1998 {
1999 if (primaryConstructor != null)
2000 {
2001 throw new BadParserException(
2002 "Primary Constructor already defined",
2003 expr.Position
2004 );
2005 }
2006
2007 fExpr.SetName(BadStaticKeys.CONSTRUCTOR_NAME);
2008 members.Add(expr);
2009 }
2010 else
2011 {
2012 members.Add(expr);
2013 }
2014 if (attributeExpressions.Count > 0)
2015 {
2016 expr.SetAttributes(attributeExpressions.ToArray());
2017 attributeExpressions.Clear();
2018 }
2019
2020 if (expr is IBadNamedExpression nExpr && nExpr.GetName() == name.Text)
2021 {
2022 throw new BadParserException(
2023 "Class Member cannot have the same name as the class",
2024 expr.Position
2025 );
2026 }
2027
2028 Reader.SkipNonToken();
2029
2030 if (RequireSemicolon(expr))
2031 {
2033 }
2034
2035 Reader.SkipNonToken();
2036 }
2037
2038 if (attributeExpressions.Count != 0)
2039 {
2040 throw new BadParserException(
2041 "Attributes without target",
2043 );
2044 }
2045
2046 Reader.Eat('}');
2047 }
2048 else
2049 {
2051 }
2052
2053 Reader.SkipNonToken();
2054 if (primaryConstructor != null)
2055 {
2056 List<BadExpression> block = new List<BadExpression>();
2057
2058 //2. Add the primary constructor as a function to the class
2059 BadFunctionExpression ctor = new BadFunctionExpression(BadStaticKeys.CONSTRUCTOR_NAME, primaryConstructor, block, primaryConstructorPosition!, false, null, false, false);
2060 members.Add(ctor);
2061 if (baseInvocationParameters != null)
2062 {
2063 // 2.1. (call base class constructor if baseInvocationParameters is not null)
2065 new BadVariableExpression("base", primaryConstructorPosition!),
2066 baseInvocationParameters,
2067 baseInvocationParametersPosition!
2068 );
2069 block.Add(baseInvocation);
2070 }
2071 else
2072 {
2073 BadVariableExpression thisExpr = new BadVariableExpression(BadStaticKeys.THIS_KEY, primaryConstructorPosition!);
2074 foreach (BadFunctionParameter parameter in primaryConstructor)
2075 {
2076 // 2.2. (if baseInvocationParameters is null, assign the parameters to the class members)
2077 // this.{parameter.Name} = {parameter.Name};
2078 block.Add(
2080 new BadMemberAccessExpression(thisExpr, parameter.Name, primaryConstructorPosition!, new List<BadExpression>()),
2081 new BadVariableExpression(parameter.Name, primaryConstructorPosition!),
2082 primaryConstructorPosition!
2083 )
2084 );
2085
2086 //3. (if baseInvocationParameters is null, define the properties for the parameters)
2087 //let {type} {parameter.Name};
2088 members.Add(new BadVariableDefinitionExpression(parameter.Name, primaryConstructorPosition!, parameter.TypeExpr, true));
2089 }
2090 }
2091 }
2092
2093 return new BadClassPrototypeExpression(
2094 name.Text,
2095 members.ToArray(),
2096 staticMembers.ToArray(),
2097 baseClasses.ToArray(),
2099 meta,
2100 genericParameters.ToArray()
2101 );
2102 }
Describes a specific position inside a source file.
List< BadWordToken > ParseGenericParameters()
BadMetaData? m_MetaData
The Meta Data of the current expression.
List< BadFunctionParameter > ParseParameters(int start)
Parses a Function Parameter List. Moves the reader to the next token.
Implements the Member Access to set or get properties from an object. LEFT.RIGHT.
BadSourcePosition Position
The source Position of the Expression.
void SetAttributes(IEnumerable< BadExpression > attributes)
Implements the Assign Expression LEFT = RIGHT.
BadSourcePosition MakeSourcePosition(int length)
Creates a source position with the specified length and the current index of the reader.
int CurrentIndex
The Current Index of the Reader.
string Text
The Text Representation of the Token.
Definition BadToken.cs:27
BadExpression? TypeExpr
The Expression that returns the type of the parameter if evaluated.
Gets inherited by all Expressions that have a Name(e.g. Variable Definitions, Function Definitions,...
string? GetName()
Returns the Name of the Expression.

◆ ParseExpression()

BadExpression BadScript2.Parser.BadSourceParser.ParseExpression ( BadExpression left = null,
int  precedence = int::MaxValue 
)

Parses an Expression with a precedence greater than the given precedence. Moves the reader to the next token.

Parameters
leftThe (optional) Left side of the expression
precedenceThe Minimum Precedence
Returns
Parsed Expression

Definition at line 1047 of file BadSourceParser.cs.

1048 {
1049 left ??= ParseValue(precedence);
1050
1051 while (!Reader.IsEof())
1052 {
1053 Reader.SkipNonToken();
1054
1056 {
1057 return left;
1058 }
1059
1060
1061 if (Reader.Is('[') || Reader.Is("?["))
1062 {
1063 bool isNullChecked = Reader.Is("?[");
1064
1065 if (isNullChecked)
1066 {
1067 Reader.Eat("?[");
1068 }
1069 else
1070 {
1071 Reader.Eat('[');
1072 }
1073
1074 Reader.SkipNonToken();
1075 bool isReverse = false;
1076
1077 if (Reader.Is('^'))
1078 {
1079 Reader.Eat('^');
1080 isReverse = true;
1081 }
1082
1083 List<BadExpression> indices = new List<BadExpression>();
1084
1085 if (!Reader.Is(']'))
1086 {
1087 bool readNext;
1088
1089 do
1090 {
1091 readNext = false;
1092 Reader.SkipNonToken();
1093 indices.Add(ParseExpression());
1094
1095 Reader.SkipNonToken();
1096
1097 if (Reader.Is(','))
1098 {
1099 readNext = true;
1100 Reader.Eat(',');
1101 }
1102
1103 Reader.SkipNonToken();
1104 }
1105 while (readNext);
1106 }
1107
1108 BadSourcePosition end = Reader.Eat(']');
1109 Reader.SkipNonToken();
1110
1111 if (isReverse)
1112 {
1114 left,
1115 indices.ToArray(),
1116 left.Position.Combine(end),
1117 isNullChecked
1118 );
1119 }
1120 else
1121 {
1122 left = new BadArrayAccessExpression(
1123 left,
1124 indices.ToArray(),
1125 left.Position.Combine(end),
1126 isNullChecked
1127 );
1128 }
1129
1130 continue;
1131 }
1132
1133 if (Reader.Is('('))
1134 {
1135 Reader.Eat('(');
1136 Reader.SkipNonToken();
1137 List<BadExpression> args = new List<BadExpression>();
1138
1139 if (!Reader.Is(')'))
1140 {
1141 bool readNext;
1142
1143 do
1144 {
1145 readNext = false;
1146 Reader.SkipNonToken();
1147 args.Add(ParseExpression());
1148
1149 Reader.SkipNonToken();
1150
1151 if (Reader.Is(','))
1152 {
1153 readNext = true;
1154 Reader.Eat(',');
1155 }
1156
1157 Reader.SkipNonToken();
1158 }
1159 while (readNext);
1160 }
1161
1163 Reader.Eat(')');
1164 left = new BadInvocationExpression(left, args.ToArray(), left.Position.Combine(rightPos));
1165 Reader.SkipNonToken();
1166
1167 continue;
1168 }
1169
1170 // Parse Symbol
1171 BadSymbolToken? symbol = Reader.TryParseSymbols(m_Operators.BinarySymbols);
1172
1173 if (symbol == null)
1174 {
1175 return left;
1176 }
1177
1178 BadBinaryOperator? op = m_Operators.FindBinaryOperator(symbol.Text, precedence);
1179
1180
1181 if (op == null)
1182 {
1184
1185 return left;
1186 }
1187
1188 left = op.Parse(left, this);
1189 }
1190
1191 return left;
1192 }
int Index
The Start Index of the Position.
BadExpression ParseValue(int precedence)
Parses a Value Expression or a Prefix Function with precedence greater than the provided precedence....
Implements the Array Access to set or get properties from an object. LEFT[RIGHT].
Implements the Reverse Array Access to set or get properties from an object. LEFT[^RIGHT].
Base class for all binary operators.
BadExpression Parse(BadExpression left, BadSourceParser parser)
Parses the operator.
IEnumerable< string > BinarySymbols
Enumeration of all Binary Operator Symbols.
BadBinaryOperator? FindBinaryOperator(string symbol, int precedence)
Finds a Binary Operator by its Symbol.
void SetPosition(int index)
Sets the Current Index of the Reader.
BadSourcePosition SourcePosition
The Source Position of the Token.
Definition BadToken.cs:22

◆ ParseFor()

BadExpression BadScript2.Parser.BadSourceParser.ParseFor ( )
private

Parses a For Loop Expression. Moves the Reader to the Next Token.

Returns
Instance of BadForExpression

Definition at line 286 of file BadSourceParser.cs.

287 {
288 int start = Reader.CurrentIndex;
290 Reader.SkipNonToken();
291 Reader.Eat('(');
292 Reader.SkipNonToken();
294 Reader.SkipNonToken();
296 Reader.SkipNonToken();
297 BadExpression condition = ParseExpression();
298 Reader.SkipNonToken();
300 Reader.SkipNonToken();
302 Reader.SkipNonToken();
303 Reader.Eat(')');
304 Reader.SkipNonToken();
305 List<BadExpression> block = ParseBlock(out bool _);
306 Reader.SkipNonToken();
307
308 return new BadForExpression(
309 vDef,
310 condition,
311 vInc,
312 block.ToArray(),
314 );
315 }
List< BadExpression > ParseBlock(out bool isSingleLine)
Parses a Block Expression. Moves the reader to the next token.

◆ ParseForEach()

BadExpression BadScript2.Parser.BadSourceParser.ParseForEach ( )
private

Parses a For Each Expression. Moves the Reader to the Next Token.

Returns
Instance of BadForEachExpression

Definition at line 230 of file BadSourceParser.cs.

231 {
232 int start = Reader.CurrentIndex;
234 Reader.SkipNonToken();
235 Reader.Eat('(');
236 Reader.SkipNonToken();
237 BadWordToken variableName = Reader.ParseWord();
238 Reader.SkipNonToken();
239 Reader.Eat("in");
240 Reader.SkipNonToken();
241 BadExpression collection = ParseExpression();
242 Reader.SkipNonToken();
243 Reader.Eat(')');
244 Reader.SkipNonToken();
245 List<BadExpression> block = ParseBlock(out bool _);
246 Reader.SkipNonToken();
247
248 return new BadForEachExpression(
249 collection,
250 variableName,
251 block.ToArray(),
253 );
254 }

◆ ParseFormatString()

BadStringExpression BadScript2.Parser.BadSourceParser.ParseFormatString ( )
private

Parses a Format Expression. Moves the reader to the next token.

Returns
Instance of BadStringExpression if no Format Parameters are found. Instance of BadFormattedStringExpression otherwise.
Exceptions
BadSourceReaderExceptionGets Raised if the First Character sequence is not BadStaticKeys.FormatStringKey
BadParserExceptionGets Raised if the string is not properly Terminated.

Definition at line 1303 of file BadSourceParser.cs.

1304 {
1306 {
1307 throw new BadSourceReaderException(
1308 $"Expected string start character but got '{(Reader.IsEof() ? "EOF" : Reader.GetCurrentChar())}'",
1310 );
1311 }
1312
1313 int start = Reader.CurrentIndex;
1315 bool isEscaped = false;
1316 StringBuilder sb = new StringBuilder();
1317 List<BadExpression> args = new List<BadExpression>();
1318
1319 while (!Reader.IsStringQuote())
1320 {
1321 if (Reader.IsNewLine() || Reader.IsEof())
1322 {
1323 throw new BadSourceReaderException(
1324 "String not terminated",
1326 );
1327 }
1328
1329 if (Reader.Is('{'))
1330 {
1331 Reader.Eat('{');
1332 Reader.SkipNonToken();
1333
1334 if (!Reader.Is('{'))
1335 {
1337 Reader.SkipNonToken();
1338 Reader.Eat('}');
1339 sb.Append($"{{{args.Count}}}");
1340 args.Add(expr);
1341
1342 continue;
1343 }
1344
1345 Reader.Eat('{');
1346 sb.Append("{{");
1347
1348 continue;
1349 }
1350
1351 if (Reader.Is('}'))
1352 {
1353 int idx = Reader.CurrentIndex;
1354 Reader.Eat('}');
1355
1356 if (!Reader.Is('}'))
1357 {
1358 throw new BadParserException(
1359 "Expected '}'",
1361 );
1362 }
1363
1364 Reader.Eat('}');
1365 sb.Append("}}");
1366
1367 continue;
1368 }
1369
1371 {
1372 isEscaped = true;
1373 Reader.MoveNext();
1374 }
1375
1376 if (isEscaped)
1377 {
1378 isEscaped = false;
1379 sb.Append(Regex.Unescape($"\\{Reader.GetCurrentChar()}"));
1380 }
1381 else
1382 {
1383 sb.Append(Reader.GetCurrentChar());
1384 }
1385
1386 Reader.MoveNext();
1387 }
1388
1390
1391 if (args.Count == 0)
1392 {
1393 var str = sb.ToString()
1394 .Replace("{{", "{")
1395 .Replace("}}", "}");
1396 return new BadStringExpression(
1397 '"' + str + '"',
1399 );
1400 }
1401
1403 args.ToArray(),
1404 sb.ToString(),
1406 );
1407 }
Gets Raised if the Reader encounters an Error.
void MoveNext()
Moves the Reader to the next character in the source code.
char GetCurrentChar(int offset=0)
Returns the Current Character.

◆ ParseFunction() [1/2]

BadFunctionExpression BadScript2.Parser.BadSourceParser.ParseFunction ( bool  isConstant,
bool  isStatic,
BadFunctionCompileLevel  compileLevel 
)
private

Parses a function definition. Moves the reader to the next token.

Parameters
isConstantIndicates that the function is declared as a constant. I.e. it is readonly inside the scope it is executed in
isStaticIs the Function Static
compileLevelThe Compile level of the Function
Returns
Instance of BadFunctionExpression
Exceptions
BadParserExceptionGets raised if the function header is invalid.

Definition at line 2339 of file BadSourceParser.cs.

2340 {
2341 int start = Reader.CurrentIndex;
2343 Reader.SkipNonToken();
2344
2345 string? functionName = null;
2346 BadExpression? functionReturn = null;
2347
2348 if (!Reader.Is('('))
2349 {
2350 BadExpression functionNameExpr = ParseValue(0);
2351 Reader.SkipNonToken();
2352
2353 while (Reader.Is("."))
2354 {
2355 Reader.Eat(".");
2356 BadWordToken right = Reader.ParseWord();
2357 List<BadExpression>? genArgs = ParseGenericArguments();
2358 functionNameExpr = new BadMemberAccessExpression(
2359 functionNameExpr,
2360 right,
2361 functionNameExpr.Position.Combine(right.SourcePosition),
2362 genArgs
2363 );
2364 Reader.SkipNonToken();
2365 }
2366
2367 Reader.SkipNonToken();
2368
2369 if (!Reader.Is('('))
2370 {
2371 functionReturn = functionNameExpr;
2372 functionName = Reader.ParseWord().Text;
2373 }
2374 else
2375 {
2376 if (functionNameExpr is not BadVariableExpression expr)
2377 {
2378 throw new BadParserException(
2379 "Expected Variable Expression",
2380 functionNameExpr.Position
2381 );
2382 }
2383
2384 functionName = expr.Name;
2385 }
2386 }
2387
2388 List<BadFunctionParameter> parameters = ParseParameters(start);
2389
2390 return ParseFunction(start, functionName, functionReturn, isConstant, isStatic, compileLevel, parameters);
2391 }
BadSourcePosition Combine(BadSourcePosition other)
Combines two Source Positions.
BadFunctionExpression ParseFunction(int start, string? functionName, BadExpression? functionReturn, bool isConstant, bool isStatic, BadFunctionCompileLevel compileLevel, List< BadFunctionParameter > parameters)
Parses a Function Definition. Moves the reader to the next token.
List< BadExpression > ParseGenericArguments()

◆ ParseFunction() [2/2]

BadFunctionExpression BadScript2.Parser.BadSourceParser.ParseFunction ( int  start,
string?  functionName,
BadExpression functionReturn,
bool  isConstant,
bool  isStatic,
BadFunctionCompileLevel  compileLevel,
List< BadFunctionParameter parameters 
)
private

Parses a Function Definition. Moves the reader to the next token.

Parameters
startThe Start index of parent expression
functionNameThe Name of the Function
functionReturnThe Return Expression of the Function
isConstantIndicates that the function is declared as a constant. I.e. the result will be cached
isStaticIndicates that the function is declared as static. I.e. it can be called without an instance
compileLevelThe Compile level of the Function
parametersThe Parameters of the Function
Returns
Instance of BadFunctionExpression

Definition at line 2280 of file BadSourceParser.cs.

2288 {
2289 BadMetaData? meta = m_MetaData;
2290 m_MetaData = null;
2291 List<BadExpression> block = ParseFunctionBlock(start, out bool isSingleLine);
2292
2293 if (isSingleLine)
2294 {
2295 block[0] = new BadReturnExpression(block[0], block[0].Position, false);
2296 }
2297
2298 if (functionName == null)
2299 {
2300 return new BadFunctionExpression(
2301 null,
2302 parameters,
2303 block,
2305 isConstant,
2306 meta,
2307 isSingleLine,
2308 isStatic,
2309 compileLevel,
2310 functionReturn
2311 );
2312 }
2313
2314 return new BadFunctionExpression(
2315 functionName,
2316 parameters,
2317 block,
2319 isConstant,
2320 meta,
2321 isSingleLine,
2322 isStatic,
2323 compileLevel,
2324 functionReturn
2325 );
2326 }
List< BadExpression > ParseFunctionBlock(int start, out bool isSingleLine)
Parses a Block. Moves the reader to the next token.
Implements the Return expression that is used to exit the current function with an Optional Return Va...

◆ ParseFunctionBlock()

List< BadExpression > BadScript2.Parser.BadSourceParser.ParseFunctionBlock ( int  start,
out bool  isSingleLine 
)
private

Parses a Block. Moves the reader to the next token.

Parameters
startThe Start index of the loop
isSingleLineIndicates if the Block is in single line format.
Returns
List of Parsed Expressions
Exceptions
BadParserExceptionGets Raised if there is no block start character and no single-line block start sequence.

Definition at line 1495 of file BadSourceParser.cs.

1496 {
1497 Reader.SkipNonToken();
1498
1499 List<BadExpression> block = new List<BadExpression>();
1500
1501 if (Reader.Is("=>"))
1502 {
1503 Reader.Eat("=>");
1504 block.Add(ParseExpression());
1505 isSingleLine = true;
1506 }
1507 else if (Reader.Is('{'))
1508 {
1509 isSingleLine = false;
1510 Reader.Eat('{');
1511 Reader.SkipNonToken();
1512
1514 {
1515 Reader.SkipNonToken();
1517 block.Add(expr);
1518 Reader.SkipNonToken();
1519
1520 if (!RequireSemicolon(expr))
1521 {
1522 continue;
1523 }
1524
1526 Reader.SkipNonToken();
1527 }
1528
1530 }
1531 else
1532 {
1533 throw new BadParserException(
1534 "Expected Expression Body",
1536 );
1537 }
1538
1539 Reader.SkipNonToken();
1540
1541 return block;
1542 }

◆ ParseGenericArguments()

List< BadExpression > BadScript2.Parser.BadSourceParser.ParseGenericArguments ( )

Definition at line 1004 of file BadSourceParser.cs.

1005 {
1006 List<BadExpression> typeArgs = new List<BadExpression>();
1007 if (Reader.Is('<'))
1008 {
1009 int genStart = Reader.CurrentIndex;
1010 try
1011 {
1012 Reader.Eat('<');
1013 Reader.SkipNonToken();
1014 while (true)
1015 {
1016 BadExpression? expr = ParseExpression(null, 3);
1017 typeArgs.Add(expr);
1018 Reader.SkipNonToken();
1019 if (!Reader.Is(','))
1020 {
1021 break;
1022 }
1023 Reader.Eat(',');
1024 Reader.SkipNonToken();
1025 }
1026
1027 Reader.Eat('>');
1028
1029 Reader.SkipNonToken();
1030 }
1031 catch (Exception)
1032 {
1033 Reader.SetPosition(genStart);
1034 typeArgs.Clear();
1035 }
1036 }
1037
1038 return typeArgs;
1039 }

◆ ParseGenericParameters()

List< BadWordToken > BadScript2.Parser.BadSourceParser.ParseGenericParameters ( )
private

Definition at line 1807 of file BadSourceParser.cs.

1808 {
1809 List<BadWordToken> genericParameters = new List<BadWordToken>();
1810 Reader.SkipNonToken();
1811 if (Reader.Is('<'))
1812 {
1813 Reader.Eat('<');
1814 Reader.SkipNonToken();
1815 while (!Reader.IsEof())
1816 {
1817 genericParameters.Add(Reader.ParseWord());
1818 Reader.SkipNonToken();
1819 if (Reader.Is('>'))
1820 {
1821 break;
1822 }
1823 Reader.Eat(',');
1824 Reader.SkipNonToken();
1825 }
1826 Reader.Eat('>');
1827 Reader.SkipNonToken();
1828 }
1829
1830 return genericParameters;
1831 }

◆ ParseIf()

BadExpression BadScript2.Parser.BadSourceParser.ParseIf ( )
private

Parses an If Expression. Moves the Reader to the Next Token.

Returns
BadIfExpression Instance

Definition at line 175 of file BadSourceParser.cs.

176 {
177 int start = Reader.CurrentIndex;
178
179 Dictionary<BadExpression, BadExpression[]> conditionMap = new Dictionary<BadExpression, BadExpression[]>();
180
181 bool readNext;
182 bool isElse;
183
184 do
185 {
186 readNext = false;
187 isElse = false;
189 Reader.SkipNonToken();
190 Reader.Eat('(');
191 Reader.SkipNonToken();
192 BadExpression condition = ParseExpression();
193 Reader.SkipNonToken();
194 Reader.Eat(')');
195 Reader.SkipNonToken();
196 List<BadExpression> block = ParseBlock(out bool _);
197 Reader.SkipNonToken();
198 conditionMap[condition] = block.ToArray();
199
200 if (!Reader.IsKey(BadStaticKeys.ELSE_KEY))
201 {
202 continue;
203 }
204
206 isElse = true;
207 Reader.SkipNonToken();
208 readNext = Reader.IsKey(BadStaticKeys.IF_KEY);
209 }
210 while (readNext);
211
212 BadExpression[]? elseBlock = null;
213
214 if (isElse)
215 {
216 elseBlock = ParseBlock(out bool _).ToArray();
217 }
218
219 return new BadIfExpression(
220 conditionMap,
221 elseBlock,
223 );
224 }
Implements the If Statement Expression.

◆ ParseInterface()

BadInterfacePrototypeExpression BadScript2.Parser.BadSourceParser.ParseInterface ( )
private

Parses an Interface prototype. Moves the reader to the next token.

Returns
Instance of BadInterfacePrototypeExpression

Definition at line 1837 of file BadSourceParser.cs.

1838 {
1839 BadMetaData? meta = m_MetaData;
1840 m_MetaData = null;
1841 int start = Reader.CurrentIndex;
1843 Reader.SkipNonToken();
1844 BadWordToken name = Reader.ParseWord();
1845 List<BadWordToken> genericParameters = ParseGenericParameters();
1846 Reader.SkipNonToken();
1847 List<BadExpression> interfaces = new List<BadExpression>();
1848
1849 if (Reader.Is(':'))
1850 {
1851 Reader.Eat(':');
1852
1853 while (!Reader.IsEof())
1854 {
1855 Reader.SkipNonToken();
1856 interfaces.Add(ParseExpression());
1857 Reader.SkipNonToken();
1858
1859 if (!Reader.Is(','))
1860 {
1861 break;
1862 }
1863
1864 Reader.Eat(',');
1865 Reader.SkipNonToken();
1866 }
1867 }
1868
1869 Reader.Eat('{');
1870 Reader.SkipNonToken();
1871 List<BadInterfaceConstraint> constraints = new List<BadInterfaceConstraint>();
1872
1873 while (!Reader.Is('}'))
1874 {
1875 Reader.SkipNonToken();
1877
1878 constraints.Add(expr);
1879
1880 Reader.SkipNonToken();
1881 }
1882
1883 Reader.Eat('}');
1884 Reader.SkipNonToken();
1885
1887 name.Text,
1888 constraints.ToArray(),
1889 interfaces.ToArray(),
1890 meta,
1892 genericParameters.ToArray()
1893 );
1894 }
BadInterfaceConstraint ParseInterfaceConstraint()
Parses an Interface Constraint. Moves the reader to the next token.

◆ ParseInterfaceConstraint()

BadInterfaceConstraint BadScript2.Parser.BadSourceParser.ParseInterfaceConstraint ( )
private

Parses an Interface Constraint. Moves the reader to the next token.

Returns
Instance of BadInterfaceConstraint
Exceptions
BadParserExceptionGets raised if the interface constraint is malformed.

Definition at line 1734 of file BadSourceParser.cs.

1735 {
1736 int start = Reader.CurrentIndex;
1737 string? name = null;
1738 BadExpression? type = null;
1739
1740 if (!Reader.Is('('))
1741 {
1742 BadExpression nameExpr = ParseValue(0);
1743 Reader.SkipNonToken();
1744
1745 while (Reader.Is("."))
1746 {
1747 Reader.Eat(".");
1748 BadWordToken right = Reader.ParseWord();
1749 List<BadExpression>? genArgs = ParseGenericArguments();
1750 nameExpr = new BadMemberAccessExpression(
1751 nameExpr,
1752 right,
1753 nameExpr.Position.Combine(right.SourcePosition),
1754 genArgs
1755 );
1756 Reader.SkipNonToken();
1757 }
1758
1759 Reader.SkipNonToken();
1760
1761 if (!Reader.Is('('))
1762 {
1763 type = nameExpr;
1764 name = Reader.ParseWord().Text;
1765 }
1766 else
1767 {
1768 if (nameExpr is not BadVariableExpression expr)
1769 {
1770 throw new BadParserException(
1771 "Expected Variable Expression",
1772 nameExpr.Position
1773 );
1774 }
1775
1776 name = expr.Name;
1777 }
1778 }
1779
1780 if (name == null)
1781 {
1782 throw new BadParserException(
1783 "Expected Name",
1785 );
1786 }
1787
1788 Reader.SkipNonToken();
1789 if (Reader.Is('('))
1790 {
1791 List<BadFunctionParameter> parameters = ParseParameters(start);
1792
1793 Reader.SkipNonToken();
1794
1796
1797
1798 return new BadInterfaceFunctionConstraint(name, type, parameters.ToArray());
1799 }
1800
1801
1803
1804 return new BadInterfacePropertyConstraint(name, type);
1805 }
Implements a Function Constraint for an Interface The Constraints specifies how a specific function s...

◆ ParseLock()

BadExpression BadScript2.Parser.BadSourceParser.ParseLock ( )
private

Parses a Lock Expression. Moves the Reader to the Next Token.

Returns
Instance of BadLockExpression

Definition at line 261 of file BadSourceParser.cs.

262 {
263 int start = Reader.CurrentIndex;
265 Reader.SkipNonToken();
266 Reader.Eat('(');
267 Reader.SkipNonToken();
268 BadExpression collection = ParseExpression();
269 Reader.SkipNonToken();
270 Reader.Eat(')');
271 Reader.SkipNonToken();
272 List<BadExpression> block = ParseBlock(out bool _);
273 Reader.SkipNonToken();
274
275 return new BadLockExpression(
277 collection,
278 block.ToArray()
279 );
280 }

◆ ParseMeta()

void BadScript2.Parser.BadSourceParser.ParseMeta ( )
private

Parses the MetaData of the current expression.

Definition at line 320 of file BadSourceParser.cs.

321 {
322 if (!Reader.Is("@|"))
323 {
324 return;
325 }
326
327 Reader.Eat("@|");
328 Reader.SkipNonToken();
329 StringBuilder rootMeta = new StringBuilder();
330 StringBuilder returnMeta = new StringBuilder();
331 string returnType = "any";
332 Dictionary<string, (string, StringBuilder)> meta = new Dictionary<string, (string, StringBuilder)>();
333
334 StringBuilder GetMeta(string name, string type)
335 {
336 if (meta.TryGetValue(name, out (string, StringBuilder) val))
337 {
338 return val.Item2;
339 }
340
341 val = (type, new StringBuilder());
342 meta[name] = val;
343
344 return val.Item2;
345 }
346
347 while (!Reader.Is("|@"))
348 {
349 if (Reader.Is("|PARAM"))
350 {
351 Reader.Eat("|PARAM");
352 Reader.SkipNonToken();
353 string name = Reader.ParseWord().Text;
354 Reader.SkipNonToken();
355 string type = "any";
356
357 if (!Reader.Is(':'))
358 {
359 type = "";
360
361 while (!Reader.IsEof() && (Reader.IsWordStart() || Reader.Is('.')))
362 {
363 type += Reader.ParseWord().Text;
364
365 if (!Reader.Is('.'))
366 {
367 continue;
368 }
369
370 type += '.';
372 }
373
374 Reader.SkipNonToken();
375 }
376
377 Reader.Eat(':');
378 Reader.SkipNonToken();
379 StringBuilder m = GetMeta(name, type);
380
381 while (!Reader.IsEof() && !Reader.Is("|@") && !Reader.IsNewLine())
382 {
383 m.Append(Reader.GetCurrentChar());
385 }
386
387 Reader.SkipNonToken();
388 }
389 else if (Reader.Is("|RET"))
390 {
391 Reader.Eat("|RET");
392 Reader.SkipNonToken();
393 string type = "any";
394
395 if (!Reader.Is(':'))
396 {
397 type = "";
398
399 while (!Reader.IsEof() && (Reader.IsWordStart() || Reader.Is('.')))
400 {
401 type += Reader.ParseWord().Text;
402
403 if (!Reader.Is('.'))
404 {
405 continue;
406 }
407
408 type += '.';
410 }
411
412 Reader.SkipNonToken();
413 }
414
415 Reader.Eat(':');
416 Reader.SkipNonToken();
417
418 while (!Reader.IsEof() && !Reader.Is("|@") && !Reader.IsNewLine())
419 {
420 returnMeta.Append(Reader.GetCurrentChar());
422 }
423
424 Reader.SkipNonToken();
425
426 returnType = type;
427 }
428 else
429 {
430 if (Reader.IsNewLine(-1))
431 {
432 Reader.SkipNonToken();
433
434 if (Reader.Is("|"))
435 {
436 continue;
437 }
438 }
439
440 while (!Reader.IsEof() && !Reader.IsNewLine() && !Reader.Is("|@"))
441 {
442 rootMeta.Append(Reader.GetCurrentChar());
444 }
445
446 rootMeta.AppendLine();
447 Reader.SkipNonToken();
448 }
449 }
450
451 Reader.Eat("|@");
452 Reader.SkipNonToken();
453
454 m_MetaData = new BadMetaData(
455 rootMeta.ToString().Trim(),
456 returnMeta.ToString().Trim(),
457 returnType,
458 meta.ToDictionary(
459 x => x.Key,
460 x => new BadParameterMetaData(
461 x.Value.Item1,
462 x.Value.Item2.ToString().Trim()
463 )
464 )
465 );
466 }

◆ ParseMultiLineFormatString()

BadStringExpression BadScript2.Parser.BadSourceParser.ParseMultiLineFormatString ( )
private

Parses a Multiline Format string expression. Moves the reader to the next token.

Returns
Instance of BadStringExpression
Exceptions
BadSourceReaderExceptionGets raised if the string is not properly terminated.

Definition at line 1200 of file BadSourceParser.cs.

1201 {
1203 {
1204 throw new BadSourceReaderException(
1205 $"Expected string start character but got '{(Reader.IsEof() ? "EOF" : Reader.GetCurrentChar())}'",
1207 );
1208 }
1209
1210 int start = Reader.CurrentIndex;
1212 StringBuilder sb = new StringBuilder();
1213 List<BadExpression> args = new List<BadExpression>();
1214
1215 while (!Reader.IsStringQuote())
1216 {
1217 if (Reader.IsEof())
1218 {
1219 throw new BadSourceReaderException(
1220 "String not terminated",
1222 );
1223 }
1224
1225 if (Reader.Is('{'))
1226 {
1227 Reader.Eat('{');
1228 Reader.SkipNonToken();
1229
1230 if (!Reader.Is('{'))
1231 {
1233 Reader.SkipNonToken();
1234 Reader.Eat('}');
1235 sb.Append($"{{{args.Count}}}");
1236 args.Add(expr);
1237
1238 continue;
1239 }
1240
1241 Reader.Eat('{');
1242 sb.Append("{{");
1243
1244 continue;
1245 }
1246
1247 if (Reader.Is('}'))
1248 {
1249 int idx = Reader.CurrentIndex;
1250 Reader.Eat('}');
1251
1252 if (!Reader.Is('}'))
1253 {
1254 throw new BadSourceReaderException(
1255 "Expected '}'",
1257 );
1258 }
1259
1260 Reader.Eat('}');
1261 sb.Append("}}");
1262
1263 continue;
1264 }
1265
1266 sb.Append(Reader.GetCurrentChar());
1267
1268 Reader.MoveNext();
1269 }
1270
1272
1273 if (args.Count == 0)
1274 {
1275 var str = sb.ToString()
1276 .Replace("{{", "{")
1277 .Replace("}}", "}");
1278 return new BadStringExpression(
1279 '"' + str + '"',
1281 );
1282 }
1283
1285 args.ToArray(),
1286 sb.ToString(),
1288 );
1289 }

◆ ParseNew()

BadNewExpression BadScript2.Parser.BadSourceParser.ParseNew ( )
private

Parses a New Expression. Moves the reader to the next token.

Returns
Instance of BadNewExpression
Exceptions
BadParserExceptionGets Raised if the Expression after the new key is not an invocation expression.

Definition at line 1714 of file BadSourceParser.cs.

1715 {
1716 int start = Reader.CurrentIndex;
1718 Reader.SkipNonToken();
1720
1721 if (right is not BadInvocationExpression invoc)
1722 {
1723 throw new BadParserException("Expected Invocation Expression", right.Position);
1724 }
1725
1726 return new BadNewExpression(invoc, Reader.MakeSourcePosition(start, Reader.CurrentIndex - start));
1727 }

◆ ParseParameter()

BadFunctionParameter BadScript2.Parser.BadSourceParser.ParseParameter ( )
private

Parses a Function Parameter. Moves the reader to the next token.

Returns
Instance of BadFunctionParameter
Exceptions
BadParserExceptionGets raised if the parameter is malformed.

Definition at line 2109 of file BadSourceParser.cs.

2110 {
2111 BadExpression nameExpr = ParseValue(0);
2112 Reader.SkipNonToken();
2113
2114 while (Reader.Is("."))
2115 {
2116 Reader.Eat(".");
2117 BadWordToken right = Reader.ParseWord();
2118 List<BadExpression>? genArgs = ParseGenericArguments();
2119 nameExpr = new BadMemberAccessExpression(
2120 nameExpr,
2121 right,
2122 nameExpr.Position.Combine(right.SourcePosition),
2123 genArgs
2124 );
2125 Reader.SkipNonToken();
2126 }
2127
2128 Reader.SkipNonToken();
2129 string name;
2130 BadExpression? typeExpr = null;
2131 Reader.SkipNonToken();
2132
2133 if (Reader.IsWordStart())
2134 {
2135 name = Reader.ParseWord().Text;
2136 typeExpr = nameExpr;
2137 }
2138 else
2139 {
2140 if (nameExpr is not BadVariableExpression expr)
2141 {
2142 throw new BadParserException(
2143 "Expected Variable Expression",
2144 nameExpr.Position
2145 );
2146 }
2147
2148 name = expr.Name;
2149 }
2150
2151
2152 bool isOptional = false;
2153 bool isNullChecked = false;
2154 bool isRestArgs = false;
2155
2156 if (Reader.Is('*'))
2157 {
2158 isRestArgs = true;
2159 Reader.Eat('*');
2160 Reader.SkipNonToken();
2161 }
2162 else
2163 {
2164 if (Reader.Is('?'))
2165 {
2166 isOptional = true;
2167 Reader.Eat('?');
2168 Reader.SkipNonToken();
2169
2170 if (Reader.Is('!'))
2171 {
2172 isNullChecked = true;
2173 Reader.Eat('!');
2174 Reader.SkipNonToken();
2175 }
2176 }
2177 else if (Reader.Is('!'))
2178 {
2179 isNullChecked = true;
2180 Reader.Eat('!');
2181 Reader.SkipNonToken();
2182
2183 if (Reader.Is('?'))
2184 {
2185 isOptional = true;
2186 Reader.Eat('?');
2187 Reader.SkipNonToken();
2188 }
2189 }
2190 }
2191
2192 Reader.SkipNonToken();
2193
2194 return new BadFunctionParameter(name, isOptional, isNullChecked, isRestArgs, typeExpr);
2195 }

◆ ParseParameters()

List< BadFunctionParameter > BadScript2.Parser.BadSourceParser.ParseParameters ( int  start)
private

Parses a Function Parameter List. Moves the reader to the next token.

Parameters
startThe Start index of parent expression
Returns
List of BadFunctionParameter
Exceptions
BadParserExceptionGets raised if the parameter list is malformed.

Definition at line 2203 of file BadSourceParser.cs.

2204 {
2205 List<BadFunctionParameter> parameters = new List<BadFunctionParameter>();
2206
2207 Reader.Eat('(');
2208 Reader.SkipNonToken();
2209
2210 if (!Reader.Is(')'))
2211 {
2212 bool first = true;
2213 bool hadOptional = false;
2214 bool hadRest = false;
2215
2216 while (Reader.Is(',') || first)
2217 {
2218 if (hadRest)
2219 {
2220 throw new BadParserException(
2221 "Rest parameter must be last parameter",
2223 );
2224 }
2225
2226 if (!first)
2227 {
2228 Reader.Eat(',');
2229 Reader.SkipNonToken();
2230 }
2231
2232 first = false;
2233
2234
2236
2237 if (hadOptional && param is { IsOptional: false, IsRestArgs: false })
2238 {
2239 throw new BadParserException(
2240 "Non-Optional parameters must be in front of optional parameters",
2242 );
2243 }
2244
2245 Reader.SkipNonToken();
2246
2247 if (parameters.Any(p => p.Name == param.Name))
2248 {
2249 throw new BadParserException(
2250 "Duplicate parameter name",
2252 );
2253 }
2254
2255 hadOptional |= param.IsOptional;
2256 hadRest |= param.IsRestArgs;
2257
2258
2259 parameters.Add(param);
2260 }
2261 }
2262
2263 Reader.SkipNonToken();
2264 Reader.Eat(')');
2265
2266 return parameters;
2267 }
BadFunctionParameter ParseParameter()
Parses a Function Parameter. Moves the reader to the next token.
bool IsOptional
Indicates if this parameter is optional.
bool IsRestArgs
Indicates if this parameter is the rest parameter of the function.

◆ ParsePrefix()

BadExpression? BadScript2.Parser.BadSourceParser.ParsePrefix ( int  precedence)
private

Parses a Prefix Expression that has precedence greater than the provided precedence. Moves the Reader to the next Token.

Parameters
precedenceThe Precedence
Returns
The Parsed Expression

Definition at line 101 of file BadSourceParser.cs.

102 {
103 // Parse Symbol
104 BadSymbolToken? symbol = Reader.TryParseSymbols(m_Operators.UnaryPrefixSymbols);
105
106 if (symbol == null)
107 {
108 return null;
109 }
110
112
113
114 if (op != null)
115 {
116 return op.Parse(this);
117 }
118
120
121 return null;
122 }
IEnumerable< string > UnaryPrefixSymbols
Enumeration of all Unary Prefix Operator Symbols.
BadUnaryPrefixOperator? FindUnaryPrefixOperator(string symbol, int precedence)
Finds a Unary Prefix Operator by its Symbol.
Base class for all Unary Prefix Operators.
BadExpression Parse(BadSourceParser parser)
Parses the Operator and returns the resulting Expression.

◆ ParseSwitch()

BadExpression BadScript2.Parser.BadSourceParser.ParseSwitch ( )
private

Definition at line 124 of file BadSourceParser.cs.

125 {
126 int start = Reader.CurrentIndex;
128 Reader.SkipNonToken();
129 Reader.Eat('(');
130 Reader.SkipNonToken();
132 Reader.SkipNonToken();
133 Reader.Eat(')');
134 Reader.SkipNonToken();
135 Reader.Eat('{');
136 Reader.SkipNonToken();
137 Dictionary<BadExpression, BadExpression[]> cases = new Dictionary<BadExpression, BadExpression[]>();
138 List<BadExpression>? defaultCase = null;
139 while (!Reader.IsEof() && !Reader.Is('}'))
140 {
141 Reader.SkipNonToken();
143 {
145 Reader.SkipNonToken();
146 Reader.Eat(':');
147 Reader.SkipNonToken();
148 defaultCase = ParseBlock(out bool _);
149 Reader.SkipNonToken();
150 break;
151 }
153 Reader.SkipNonToken();
154 BadExpression caseValue = ParseExpression();
155 Reader.SkipNonToken();
156 Reader.Eat(':');
157 Reader.SkipNonToken();
158 List<BadExpression> caseBody = new List<BadExpression>();
159 if(Reader.Is('{'))
160 {
161 caseBody = ParseBlock(out bool _);
162 }
163 Reader.SkipNonToken();
164 cases[caseValue] = caseBody.ToArray();
165 }
166 Reader.Eat('}');
167
168 return new BadSwitchExpression(Reader.MakeSourcePosition(start, Reader.CurrentIndex - start), value, cases, defaultCase);
169 }
Implements the Switch Statement Expression.

◆ ParseTry()

BadExpression BadScript2.Parser.BadSourceParser.ParseTry ( )
private

Parses a Try Catch Block. Moves the reader to the next token.

Returns
Instance of BadTryCatchExpression

Definition at line 1651 of file BadSourceParser.cs.

1652 {
1653 int start = Reader.CurrentIndex;
1655 Reader.SkipNonToken();
1656 List<BadExpression> block = ParseBlock(out bool isSingleLine);
1657 Reader.SkipNonToken();
1658
1659 if (isSingleLine)
1660 {
1662 }
1663
1664 Reader.SkipNonToken();
1666 Reader.SkipNonToken();
1667 Reader.Eat('(');
1668 Reader.SkipNonToken();
1669 BadWordToken errorName = Reader.ParseWord();
1670 Reader.SkipNonToken();
1671 Reader.Eat(')');
1672 Reader.SkipNonToken();
1673 List<BadExpression> errorBlock = ParseBlock(out isSingleLine);
1674 Reader.SkipNonToken();
1675
1676 if (isSingleLine)
1677 {
1679 }
1680
1681 Reader.SkipNonToken();
1682
1683 BadExpression[] finallyBlock = Array.Empty<BadExpression>();
1685 {
1687 Reader.SkipNonToken();
1688 List<BadExpression> finallyExprs = ParseBlock(out isSingleLine);
1689 Reader.SkipNonToken();
1690 if (isSingleLine)
1691 {
1693 }
1694
1695 Reader.SkipNonToken();
1696 finallyBlock = finallyExprs.ToArray();
1697 }
1698
1699 return new BadTryCatchExpression(
1701 block.ToArray(),
1702 errorBlock.ToArray(),
1703 finallyBlock,
1704 errorName.Text
1705 );
1706 }
Implements the Try Catch Statement Expression.

◆ ParseUsing()

BadExpression BadScript2.Parser.BadSourceParser.ParseUsing ( )
private

Parses a Using Block or Statement. Moves the reader to the next token.

Returns
Instance of BadUsingExpression or BadUsingStatementExpression
Exceptions
BadParserExceptionGets raised if the using statement is malformed.

Definition at line 1592 of file BadSourceParser.cs.

1593 {
1594 int start = Reader.CurrentIndex;
1596 Reader.SkipNonToken();
1597 if (!Reader.Is('('))
1598 {
1599 return ParseUsingStatement(start);
1600 }
1601
1602 Reader.Eat('(');
1603 Reader.SkipNonToken();
1605 {
1606 throw new BadParserException(
1607 "Expected Constant Variable Definition",
1609 );
1610 }
1611
1612 //Parse single expression
1614 if (expr is not BadAssignExpression assignExpr)
1615 {
1616 throw new BadParserException(
1617 "Expected Constant Variable Definition",
1619 );
1620 }
1621
1622 if (assignExpr.Left is not BadVariableDefinitionExpression varDef)
1623 {
1624 throw new BadParserException(
1625 "Expected Constant Variable Definition",
1627 );
1628 }
1629
1630 Reader.SkipNonToken();
1631
1632 Reader.Eat(')');
1633
1634 Reader.SkipNonToken();
1635 List<BadExpression> block = ParseBlock(out bool isSingleLine);
1636 Reader.SkipNonToken();
1637 if (isSingleLine)
1638 {
1640 }
1641
1642 Reader.SkipNonToken();
1643
1644 return new BadUsingExpression(varDef.Name, block.ToArray(), Reader.MakeSourcePosition(start, Reader.CurrentIndex - start), expr);
1645 }
BadExpression ParseUsingStatement(int start)
Parses a Using Statement Expression. Moves the reader to the next token.

◆ ParseUsingStatement()

BadExpression BadScript2.Parser.BadSourceParser.ParseUsingStatement ( int  start)
private

Parses a Using Statement Expression. Moves the reader to the next token.

Parameters
startThe Start index of the expression
Returns
Instance of BadUsingStatementExpression
Exceptions
BadParserExceptionGets raised if the using statement is malformed.

Definition at line 1550 of file BadSourceParser.cs.

1551 {
1552 Reader.SkipNonToken();
1554 {
1555 throw new BadParserException(
1556 "Expected Constant Variable Definition",
1558 );
1559 }
1560
1561 //Parse single expression
1563 if (expr is not BadAssignExpression assignExpr)
1564 {
1565 throw new BadParserException(
1566 "Expected Constant Variable Definition",
1568 );
1569 }
1570
1571 if (assignExpr.Left is not BadVariableDefinitionExpression varDef)
1572 {
1573 throw new BadParserException(
1574 "Expected Constant Variable Definition",
1576 );
1577 }
1578
1579 Reader.SkipNonToken();
1580
1581 //Reader.Eat(BadStaticKeys.STATEMENT_END_KEY); //Not Needed, the parser will automatically eat the statement end key
1582
1583
1584 return new BadUsingStatementExpression(Reader.MakeSourcePosition(start, Reader.CurrentIndex - start), varDef.Name, expr);
1585 }

◆ ParseValue()

BadExpression BadScript2.Parser.BadSourceParser.ParseValue ( int  precedence)
private

Parses a Value Expression or a Prefix Function with precedence greater than the provided precedence. Moves the Reader to the Next Token.

Parameters
precedenceThe Precedence
Returns
Value Expression or Operator Prefix Expression
Exceptions
BadRuntimeExceptionGets raised if a Variable Expression is malformed.

Definition at line 475 of file BadSourceParser.cs.

476 {
477 Reader.SkipNonToken();
478
479 ParseMeta();
480
481 Reader.SkipNonToken();
482
483 BadExpression? prefixExpr = ParsePrefix(precedence);
484
485 if (prefixExpr != null)
486 {
487 return prefixExpr;
488 }
489
490 if (Reader.Is('('))
491 {
492 int start = Reader.CurrentIndex;
493
494 try
495 {
496 List<BadFunctionParameter> p = ParseParameters(start);
497
498 Reader.SkipNonToken();
499
500 if (!Reader.Is("=>"))
501 {
502 Reader.SetPosition(start);
503 }
504 else
505 {
506 return ParseFunction(start, null, null, false, false, BadFunctionCompileLevel.None, p);
507 }
508 }
509 catch (Exception)
510 {
511 Reader.SetPosition(start);
512 }
513 }
514
515 if (Reader.Is('('))
516 {
517 Reader.Eat('(');
519 Reader.Eat(')');
520
521 return expr;
522 }
523
524 if (Reader.Is('['))
525 {
526 int start = Reader.CurrentIndex;
527 Reader.Eat('[');
528 Reader.SkipNonToken();
529 List<BadExpression> initExpressions = new List<BadExpression>();
530
531 if (!Reader.Is(']'))
532 {
533 bool parseNext;
534
535 do
536 {
537 parseNext = false;
538
539 Reader.SkipNonToken();
540 initExpressions.Add(ParseExpression());
541
542 Reader.SkipNonToken();
543
544 if (Reader.Is(','))
545 {
546 Reader.Eat(',');
547 Reader.SkipNonToken();
548 parseNext = true;
549 }
550 }
551 while (parseNext);
552 }
553
554 Reader.SkipNonToken();
555 Reader.Eat(']');
556
557 return new BadArrayExpression(
558 initExpressions.ToArray(),
560 );
561 }
562
563 if (Reader.Is('{'))
564 {
565 int start = Reader.CurrentIndex;
566 Reader.Eat('{');
567 Dictionary<BadWordToken, BadExpression> table = new Dictionary<BadWordToken, BadExpression>();
568 Reader.SkipNonToken();
569
570 if (!Reader.Is('}'))
571 {
572 bool parseNext;
573
574 do
575 {
576 parseNext = false;
577 Reader.SkipNonToken();
578 BadWordToken key = Reader.ParseWord();
579 Reader.SkipNonToken();
580 Reader.Eat(':');
581 Reader.SkipNonToken();
583 table[key] = value;
584 Reader.SkipNonToken();
585
586 if (Reader.Is(','))
587 {
588 parseNext = true;
589 Reader.Eat(',');
590 }
591 }
592 while (parseNext);
593 }
594
595 Reader.Eat('}');
596
597 return new BadTableExpression(
598 table,
600 );
601 }
602
603 if (Reader.IsKey(BadStaticKeys.LOCK_KEY))
604 {
605 return ParseLock();
606 }
607
609 {
610 return ParseForEach();
611 }
612
613 if (Reader.IsKey(BadStaticKeys.FOR_KEY))
614 {
615 return ParseFor();
616 }
617
618 if (Reader.IsKey(BadStaticKeys.IF_KEY))
619 {
620 return ParseIf();
621 }
622
624 {
625 return ParseSwitch();
626 }
627
629 {
631
632 if (Reader.IsWordChar())
633 {
635 }
636 else
637 {
638 Reader.SkipNonToken();
639
640 return new BadContinueExpression(pos);
641 }
642 }
643
644 if (Reader.IsKey(BadStaticKeys.BREAK_KEY))
645 {
647
648 if (Reader.IsWordChar())
649 {
651 }
652 else
653 {
654 Reader.SkipNonToken();
655
656 return new BadBreakExpression(pos);
657 }
658 }
659
660 if (Reader.IsKey(BadStaticKeys.THROW_KEY))
661 {
663
664 if (Reader.IsWordChar())
665 {
667 }
668 else
669 {
670 return new BadThrowExpression(ParseExpression(), pos);
671 }
672 }
673
675 {
677
678 if (Reader.IsWordChar())
679 {
681 }
682 else
683 {
684 Reader.SkipNonToken();
685 bool isRef = false;
686
687 if (Reader.Is(';'))
688 {
689 return new BadReturnExpression(null, pos, false);
690 }
691
692 if (Reader.IsKey(BadStaticKeys.REF_KEY))
693 {
694 isRef = true;
696 Reader.SkipNonToken();
697 }
698
700
701 return new BadReturnExpression(expr, pos, isRef);
702 }
703 }
704
705 if (Reader.IsKey(BadStaticKeys.TRUE) ||
707 {
708 BadBooleanToken token = Reader.ParseBoolean();
709
710 if (Reader.IsWordChar())
711 {
713 }
714 else
715 {
716 return new BadBooleanExpression(bool.Parse(token.Text), token.SourcePosition);
717 }
718 }
719
720 bool isConstant = false;
721 bool isStatic = false;
723 int constStart = Reader.CurrentIndex;
724
726 {
727 isConstant = true;
729 Reader.SkipNonToken();
730 }
732 {
733 isStatic = true;
735 Reader.SkipNonToken();
736 }
737
738 int compiledStart = Reader.CurrentIndex;
739
741 {
742 compileLevel = BadFunctionCompileLevel.Compiled;
744 Reader.SkipNonToken();
745
747 {
748 compileLevel = BadFunctionCompileLevel.CompiledFast;
750 Reader.SkipNonToken();
751 }
752 }
753
755 {
756 return ParseFunction(isConstant, isStatic, compileLevel);
757 }
758
759 if (compileLevel != BadFunctionCompileLevel.None || isConstant)
760 {
761 Reader.SetPosition(compiledStart < constStart ? compiledStart : constStart);
762 }
763
764
765 if (Reader.IsKey(BadStaticKeys.CLASS_KEY))
766 {
767 return ParseClass();
768 }
769
771 {
772 return ParseInterface();
773 }
774
775 if (Reader.IsKey(BadStaticKeys.NEW_KEY))
776 {
777 return ParseNew();
778 }
779
780 if (Reader.IsKey(BadStaticKeys.TRY_KEY))
781 {
782 return ParseTry();
783 }
784
785 if (Reader.IsKey(BadStaticKeys.USING_KEY))
786 {
787 return ParseUsing();
788 }
789
790 if (Reader.IsKey(BadStaticKeys.WHILE))
791 {
792 return ParseWhile();
793 }
794
795 if (Reader.IsKey(BadStaticKeys.NULL))
796 {
797 BadNullToken token = Reader.ParseNull();
798
799 if (Reader.IsWordChar())
800 {
802 }
803 else
804 {
805 return new BadNullExpression(token.SourcePosition);
806 }
807 }
808
809 if (Reader.IsStringQuote() || Reader.IsStringQuote(0, true))
810 {
811 BadStringToken token = Reader.ParseString();
812
813 return new BadStringExpression(token.Value, token.SourcePosition);
814 }
815
817 {
818 return ParseFormatString();
819 }
820
821
823 {
825 }
826
827
829 {
830 BadStringToken token = Reader.ParseMultiLineString();
831
832 return new BadStringExpression(token.Value, token.SourcePosition);
833 }
834
835 if (Reader.IsNumberStart())
836 {
837 BadNumberToken token = Reader.ParseNumber();
838
839 return new BadNumberExpression(
840 decimal.Parse(token.Text, NumberFormatInfo.InvariantInfo),
841 token.SourcePosition
842 );
843 }
844
845 BadValueParser? valueParser = m_Operators.GetValueParser(this);
846
847 if (valueParser != null)
848 {
849 return valueParser.ParseValue(this);
850 }
851
852 Reader.SkipNonToken();
853
854 int wordStart = Reader.CurrentIndex;
855 BadWordToken word = Reader.ParseWord();
856
859 {
860 bool isReadOnly = word.Text == BadStaticKeys.CONSTANT_DEFINITION_KEY;
861 Reader.SkipNonToken();
862 BadExpression nameExpr = ParseValue(0);
863 Reader.SkipNonToken();
864
865 while (Reader.Is("."))
866 {
867 Reader.Eat(".");
868 BadWordToken right = Reader.ParseWord();
869 List<BadExpression>? genArgs = ParseGenericArguments();
870 nameExpr = new BadMemberAccessExpression(
871 nameExpr,
872 right,
873 nameExpr.Position.Combine(right.SourcePosition),
874 genArgs
875 );
876 Reader.SkipNonToken();
877 }
878
879 BadWordToken name;
880 BadExpression? type = null;
881 Reader.SkipNonToken();
882
883 if (Reader.IsWordStart())
884 {
885 type = nameExpr;
886 name = Reader.ParseWord();
887 }
888 else
889 {
890 if (nameExpr is not BadVariableExpression expr)
891 {
892 throw new BadRuntimeException("Expected variable name", nameExpr.Position);
893 }
894
895 name = expr.Name;
896 }
897
898 Reader.SkipNonToken();
899
900 if (Reader.Is('{'))
901 {
902 //Parse Property Accessors
903 // => { get => <expr> [set => <expr>] }
904 Reader.Eat('{');
905 Reader.SkipNonToken();
907 Reader.SkipNonToken();
908 Reader.Eat("=>");
909 Reader.SkipNonToken();
910 BadExpression getExpr = ParseExpression();
911 Reader.SkipNonToken();
913 Reader.SkipNonToken();
914 BadExpression? setExpr = null;
916 {
917 if (isReadOnly)
918 {
919 throw new BadParserException("Cannot define a set accessor for a constant", Reader.MakeSourcePosition(wordStart, Reader.CurrentIndex - wordStart));
920 }
922 Reader.SkipNonToken();
923 Reader.Eat("=>");
924 Reader.SkipNonToken();
925 setExpr = ParseExpression();
926 Reader.SkipNonToken();
928 }
929
930 Reader.SkipNonToken();
931 Reader.Eat('}');
932
933 return new BadPropertyDefinitionExpression(name.Text, word.SourcePosition, getExpr, type, setExpr, isReadOnly);
934 }
935
936 return new BadVariableDefinitionExpression(name.Text, word.SourcePosition, type, isReadOnly);
937 }
938
939 Reader.SkipNonToken();
940
941 List<BadExpression> typeArgs = ParseGenericArguments();
942
943 if (precedence <= 0 || !Reader.Is("=>") && !Reader.Is('*') && !Reader.Is('?') && !Reader.Is('!'))
944 {
945 return new BadVariableExpression(word.Text, word.SourcePosition, typeArgs.ToArray());
946 }
947
948 {
949 int start = Reader.CurrentIndex;
950
951 while (Reader.Is('*') || Reader.Is('?') || Reader.Is('!'))
952 {
954 }
955
956 Reader.SkipNonToken();
957
958 if (!Reader.Is("=>"))
959 {
960 Reader.SetPosition(start);
961 }
962 else
963 {
964 Reader.SetPosition(start);
966
967 if (Reader.Is("=>"))
968 {
969 p = new BadFunctionParameter(word.Text, false, false, false);
970 }
971 else
972 {
973 Reader.SetPosition(wordStart);
974 p = ParseParameter();
975 }
976
977 Reader.SkipNonToken();
978
979 if (!Reader.Is("=>"))
980 {
981 Reader.SetPosition(start);
982 }
983 else
984 {
985 return ParseFunction(
986 start,
987 null,
988 null,
989 false,
990 isStatic,
992 new List<BadFunctionParameter>
993 {
994 p,
995 }
996 );
997 }
998 }
999 }
1000
1001 return new BadVariableExpression(word.Text, word.SourcePosition, typeArgs.ToArray());
1002 }
BadStringExpression ParseFormatString()
Parses a Format Expression. Moves the reader to the next token.
BadNewExpression ParseNew()
Parses a New Expression. Moves the reader to the next token.
BadExpression ParseLock()
Parses a Lock Expression. Moves the Reader to the Next Token.
IEnumerable< BadExpression > Parse()
Parses the File from start to end.
BadClassPrototypeExpression ParseClass()
Parses a Class Structure. Moves the reader to the next token.
BadExpression? ParsePrefix(int precedence)
Parses a Prefix Expression that has precedence greater than the provided precedence....
BadExpression ParseFor()
Parses a For Loop Expression. Moves the Reader to the Next Token.
BadInterfacePrototypeExpression ParseInterface()
Parses an Interface prototype. Moves the reader to the next token.
BadExpression ParseTry()
Parses a Try Catch Block. Moves the reader to the next token.
BadExpression ParseUsing()
Parses a Using Block or Statement. Moves the reader to the next token.
BadStringExpression ParseMultiLineFormatString()
Parses a Multiline Format string expression. Moves the reader to the next token.
BadWhileExpression ParseWhile()
Parses a While Loop. Moves the reader to the next token.
void ParseMeta()
Parses the MetaData of the current expression.
BadExpression ParseForEach()
Parses a For Each Expression. Moves the Reader to the Next Token.
BadExpression ParseIf()
Parses an If Expression. Moves the Reader to the Next Token.
Implements the Break Expression that is used to prematurely exit a loop.
Implements the Break Expression that is used to skip a loop iteraion.
Implements the Throw Expression that is used to raise errors inside the Script.
BadValueParser? GetValueParser(BadSourceParser parser)
Returns a Value Parser that is able to parse the given Token.
Base class for all Value Parsers.
BadExpression ParseValue(BadSourceParser parser)
Parses the Current Token.
Implements a Token that represents a Boolean.
Implements a Token that represents a Number.
Implements a Token that represents a String.
BadFunctionCompileLevel
The BadFunctionCompileLevel enum defines the different levels of compilation for a function.

◆ ParseWhile()

BadWhileExpression BadScript2.Parser.BadSourceParser.ParseWhile ( )
private

Parses a While Loop. Moves the reader to the next token.

Returns
Instance of BadWhileExpression

Definition at line 1413 of file BadSourceParser.cs.

1414 {
1415 int start = Reader.CurrentIndex;
1417 Reader.SkipNonToken();
1418 Reader.Eat('(');
1419 BadExpression condition = ParseExpression();
1420 Reader.Eat(')');
1421
1422 List<BadExpression> block = ParseBlock(out bool _);
1423
1424 return new BadWhileExpression(
1425 condition,
1426 block,
1428 );
1429 }

◆ RequireSemicolon()

static bool BadScript2.Parser.BadSourceParser.RequireSemicolon ( BadExpression  expr)
staticprivate

Returns true if the given expression requires a semicolon.

Parameters
exprThe Expression to check
Returns
True if the expression requires a semicolon. False otherwise.

Definition at line 2398 of file BadSourceParser.cs.

2399 {
2400 if (expr is BadNamedExportExpression named)
2401 {
2402 return RequireSemicolon(named.Expression);
2403 }
2404
2405 if (expr is BadDefaultExportExpression def)
2406 {
2407 return RequireSemicolon(def.Expression);
2408 }
2409
2410 return expr is not (
2423 {
2424 IsSingleLine: false,
2425 });
2426 }

Member Data Documentation

◆ m_MetaData

BadMetaData? BadScript2.Parser.BadSourceParser.m_MetaData
private

The Meta Data of the current expression.

Definition at line 42 of file BadSourceParser.cs.

◆ m_Operators

readonly BadOperatorTable BadScript2.Parser.BadSourceParser.m_Operators
private

The Operator Table that is used to parse the Source Code.

Definition at line 37 of file BadSourceParser.cs.

Property Documentation

◆ Reader

BadSourceReader BadScript2.Parser.BadSourceParser.Reader
get

The Source Reader.

Definition at line 58 of file BadSourceParser.cs.

58{ get; }

The documentation for this class was generated from the following file: