Skip to content

Commit 085503e

Browse files
verify flags better
1 parent 908b1a8 commit 085503e

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using SER.Code.ContextSystem.BaseContexts;
2+
using SER.Code.ContextSystem.Structures;
3+
using SER.Code.FlagSystem.Flags;
4+
using SER.Code.Helpers.ResultSystem;
5+
using SER.Code.TokenSystem.Tokens;
6+
7+
namespace SER.Code.ContextSystem.Contexts;
8+
9+
public class FlagContext : StandardContext
10+
{
11+
private string? _flagName;
12+
13+
public override string FriendlyName => "flag declaration";
14+
15+
public override TryAddTokenRes TryAddToken(BaseToken token)
16+
{
17+
if (Flag.FlagInfos.Count == 0)
18+
{
19+
Flag.RegisterFlags();
20+
}
21+
22+
if (!Flag.FlagInfos.ContainsKey(token.RawRep))
23+
{
24+
return TryAddTokenRes.Error($"Flag '{token.RawRep}' is not a valid flag.");
25+
}
26+
27+
_flagName = token.RawRep;
28+
return TryAddTokenRes.End();
29+
}
30+
31+
public override Result VerifyCurrentState()
32+
{
33+
return Result.Assert(_flagName is not null, "Name of the flag is missing.");
34+
}
35+
36+
protected override void Execute()
37+
{
38+
}
39+
}

‎Code/TokenSystem/Tokens/FlagToken.cs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ protected override IParseResult InternalParse(Script scr)
1313
: new Ignore();
1414
}
1515

16-
public RunnableContext? GetContext(Script scr) => null;
17-
}
16+
public RunnableContext GetContext(Script scr) => new SER.Code.ContextSystem.Contexts.FlagContext
17+
{
18+
LineNum = LineNum,
19+
Script = scr,
20+
};
21+
}

0 commit comments

Comments
 (0)