Skip to content

Commit

Permalink
Added syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergiu Marton committed Jul 31, 2018
1 parent 4a8c86f commit db7b25f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
11 changes: 9 additions & 2 deletions PseudoEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using Microsoft.Win32;
using Path = System.IO.Path;

Expand All @@ -25,15 +28,19 @@ public partial class MainWindow : Window
{
private string _currentFileName;
private const string ProgramName = "PseudoEditor";
private const string HighlightingFile = "PseudoHighlight.xshd";

public MainWindow()
{
InitializeComponent();

Editor.Focus();

ShowLineColumn();
Editor.TextArea.Caret.PositionChanged += (sender, args) => ShowLineColumn();

Editor.SyntaxHighlighting =
HighlightingLoader.Load(XmlReader.Create(HighlightingFile), HighlightingManager.Instance);

Editor.Focus();
}

private void ShowLineColumn()
Expand Down
3 changes: 3 additions & 0 deletions PseudoEditor/PseudoEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Include="PseudoHighlight.xshd">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
46 changes: 46 additions & 0 deletions PseudoEditor/PseudoHighlight.xshd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<SyntaxDefinition name="C#"
xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" />
<Color name="String" foreground="Blue" />

<!-- This is the main ruleset. -->
<RuleSet>
<Span color="Comment" begin="//" />
<Span color="Comment" multiline="true" begin="/\*" end="\*/" />

<Span color="String">
<Begin>"</Begin>
<End>"</End>
<RuleSet>
<!-- nested span for escape sequences -->
<Span begin="\\" end="." />
</RuleSet>
</Span>

<Keywords fontWeight="bold" foreground="Blue">
<Word>daca</Word>
<Word>altfel</Word>
<Word>atunci</Word>
<Word>cat timp</Word>
<Word>pentru</Word>
<Word>executa</Word>
<Word>sfarsit</Word>
<Word>intreg</Word>
<Word>real</Word>
<Word>text</Word>
<Word>scrie</Word>
<Word>scrieln</Word>
<Word>citeste</Word>
</Keywords>

<!-- Digits -->
<Rule foreground="DarkBlue">
\b0[xX][0-9a-fA-F]+ # hex number
| \b
( \d+(\.[0-9]+)? #number with optional floating point
| \.[0-9]+ #or just starting with floating point
)
([eE][+-]?[0-9]+)? # optional exponent
</Rule>
</RuleSet>
</SyntaxDefinition>

0 comments on commit db7b25f

Please sign in to comment.