Files
SWG-ScriptConverter/ScriptConverter/Parser/Parselets/Declarations/IncludeParselet.cs
T
2019-01-23 22:52:45 -05:00

35 lines
1.0 KiB
C#

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);
}
}
}