Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "lexcom",
"command": "dotnet",
"type": "process",
"args": [
"run",
"--project",
"${workspaceFolder}/lexcom/lexcom.csproj",
"--",
"${file}"
],
"problemMatcher": "$msCompile"
}
]

}
1 change: 0 additions & 1 deletion LC/LC.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>

<ProjectReference Include="..\Lex\Lex.csproj">
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
Expand Down
35 changes: 1 addition & 34 deletions LC/LexRepl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,40 +117,7 @@ protected override void EvaluateSubmition(string text)
}
else
{
foreach (var diagnostic in result.Diagnostics.OrderBy(diag =>diag.Span, new TextSpanComparer()))
{
var lineIndex = syntaxTree.Text.GetLineIndex(diagnostic.Span.Start);
var line = syntaxTree.Text.Lines[lineIndex];
var lineNumber = lineIndex + 1;
var character = diagnostic.Span.Start - line.Start + 1;

Console.WriteLine();

Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write($"({lineNumber}, {character}): ");
Console.WriteLine(diagnostic);
Console.ResetColor();

var prefixSpan = TextSpan.FromBounds(line.Start, diagnostic.Span.Start);
var suffixSpan = TextSpan.FromBounds(diagnostic.Span.End, line.end);

var prefix = syntaxTree.Text.ToString(prefixSpan);
var error = syntaxTree.Text.ToString(diagnostic.Span);
var suffix = syntaxTree.Text.ToString(suffixSpan);

Console.Write(" ");
Console.Write(prefix);

Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(error);
Console.ResetColor();

Console.Write(suffix);

Console.WriteLine();
}

Console.WriteLine();
Console.Out.WriteDiagnostics(result.Diagnostics, syntaxTree);
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions LC/TextSpanComparer.cs

This file was deleted.

Binary file modified Lex.Tests/bin/Debug/netcoreapp3.0/Lex.Tests.dll
Binary file not shown.
Binary file modified Lex.Tests/bin/Debug/netcoreapp3.0/Lex.Tests.pdb
Binary file not shown.
Binary file modified Lex.Tests/obj/Debug/netcoreapp3.0/Lex.Tests.dll
Binary file not shown.
Binary file modified Lex.Tests/obj/Debug/netcoreapp3.0/Lex.Tests.pdb
Binary file not shown.
14 changes: 14 additions & 0 deletions Lex.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LC", "LC\LC.csproj", "{4CC28DD9-CC33-4915-BB16-22D52BC1E426}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lexcom", "lexcom\lexcom.csproj", "{B96B9B71-2FD8-4C61-96BF-337166696452}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,5 +32,17 @@ Global
{4CC28DD9-CC33-4915-BB16-22D52BC1E426}.Release|x64.Build.0 = Release|Any CPU
{4CC28DD9-CC33-4915-BB16-22D52BC1E426}.Release|x86.ActiveCfg = Release|Any CPU
{4CC28DD9-CC33-4915-BB16-22D52BC1E426}.Release|x86.Build.0 = Release|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Debug|x64.ActiveCfg = Debug|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Debug|x64.Build.0 = Debug|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Debug|x86.ActiveCfg = Debug|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Debug|x86.Build.0 = Debug|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Release|Any CPU.Build.0 = Release|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Release|x64.ActiveCfg = Release|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Release|x64.Build.0 = Release|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Release|x86.ActiveCfg = Release|Any CPU
{B96B9B71-2FD8-4C61-96BF-337166696452}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
46 changes: 44 additions & 2 deletions Lex/IO/TextWriterExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Lex.CodeAnalysis.Syntax;
using Lex.CodeAnalysis.Text;

namespace Lex.CodeAnalysis
{
internal static class TextWriterExtensions
public static class TextWriterExtensions
{
public static bool IsConsoleOut(this TextWriter writer)
{
Expand Down Expand Up @@ -63,7 +67,45 @@ public static void WritePunctuation(this TextWriter writer, string text)
writer.Write(text);
writer.ResetColor();
}
}


public static void WriteDiagnostics(this TextWriter TextWriter, IEnumerable<Diagnostic> diagnostics, SyntaxTree syntaxTree){
foreach (var diagnostic in diagnostics.OrderBy(d =>d.Span.Start).ThenBy(d => d.Span.Length))
{
var lineIndex = syntaxTree.Text.GetLineIndex(diagnostic.Span.Start);
var line = syntaxTree.Text.Lines[lineIndex];
var lineNumber = lineIndex + 1;
var character = diagnostic.Span.Start - line.Start + 1;

Console.WriteLine();

Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write($"({lineNumber}, {character}): ");
Console.WriteLine(diagnostic);
Console.ResetColor();

var prefixSpan = TextSpan.FromBounds(line.Start, diagnostic.Span.Start);
var suffixSpan = TextSpan.FromBounds(diagnostic.Span.End, line.end);

var prefix = syntaxTree.Text.ToString(prefixSpan);
var error = syntaxTree.Text.ToString(diagnostic.Span);
var suffix = syntaxTree.Text.ToString(suffixSpan);

Console.Write(" ");
Console.Write(prefix);

Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(error);
Console.ResetColor();

Console.Write(suffix);

Console.WriteLine();
}

Console.WriteLine();
}

}

}
13 changes: 12 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ pool:
vmImage: 'windows-latest'

variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
sln: './Lex/Lex.sln'
tests: './Lex.Tests/Lex.Tests.csproj'

steps:
- task: NuGetToolInstaller@1
Expand All @@ -32,3 +33,13 @@ steps:
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- script: dotnet build --configuration $(buildConfiguration) $(sln)
displayName: 'dotnet build $(buildConfiguration)'
- script: dotnet test $(tests) --logger "xunit;LogFileName=TestResults.xml"
displayName: 'dotnet test'
- task: PublishTestResults@2
displayName: 'publish test results to azure pipelines'
inputs:
testResultsFormat: 'xUnit'
testResultsFiles: '**/TestResults.xml'
condition: always()
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions lexcom.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

dotnet run --project ./lexcom/lexcom.csproj -- %*
3 changes: 3 additions & 0 deletions lexcom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dotnet run --project ./lexcom/lexcom.csproj -- "$@"
44 changes: 44 additions & 0 deletions lexcom/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Lex.CodeAnalysis;
using Lex.CodeAnalysis.Symbols;
using Lex.CodeAnalysis.Syntax;

namespace Lex
{
internal static class Program
{
private static void Main(string[] args)
{
if (args.Length ==0)
{
Console.Error.WriteLine("usage: lex <source-paths>");
return;
}

if (args.Length > 1)
{
Console.Error.WriteLine("Error: Onl one path supported right now");
return;
}

var path = args.Single();

var text = File.ReadAllText(path);
var syntaxTree = SyntaxTree.Parse(text);

var compilation = new Compilation(syntaxTree);
var result = compilation.Evaluate(new Dictionary<VariableSymble , object>());

if (result.Diagnostics.Any()){
Console.Error.WriteDiagnostics(result.Diagnostics, syntaxTree);
}else{
if (result.Value != null){
Console.Out.WriteLine(result.Value);
}
}
}
}
}
Binary file added lexcom/bin/Debug/netcoreapp3.0/Lex.dll
Binary file not shown.
Binary file added lexcom/bin/Debug/netcoreapp3.0/Lex.pdb
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions lexcom/bin/Debug/netcoreapp3.0/cfg.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
digraph G {
N0 [label = "<Start>" shape = box]
N1 [label = "print(\"What is Your name\")\lstring name = input()\lprint(\"Hello \" + name)\l" shape = box]
N2 [label = "<End>" shape = box]
N0 -> N1 [label = ""]
N1 -> N2 [label = ""]
}
54 changes: 54 additions & 0 deletions lexcom/bin/Debug/netcoreapp3.0/lexcom.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.0": {
"lexcom/1.0.0": {
"dependencies": {
"Lex": "1.0.0"
},
"runtime": {
"lexcom.dll": {}
}
},
"System.Collections.Immutable/1.7.1": {
"runtime": {
"lib/netstandard2.0/System.Collections.Immutable.dll": {
"assemblyVersion": "1.2.5.0",
"fileVersion": "4.700.20.21406"
}
}
},
"Lex/1.0.0": {
"dependencies": {
"System.Collections.Immutable": "1.7.1"
},
"runtime": {
"Lex.dll": {}
}
}
}
},
"libraries": {
"lexcom/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"System.Collections.Immutable/1.7.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-B43Zsz5EfMwyEbnObwRxW5u85fzJma3lrDeGcSAV1qkhSRTNY5uXAByTn9h9ddNdhM+4/YoLc/CI43umjwIl9Q==",
"path": "system.collections.immutable/1.7.1",
"hashPath": "system.collections.immutable.1.7.1.nupkg.sha512"
},
"Lex/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
Binary file added lexcom/bin/Debug/netcoreapp3.0/lexcom.dll
Binary file not shown.
Binary file added lexcom/bin/Debug/netcoreapp3.0/lexcom.exe
Binary file not shown.
Binary file added lexcom/bin/Debug/netcoreapp3.0/lexcom.pdb
Binary file not shown.
8 changes: 8 additions & 0 deletions lexcom/bin/Debug/netcoreapp3.0/lexcom.runtimeconfig.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\Danuja Fernando\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Danuja Fernando\\.nuget\\packages"
]
}
}
9 changes: 9 additions & 0 deletions lexcom/bin/Debug/netcoreapp3.0/lexcom.runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.0.0"
}
}
}
14 changes: 14 additions & 0 deletions lexcom/lexcom.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Lex\Lex.csproj">
</ProjectReference>
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.0", FrameworkDisplayName = "")]
16 changes: 16 additions & 0 deletions lexcom/obj/Debug/netcoreapp3.0/lexcom.AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Generated by the MSBuild WriteCodeFragment class.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("lexcom")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("lexcom")]
[assembly: System.Reflection.AssemblyTitleAttribute("lexcom")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bc9170369c4781a262e84076e7d137eb34bf1d54
Binary file added lexcom/obj/Debug/netcoreapp3.0/lexcom.assets.cache
Binary file not shown.
Empty file.
Loading