This commit is contained in:
Rohan Singh
2019-01-23 22:52:45 -05:00
parent 3f69ec7987
commit ad50a19057
103 changed files with 5734 additions and 1 deletions
@@ -0,0 +1,23 @@
using ScriptConverter.Ast;
using ScriptConverter.Ast.Declarations;
namespace ScriptConverter.Parser.Parselets.Declarations
{
class ConstParselet : IDeclarationParselet
{
public Declaration Parse(ScriptParser parser, ScriptToken token)
{
ScriptType type;
string name;
parser.ParseNamedType(out type, out name);
parser.Take(ScriptTokenType.Assign);
var value = parser.ParseExpression();
parser.Take(ScriptTokenType.Semicolon);
return new FieldDeclaration(token, parser.Previous, type, name, value, true, true);
}
}
}
@@ -0,0 +1,34 @@
using System;
using System.Linq;
using ScriptConverter.Ast.Declarations;
namespace ScriptConverter.Parser.Parselets.Declarations
{
class IncludeParselet : IDeclarationParselet
{
public Declaration Parse(ScriptParser parser, ScriptToken token)
{
var done = false;
var tokens = parser.ParseSeparatedBy(ScriptTokenType.Dot, (_, first) =>
{
if (done)
return null;
if (parser.Match(ScriptTokenType.Multiply))
{
done = true;
return parser.Take(ScriptTokenType.Multiply);
}
return parser.Take(ScriptTokenType.Identifier);
});
var name = string.Join(".", tokens.Select(t => t.Contents));
if (!parser.MatchAndTake(ScriptTokenType.Semicolon))
Console.WriteLine("JFjngkjasnholjhnaskl");
return new IncludeDeclaration(token, parser.Previous, name);
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Linq;
using ScriptConverter.Ast.Declarations;
namespace ScriptConverter.Parser.Parselets.Declarations
{
class InheritsParselet : IDeclarationParselet
{
public Declaration Parse(ScriptParser parser, ScriptToken token)
{
var tokens = parser.ParseSeparatedBy(ScriptTokenType.Dot, (_, first) => parser.Take(ScriptTokenType.Identifier));
var name = string.Join(".", tokens.Select(t => t.Contents));
if (!parser.MatchAndTake(ScriptTokenType.Semicolon))
Console.WriteLine("fkshgnbkashnkhnasb");
return new InheritsDeclaration(token, parser.Previous, name);
}
}
}
@@ -0,0 +1,43 @@
using System.Linq;
using ScriptConverter.Ast;
using ScriptConverter.Ast.Declarations;
namespace ScriptConverter.Parser.Parselets.Declarations
{
class MethodParselet : IDeclarationParselet
{
public Declaration Parse(ScriptParser parser, ScriptToken token)
{
var returnType = parser.ParseType(token);
var name = parser.Take(ScriptTokenType.Identifier).Contents;
if (parser.MatchAndTake(ScriptTokenType.Assign))
{
var value = parser.ParseExpression();
parser.Take(ScriptTokenType.Semicolon);
return new FieldDeclaration(token, parser.Previous, returnType, name, value, false, false);
}
parser.Take(ScriptTokenType.LeftParen);
var parameters = parser.ParseSeparatedBy(ScriptTokenType.Comma, (_, first) =>
{
if (parser.Match(ScriptTokenType.RightParen))
return null;
ScriptType paramType;
string paramName;
parser.ParseNamedType(out paramType, out paramName);
return new MethodDeclaration.Parameter(paramType, paramName);
}).ToList();
parser.Take(ScriptTokenType.RightParen);
var block = parser.ParseBlock(false);
return new MethodDeclaration(token, parser.Previous, returnType, name, parameters, block);
}
}
}
@@ -0,0 +1,23 @@
using ScriptConverter.Ast;
using ScriptConverter.Ast.Declarations;
namespace ScriptConverter.Parser.Parselets.Declarations
{
class PublicParselet : IDeclarationParselet
{
public Declaration Parse(ScriptParser parser, ScriptToken token)
{
ScriptType type;
string name;
parser.ParseNamedType(out type, out name);
parser.Take(ScriptTokenType.Assign);
var value = parser.ParseExpression();
parser.Take(ScriptTokenType.Semicolon);
return new FieldDeclaration(token, parser.Previous, type, name, value, false, true);
}
}
}