Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
#3 Remove Parser
Browse files Browse the repository at this point in the history
We removed the parser and added a scan method instead of the parser in the scanner.
  • Loading branch information
Gallimathias committed Dec 19, 2017
1 parent 8a9dbf8 commit d427c9b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 34 deletions.
1 change: 0 additions & 1 deletion Arrow.Core/Arrow.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<Compile Include="Parsing\Definition\TypeDeclarationSyntax.cs" />
<Compile Include="Parsing\Definition\VariableDeclarationSyntax.cs" />
<Compile Include="Parsing\IScanable.cs" />
<Compile Include="Parsing\Parser.cs" />
<Compile Include="Parsing\RawKind.cs" />
<Compile Include="Parsing\Scanner.cs" />
<Compile Include="Parsing\Syntax.cs" />
Expand Down
17 changes: 9 additions & 8 deletions Arrow.Core/ArrowCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Arrow.Core.Parsing;
using Arrow.Core.Parsing.Definition;
using Arrow.Core.Scanning;
using Arrow.Core.Visitors;
using System;
Expand All @@ -18,8 +19,8 @@ public Func<T> RunFunc<T>(string input)
var tokenDefinitions = TokenDefinitionCollection.LoadFromIntern();
var tokenizer = new Tokenizer(tokenDefinitions);
var tokenResult = tokenizer.Parse(input);
var parser = new Parser();
var synatxTree = parser.Parse(tokenResult);
var scanner = new Scanner();
var synatxTree = new SyntaxTree(scanner.Scan<StatmentSyntax>(new SyntaxStream(tokenResult)));
return synatxTree.Visit<T>();
}

Expand All @@ -28,8 +29,8 @@ public Action RunVoid(string input)
var tokenDefinitions = TokenDefinitionCollection.LoadFromIntern();
var tokenizer = new Tokenizer(tokenDefinitions);
var tokenResult = tokenizer.Parse(input);
var parser = new Parser();
var synatxTree = parser.Parse(tokenResult);
var scanner = new Scanner();
var synatxTree = new SyntaxTree(scanner.Scan<StatmentSyntax>(new SyntaxStream(tokenResult)));
return synatxTree.Visit();
}

Expand All @@ -43,10 +44,10 @@ public Assembly GetAssembly(string input)
var tokenDefinitions = TokenDefinitionCollection.LoadFromIntern();
var tokenizer = new Tokenizer(tokenDefinitions);
var tokenResult = tokenizer.Parse(input);
var parser = new Parser();
var synatxTree = parser.Parse(tokenResult);
var scanner = new Scanner();
var expression = scanner.Scan<NamespaceDeclarationSyntax>(new SyntaxStream(tokenResult));

visitor.Visit(synatxTree.Expression, new ProgramScope(moduleBuilder));
visitor.Visit(expression, new ProgramScope(moduleBuilder));

moduleBuilder.CreateGlobalFunctions();

Expand All @@ -55,4 +56,4 @@ public Assembly GetAssembly(string input)
return assemblyBuilder;
}
}
}
}
24 changes: 0 additions & 24 deletions Arrow.Core/Parsing/Parser.cs

This file was deleted.

9 changes: 9 additions & 0 deletions Arrow.Core/Parsing/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ internal Syntax Scan(SyntaxStream syntaxStream)
throw new Exception($"Syntax {syntaxStream.SyntaxList.FirstOrDefault()} not found!");
}

internal Syntax Scan<T>(SyntaxStream syntaxStream)
where T : Syntax,new()
{
if (TryScan<T>(syntaxStream, out var syntax))
return syntax;

throw new Exception($"Syntax {syntaxStream.SyntaxList.FirstOrDefault()} not found!");
}


internal void Collect()
{
Expand Down
2 changes: 2 additions & 0 deletions Arrow.Core/Parsing/Syntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Arrow.Core.Parsing
{
public abstract class Syntax : IScanable
{
public int Position { get; set; }
public int Length { get; set; }

public string Name { get; protected set; }

Expand Down
4 changes: 3 additions & 1 deletion Arrow.Core/Parsing/SyntaxStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace Arrow.Core.Parsing
public class SyntaxStream
{
public int Count => baseStream != null ? length : syntaxList.Count;

public int GlobalPosition => baseStream == null ? 0 : baseStream.GlobalPosition + index;


private List<Syntax> syntaxList;
private SyntaxStream baseStream;
private int index;
Expand Down

0 comments on commit d427c9b

Please sign in to comment.