Skip to content

Commit

Permalink
Merge branch 'master' into features/graphics_rework
Browse files Browse the repository at this point in the history
  • Loading branch information
gusmanb authored Jan 14, 2024
2 parents 1c74aa3 + b886d80 commit 7c74ddf
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
28 changes: 16 additions & 12 deletions ZXBStudio/BuildSystem/ZXBasicMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,23 +562,27 @@ private static ZXVariableStorage StorageFromString(string? Value, string Variabl

private static int GetDimensionSize(string DimensionString)
{
int size = 0;

if (!int.TryParse(DimensionString, out size))
try
{
if (DimensionString.ToLower().Contains("to"))
int size = 0;

if (!int.TryParse(DimensionString, out size))
{
string[] parts = DimensionString.ToLower().Split("to");
if (parts.Length == 1)
return int.Parse(parts[0]);
if (DimensionString.ToLower().Contains("to"))
{
string[] parts = DimensionString.ToLower().Split("to");
if (parts.Length == 1)
return int.Parse(parts[0]);
else
return int.Parse(parts[1]) - int.Parse(parts[0]) + 1;
}
else
return int.Parse(parts[1]) - int.Parse(parts[0]) + 1;
return 0;
}
else
return 0;
}

return size;
return size;
}
catch { return 0; }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ZXBasicStudio.DocumentEditors.ZXTextEditor.Classes.Folding
{
public class ZXBasicFoldingStrategy : AbstractFoldingStrategy
{
Regex regStartSubFold = new Regex("(^|:)[^\\S\\r\\n^:]*(fastcall)?[^\\S\\r\\n^:]*?(sub|function)\\s+(fastcall\\s+)?([^\\s\\(]+)\\([^\\n]*?$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Regex regStartSubFold = new Regex("(^|:)[^\\S\\r\\n^:]*(fastcall)?[^\\S\\r\\n^:]*?(sub|function)\\s+(fastcall\\s+)?([^\\s\\(]+)\\s*?\\([^\\n]*?$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Regex regEndSubFold = new Regex("(^|[^\\S\\r\\n^:]+|:)[^\\S\\r\\n^:]*?end\\s+(sub|function)", RegexOptions.Multiline | RegexOptions.IgnoreCase);

Regex regStartCommentFold = new Regex("/'", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Expand All @@ -27,6 +27,9 @@ public class ZXBasicFoldingStrategy : AbstractFoldingStrategy
Regex regStartMultiDefine = new Regex("^[^\\S$\\n]*?#define\\s+(\\w+(\\([^\\)]*\\)?))[^\\n]*?\\\\[^\\S$\\n]*?$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Regex regEndMultiDefine = new Regex("^[^\\\\]*?$", RegexOptions.Multiline | RegexOptions.IgnoreCase);

Regex regStartProcedure = new Regex("^\\s*?PROC\\s*?[\\r\\n;]", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Regex regEndProcedure = new Regex("^\\s*?ENDP\\s*?[\\r\\n;]", RegexOptions.Multiline | RegexOptions.IgnoreCase);

public override IEnumerable<NewFolding> CreateNewFoldings(TextDocument document, out int firstErrorOffset)
{
int subError = -1;
Expand All @@ -39,15 +42,18 @@ public override IEnumerable<NewFolding> CreateNewFoldings(TextDocument document,
var regionFoldings = CreateRegionFoldings(document, out regionError);
int defineError = -1;
var defineFoldings = CreateMultiDefineFoldings(document, out defineError);
int procedureError = -1;
var procedureFoldings = CreateProcedureFoldings(document, out procedureError);

List<NewFolding> allFoldings = new List<NewFolding>();
allFoldings.AddRange(subFoldings);
allFoldings.AddRange(commentFoldings);
allFoldings.AddRange(dimFoldings);
allFoldings.AddRange(regionFoldings);
allFoldings.AddRange(defineFoldings);
allFoldings.AddRange(procedureFoldings);

int[] errs = new int[] { subError, commentError, dimError, regionError, defineError };
int[] errs = new int[] { subError, commentError, dimError, regionError, defineError, procedureError };

firstErrorOffset = !errs.Any(e => e != -1) ? -1 : errs.Where(e => e != -1).Min();

Expand Down Expand Up @@ -201,6 +207,31 @@ private IEnumerable<NewFolding> CreateMultiDefineFoldings(TextDocument document,
foldings.Add(new NewFolding { StartOffset = start.Index, EndOffset = end.Index + end.Length - disp, DefaultClosed = true, IsDefinition = true, Name = name });
}

return foldings;
}
private IEnumerable<NewFolding> CreateProcedureFoldings(TextDocument document, out int firstErrorOffset)
{
firstErrorOffset = -1;

List<NewFolding> foldings = new List<NewFolding>();
var startFoldings = regStartProcedure.Matches(document.Text).ToArray();

for (int buc = 0; buc < startFoldings.Length; buc++)
{
var start = startFoldings[buc];

var end = regEndProcedure.Match(document.Text, start.Index + start.Length);

if (end == null || !end.Success)
continue;

string name = "PROC";

int disp = end.Value.EndsWith('\n') || end.Value.EndsWith('\r') ? 1 : 0;

foldings.Add(new NewFolding { StartOffset = start.Index, EndOffset = end.Index + end.Length - disp, DefaultClosed = false, IsDefinition = false, Name = name });
}

return foldings;
}
}
Expand Down
12 changes: 12 additions & 0 deletions ZXBStudio/DocumentEditors/ZXTextEditor/Controls/ZXBasicEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ public class ZXBasicEditor : ZXTextEditor
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "ORG", "Set origin."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "ASM", "End assembly."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "ALIGN", "Align section."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "PROC", "Procedure start."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "ENDP", "Procedure end."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "LOCAL", "Procedure local label."),
};
//Also contains flags
static ZXBasicCompletionData[] assemblerRegisters = new ZXBasicCompletionData[]
{
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "AF", "Register pair."),
Expand All @@ -419,6 +423,14 @@ public class ZXBasicEditor : ZXTextEditor
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "IXL", "Register."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "IYH", "Register."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "IYL", "Register."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "Z", "Zero flag set."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "NZ", "Zero flag not set."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "C", "Carry flag set."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "NC", "Carry flag not set."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "M", "Sign flag set."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "P", "Sign flag not set."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "PE", "Parity/overflow flag set."),
new ZXBasicCompletionData(ZXBasicCompletionType.Assembler, "PO", "Parity/overflow flag not set."),
};
static ZXBasicCompletionData[] assembler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ private void Document_Changed(object? sender, DocumentChangeEventArgs e)
if (!allowsBreakpoints || e.OffsetChangeMap == null || e.OffsetChangeMap.Count == 0)
return;


if (updateFoldingsTimer != null)
{
updateFoldingsTimer.IsEnabled = false;
updateFoldingsTimer.IsEnabled = true;
}

// TODO: DUEFECTU 2023.05.17 - if e.OffsetChangeMap.Count == 0, e.OffsetChangeMap[0].Offset throws a null reference exception
if (e.OffsetChangeMap.Count == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion ZXBStudio/ZXBasicStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.6" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.5" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.6" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.6" />
<PackageReference Include="Avalonia.Svg.Skia" Version="11.0.0.9" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.6" />
Expand Down

0 comments on commit 7c74ddf

Please sign in to comment.