mirror of
https://github.com/Cekis/SWG-ScriptConverter.git
synced 2026-10-07 22:13:32 -04:00
Add code
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System.Linq;
|
||||
using ScriptConverter.Ast;
|
||||
using ScriptConverter.Ast.Expressions;
|
||||
using ScriptConverter.Ast.Statements;
|
||||
|
||||
namespace ScriptConverter.Parser.Parselets.Statements
|
||||
{
|
||||
class VariableParselet : IStatementParselet
|
||||
{
|
||||
public Statement Parse(ScriptParser parser, ScriptToken token, out bool trailingSemicolon)
|
||||
{
|
||||
trailingSemicolon = true;
|
||||
|
||||
var baseType = parser.ParseType(token);
|
||||
|
||||
var definitions = parser.ParseSeparatedBy(ScriptTokenType.Comma, (_, first) =>
|
||||
{
|
||||
var name = parser.Take(ScriptTokenType.Identifier).Contents;
|
||||
|
||||
var arrayDims = 0;
|
||||
while (parser.MatchAndTake(ScriptTokenType.LeftSquare))
|
||||
{
|
||||
parser.Take(ScriptTokenType.RightSquare);
|
||||
arrayDims++;
|
||||
}
|
||||
|
||||
var type = baseType;
|
||||
|
||||
if (arrayDims > 0)
|
||||
type = new ScriptType(baseType.Name, baseType.ArrayDimensions + arrayDims, baseType.IsResizable);
|
||||
|
||||
Expression value = null;
|
||||
if (parser.MatchAndTake(ScriptTokenType.Assign))
|
||||
value = parser.ParseExpression();
|
||||
|
||||
return new VariableStatement.Definition(type, name, value);
|
||||
}).ToList();
|
||||
|
||||
return new VariableStatement(token, parser.Previous, baseType, false, definitions);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user