Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Apr 26, 2024
1 parent 88f0d16 commit 38cf139
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ public void TestLexerOptions()
var builder = new ParserBuilder();
var model = builder.CompileModel(grammar, "MinimalParser");
Check.That(model).IsOkModel();
Check.That(model.Value.LexerModel.Options.IgnoreKeyWordCase).IsTrue();
Check.That(model.Value.LexerModel.Options.IndentationAware).IsFalse();
Check.That(model.Value.LexerModel.Options.IgnoreWS).IsFalse();
Check.That(model.Value.LexerModel.Options.IgnoreEOL).IsFalse();
Check.That(model.Value.LexerModel.Options.IgnoreKeyWordCase.Value).IsTrue();
Check.That(model.Value.LexerModel.Options.IndentationAware.Value).IsFalse();
Check.That(model.Value.LexerModel.Options.IgnoreWS).IsNull();
Check.That(model.Value.LexerModel.Options.IgnoreEOL).IsNull();

var generator = new LexerGenerator();
var lexer = generator.GenerateLexer(model.Value.LexerModel, "namespace");
Expand Down
10 changes: 6 additions & 4 deletions csly-cli-builder/LexerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public LexerBuilder(string name)
ModuleBuilder moduleBuilder = dynamicAssembly.DefineDynamicModule(aName.Name);

EnumBuilder enumBuilder = moduleBuilder.DefineEnum(DynamicLexerName, TypeAttributes.Public, typeof(int));

SetLexerOptions(enumBuilder, model.Options);

int i = 0;

Expand Down Expand Up @@ -75,10 +77,10 @@ private void SetLexerOptions(EnumBuilder builder, LexerOptions options)
attributeType.GetProperty(nameof(LexerAttribute.IndentationAWare)),
}!,
new object[] { // values for property assignment
options.IgnoreEOL,
options.IgnoreWS,
options.IgnoreKeyWordCase,
options.IndentationAware
options.IgnoreEOL ?? true,
options.IgnoreWS ?? true,
options.IgnoreKeyWordCase ?? false,
options.IndentationAware ?? false
});

builder.SetCustomAttribute(customAttributeBuilder);
Expand Down
8 changes: 4 additions & 4 deletions csly-cli-model/lexer/LexerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace clsy.cli.model.lexer;

public class LexerOptions : ICLIModel
{
public bool IgnoreWS { get; set; }
public bool? IgnoreWS { get; set; }

public bool IgnoreEOL { get; set; }
public bool? IgnoreEOL { get; set; }

public bool IgnoreKeyWordCase { get; set; }
public bool? IgnoreKeyWordCase { get; set; }

public bool IndentationAware { get; set; }
public bool? IndentationAware { get; set; }
}
17 changes: 9 additions & 8 deletions csly-cli-parser/CLIParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ public ICLIModel Lexer(Token<CLIToken> name, List<ICLIModel> optionList, List<IC
var opts = optionList.Cast<LexerOptions>();
var options = new LexerOptions()
{
IgnoreWS = opts.Any(x => x.IgnoreWS),
IndentationAware = opts.Any(x => x.IndentationAware),
IgnoreEOL = opts.Any(x => x.IgnoreEOL),
IgnoreKeyWordCase = opts.Any(x => x.IgnoreKeyWordCase)

IgnoreWS = opts.Select(x => x.IgnoreWS).FirstOrDefault(x => x.HasValue),
IndentationAware = opts.Select(x => x.IndentationAware).FirstOrDefault(x => x.HasValue),
IgnoreEOL = opts.Select(x => x.IgnoreEOL).FirstOrDefault(x => x.HasValue),
IgnoreKeyWordCase = opts.Select(x => x.IgnoreKeyWordCase).FirstOrDefault(x => x.HasValue)
};
return new LexerModel(tokens.Cast<TokenModel>().ToList(),options, name.Value);
}
Expand Down Expand Up @@ -327,10 +328,10 @@ public ICLIModel lexerOption(Token<CLIToken> option, Token<CLIToken> enabledFlag
bool enabled = enabledFlag.Value == "true";
return new LexerOptions()
{
IgnoreWS = option.TokenID == CLIToken.IGNOREWHITESPACES && enabled,
IgnoreEOL = option.TokenID == CLIToken.IGNOREEOL && enabled,
IgnoreKeyWordCase = option.TokenID == CLIToken.IGNOREKEYWORDCASING && enabled,
IndentationAware = option.TokenID == CLIToken.INDENTATIONAWARE && enabled
IgnoreWS = option.TokenID == CLIToken.IGNOREWHITESPACES ? enabled : null,
IgnoreEOL = option.TokenID == CLIToken.IGNOREEOL ? enabled : null,
IgnoreKeyWordCase = option.TokenID == CLIToken.IGNOREKEYWORDCASING ? enabled : null,
IndentationAware = option.TokenID == CLIToken.INDENTATIONAWARE ? enabled : null
};
}

Expand Down

0 comments on commit 38cf139

Please sign in to comment.