/// <summary> /// Transforms the script into a list of blocks. The blocks that cannot be converted will be created as BlockLSCode blocks. /// </summary> /// <returns></returns> public List <BlockBase> ToBlocks() { List <BlockBase> list = new List <BlockBase>(); var compressed = CompressedLines; List <string> buffer = new List <string>(); var isScript = false; foreach (var c in compressed.Where(c => !string.IsNullOrEmpty(c.Trim()))) { if (!isScript && BlockParser.IsBlock(c)) { if (buffer.Count > 0) { var b = new BlockLSCode(); list.Add(b.FromLS(buffer)); buffer.Clear(); } try { list.Add(BlockParser.Parse(c)); } catch (Exception ex) { var line = c; line = BlockBase.TruncatePretty(line, 50); throw new Exception($"Exception while parsing block {line}\nReason: {ex.Message}"); } } else { buffer.Add(c); if (c.StartsWith("BEGIN SCRIPT")) { isScript = true; } else if (c.StartsWith("END SCRIPT")) { isScript = false; } } } if (buffer.Count > 0) { var b = new BlockLSCode(); list.Add(b.FromLS(buffer)); buffer.Clear(); } return(list); }
public PageBlockLSCode(BlockLSCode block) { InitializeComponent(); this.block = block; DataContext = this.block; // Style the LoliScript editor scriptEditor.Text = block.Script; scriptEditor.ShowLineNumbers = true; scriptEditor.TextArea.Foreground = new SolidColorBrush(Colors.Gainsboro); scriptEditor.TextArea.TextView.LinkTextForegroundBrush = new SolidColorBrush(Colors.DodgerBlue); using (XmlReader reader = XmlReader.Create("LSHighlighting.xshd")) { scriptEditor.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance); } }