-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to specify existing uses/symbols for interactive documents.
Closes #54.
- Loading branch information
Showing
28 changed files
with
202 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
namespace Vezel.Celerity.Language.Semantics.Binding; | ||
|
||
public sealed partial class InteractiveContext | ||
{ | ||
public static InteractiveContext Default { get; } = | ||
new(ImmutableDictionary<string, ModulePath>.Empty, ImmutableDictionary<string, InteractiveSymbol>.Empty); | ||
|
||
private readonly ImmutableDictionary<string, ModulePath> _uses; | ||
|
||
private readonly ImmutableDictionary<string, InteractiveSymbol> _symbols; | ||
|
||
private InteractiveContext( | ||
ImmutableDictionary<string, ModulePath> uses, ImmutableDictionary<string, InteractiveSymbol> symbols) | ||
{ | ||
_uses = uses; | ||
_symbols = symbols; | ||
} | ||
|
||
public bool TryGetUse(string name, [MaybeNullWhen(false)] out ModulePath path) | ||
{ | ||
Check.Argument(UseRegex().IsMatch(name), name); | ||
|
||
return _uses.TryGetValue(name, out path); | ||
} | ||
|
||
public InteractiveContext AddUse(string name, ModulePath path) | ||
{ | ||
Check.Argument(UseRegex().IsMatch(name), name); | ||
Check.Null(path); | ||
|
||
return new(_uses.Add(name, path), _symbols); | ||
} | ||
|
||
public InteractiveContext RemoveUse(string name) | ||
{ | ||
Check.Argument(UseRegex().IsMatch(name), name); | ||
|
||
return new(_uses.Remove(name), _symbols); | ||
} | ||
|
||
public bool TryGetSymbol(string name, [MaybeNullWhen(false)] out InteractiveSymbol symbol) | ||
{ | ||
Check.Argument(SymbolRegex().IsMatch(name), name); | ||
|
||
return _symbols.TryGetValue(name, out symbol); | ||
} | ||
|
||
public InteractiveContext AddSymbol(string name, bool mutable) | ||
{ | ||
Check.Argument(SymbolRegex().IsMatch(name), name); | ||
|
||
return new(_uses, _symbols.Add(name, new(name, mutable))); | ||
} | ||
|
||
public InteractiveContext RemoveSymbol(string name) | ||
{ | ||
Check.Argument(SymbolRegex().IsMatch(name), name); | ||
|
||
return new(_uses, _symbols.Remove(name)); | ||
} | ||
|
||
[GeneratedRegex(@"^[A-Z][a-zA-Z0-9]*$", RegexOptions.Singleline | RegexOptions.CultureInvariant)] | ||
private static partial Regex UseRegex(); | ||
|
||
[GeneratedRegex(@"^[a-z][_0-9a-z]*$", RegexOptions.Singleline | RegexOptions.CultureInvariant)] | ||
private static partial Regex SymbolRegex(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Vezel.Celerity.Language.Semantics.Tree; | ||
using Vezel.Celerity.Language.Syntax.Tree; | ||
|
||
namespace Vezel.Celerity.Language.Semantics.Binding; | ||
|
||
public sealed class InteractiveSymbol : LocalSymbol | ||
{ | ||
public override bool IsMutable => _mutable; | ||
|
||
public override bool IsDiscard => false; | ||
|
||
private readonly bool _mutable; | ||
|
||
internal InteractiveSymbol(string name, bool mutable) | ||
: base(name) | ||
{ | ||
_mutable = mutable; | ||
} | ||
|
||
private protected override SyntaxToken GetToken(SemanticNode node) | ||
{ | ||
// We never have bindings, so this should never be called. | ||
throw new UnreachableException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public sealed partial class QualityTests | ||
{ | ||
[Fact] | ||
public Task unreachable_code_submission() | ||
{ | ||
return TestAsync( | ||
ctx => ctx, | ||
""" | ||
{ | ||
ret nil; | ||
42; | ||
}; | ||
""", | ||
UnreachableCodePass.Instance); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/tests/quality/unreachable_code_submission.diags.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Warning[unreachable-code]: Code is unreachable | ||
--> unreachable_code_submission.cel (3,5)-(3,8) | ||
1 | { | ||
2 | ret nil; | ||
3 | 42; | ||
: ^^^ | ||
4 | }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
public sealed partial class SemanticTests | ||
{ | ||
[Fact] | ||
public Task contextual_submissions() | ||
{ | ||
return TestAsync( | ||
ctx => ctx | ||
.AddSymbol("mutable", mutable: true) | ||
.AddSymbol("immutable", mutable: false), | ||
""" | ||
mutable = 1; | ||
immutable = 2; | ||
let mut immutable = 3; | ||
immutable = 4; | ||
nonexistent = 5; | ||
"""); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/tests/semantics/contextual_submissions.diags.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Error[E0033]: Assignment to immutable symbol 'immutable' | ||
--> contextual_submissions.cel (2,1)-(2,10) | ||
1 | mutable = 1; | ||
2 | immutable = 2; | ||
: ^^^^^^^^^ | ||
3 | let mut immutable = 3; | ||
4 | immutable = 4; | ||
5 | nonexistent = 5; | ||
Error[E0030]: Unknown symbol name 'nonexistent' | ||
--> contextual_submissions.cel (5,1)-(5,12) | ||
2 | immutable = 2; | ||
3 | let mut immutable = 3; | ||
4 | immutable = 4; | ||
5 | nonexistent = 5; | ||
: ^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.