-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #498 from b3b00/test/fstrings
Test/fstrings
- Loading branch information
Showing
8 changed files
with
258 additions
and
28 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
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,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using csly.whileLang.compiler; | ||
using Sigil; | ||
using sly.lexer; | ||
|
||
namespace csly.whileLang.model; | ||
|
||
public class FString : Expression | ||
{ | ||
public LexerPosition Position { get; set; } | ||
public Scope CompilerScope { get; set; } | ||
|
||
public List<FStringElement> Elements { get; set; } | ||
|
||
public FString(List<FStringElement> elements, LexerPosition position) | ||
{ | ||
this.Elements = elements; | ||
Position = position; | ||
} | ||
|
||
public string Dump(string tab) | ||
{ | ||
StringBuilder builder = new StringBuilder(); | ||
builder.Append($"{{tab}}\""); | ||
foreach (var element in Elements) | ||
{ | ||
builder.Append(element.Dump("")); | ||
} | ||
|
||
builder.Append("\""); | ||
return builder.ToString(); | ||
} | ||
|
||
public string Transpile(CompilerContext context) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Emit<Func<int>> EmitByteCode(CompilerContext context, Emit<Func<int>> emiter) | ||
{ | ||
if (Elements.Count == 1) | ||
{ | ||
return Elements[0].EmitByteCode(context, emiter); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public WhileType Whiletype { get; set; } = WhileType.STRING; | ||
} |
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,63 @@ | ||
using System; | ||
using csly.whileLang.compiler; | ||
using Sigil; | ||
using sly.lexer; | ||
|
||
namespace csly.whileLang.model; | ||
|
||
public class FStringElement : WhileAST | ||
{ | ||
|
||
public LexerPosition Position { get; set; } | ||
|
||
public Scope CompilerScope { get; set; } | ||
public Variable VariableElement { get; set; } | ||
|
||
public StringConstant StringElement { get; set; } | ||
|
||
public bool IsStringElement => StringElement != null; | ||
|
||
public bool IsVariable => VariableElement != null; | ||
|
||
public FStringElement(Variable variableElement, LexerPosition position) | ||
{ | ||
VariableElement = variableElement; | ||
Position = position; | ||
} | ||
|
||
public FStringElement(StringConstant stringElement, LexerPosition position) | ||
{ | ||
StringElement = stringElement; | ||
Position = position; | ||
} | ||
|
||
|
||
public string Dump(string tab) | ||
{ | ||
if (IsStringElement) | ||
{ | ||
return tab + StringElement.Value; | ||
} | ||
else | ||
{ | ||
return $"{{tab}}{{{{{VariableElement.Dump("")}}}"; | ||
} | ||
} | ||
|
||
public string Transpile(CompilerContext context) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Emit<Func<int>> EmitByteCode(CompilerContext context, Emit<Func<int>> emiter) | ||
{ | ||
if (IsStringElement) | ||
{ | ||
return StringElement.EmitByteCode(context, emiter); | ||
} | ||
else | ||
{ | ||
return VariableElement.EmitByteCode(context, emiter); | ||
} | ||
} | ||
} |
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.