-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from vein-lang/improvements/compiler-features
for loop support and other improvements
- Loading branch information
Showing
11 changed files
with
255 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace vein.syntax; | ||
|
||
using Sprache; | ||
|
||
public class ForStatementSyntax( | ||
IOption<LocalVariableDeclaration> loopVariable, | ||
IOption<ExpressionSyntax> loopContact, | ||
IOption<ExpressionSyntax> loopCounter, | ||
StatementSyntax statement) | ||
: StatementSyntax, IPositionAware<ForStatementSyntax> | ||
{ | ||
public LocalVariableDeclaration? LoopVariable { get; } = loopVariable.GetOrDefault(); | ||
public ExpressionSyntax? LoopContact { get; } = loopContact.GetOrDefault(); | ||
public ExpressionSyntax? LoopCounter { get; } = loopCounter.GetOrDefault(); | ||
public StatementSyntax Statement { get; } = statement; | ||
|
||
|
||
public override SyntaxType Kind => SyntaxType.ForEachStatement; | ||
|
||
public override IEnumerable<BaseSyntax> ChildNodes | ||
=> new BaseSyntax[] { LoopVariable!, LoopContact!, LoopCounter!, Statement }.Where(x => x is not null).ToList(); | ||
|
||
public new ForStatementSyntax SetPos(Position startPos, int length) | ||
{ | ||
base.SetPos(startPos, length); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
namespace vein.syntax | ||
{ | ||
using System.Collections.Generic; | ||
using Sprache; | ||
namespace vein.syntax; | ||
|
||
public class ForeachStatementSyntax : StatementSyntax, IPositionAware<ForeachStatementSyntax> | ||
{ | ||
public LocalVariableDeclaration Variable { get; } | ||
public ExpressionSyntax Expression { get; } | ||
public StatementSyntax Statement { get; } | ||
using System.Collections.Generic; | ||
using Sprache; | ||
|
||
public class ForeachStatementSyntax( | ||
LocalVariableDeclaration declaration, | ||
ExpressionSyntax exp, | ||
StatementSyntax statement) | ||
: StatementSyntax, IPositionAware<ForeachStatementSyntax> | ||
{ | ||
public LocalVariableDeclaration Variable { get; } = declaration; | ||
public ExpressionSyntax Expression { get; } = exp; | ||
public StatementSyntax Statement { get; } = statement; | ||
|
||
public override SyntaxType Kind => SyntaxType.ForEachStatement; | ||
|
||
public override IEnumerable<BaseSyntax> ChildNodes => new List<BaseSyntax> { Variable, Expression, Statement }; | ||
public override SyntaxType Kind => SyntaxType.ForEachStatement; | ||
|
||
public ForeachStatementSyntax(LocalVariableDeclaration declaration, ExpressionSyntax exp, StatementSyntax statement) | ||
{ | ||
Variable = declaration; | ||
Expression = exp; | ||
Statement = statement; | ||
} | ||
public override IEnumerable<BaseSyntax> ChildNodes => new List<BaseSyntax> { Variable, Expression, Statement }; | ||
|
||
public new ForeachStatementSyntax SetPos(Position startPos, int length) | ||
{ | ||
base.SetPos(startPos, length); | ||
return this; | ||
} | ||
public new ForeachStatementSyntax SetPos(Position startPos, int length) | ||
{ | ||
base.SetPos(startPos, length); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace veinc_test.Features; | ||
|
||
public class ForFeatureTest | ||
{ | ||
public static VeinSyntax Syntax => new(); | ||
|
||
[Test] | ||
public void Test1() => | ||
Syntax.for_statement.ParseVein( | ||
""" | ||
for(let i = 0; i != 15; i++) { | ||
Out.print("hello world!"); | ||
} | ||
"""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
namespace veinc_test.Features; | ||
|
||
public class GenericDocumentFeature | ||
{ | ||
public static VeinSyntax Syntax = new(); | ||
|
||
[Test] | ||
public void test1() | ||
{ | ||
Syntax.CompilationUnit.ParseVein( | ||
""" | ||
#space "test" | ||
#use "vein/lang" | ||
struct App { | ||
public test2(): void | ||
{ | ||
for (let i = 55; i++; i != 500) { | ||
Out.print("hello world!"); | ||
} | ||
} | ||
public test1(): void { | ||
fail null; | ||
} | ||
public test1(): void { | ||
let b = "asdads" + "gfdfg"; | ||
} | ||
public static master(): void { | ||
Out.print(Fib(15)); | ||
} | ||
public static Fib(n: i32): i32 | ||
{ | ||
if (n < 2) | ||
{ | ||
return n; | ||
} | ||
auto a = Fib(n - 1); | ||
auto b = Fib(n - 2) | ||
return a + b; | ||
} | ||
} | ||
""" | ||
); | ||
} | ||
|
||
[Test] | ||
public void test2() | ||
{ | ||
Syntax.CompilationUnit.ParseVein( | ||
""" | ||
#space "test" | ||
#use "vein/lang" | ||
struct App { | ||
public test1(): i32 { return 1; } | ||
public test2(): void { } | ||
public test3(): boolean { return false; } | ||
public test4(): string { return "test"; } | ||
public test5(): void { } | ||
public test6(): void { } | ||
} | ||
""" | ||
); | ||
} | ||
|
||
[Test] | ||
public void test3() | ||
{ | ||
Syntax.CompilationUnit.ParseVein( | ||
""" | ||
#space "test" | ||
#use "vein/lang" | ||
struct App { | ||
public test1(): i32 { fail null; } | ||
public test2(): void { } | ||
public test3(): boolean { | ||
if (true) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
public test4(): string { return "test"; } | ||
public test5(i: i32): void { } | ||
public test6(b: string): void { } | ||
} | ||
""" | ||
); | ||
} | ||
|
||
[Test] | ||
public void test4() | ||
{ | ||
Syntax.CompilationUnit.ParseVein( | ||
""" | ||
#space "test" | ||
#use "vein/lang" | ||
struct App | ||
{ | ||
public test1(): void | ||
{ | ||
let b = "asdads" + "gfdfg"; | ||
} | ||
public static master(): void { | ||
Out.print(Fib(15)); | ||
} | ||
public static Fib(n: i32): i32 | ||
{ | ||
if (n < 2) | ||
{ | ||
return n; | ||
} | ||
auto a = Fib(n - 1); | ||
auto b = Fib(n - 2) | ||
return a + b; | ||
} | ||
} | ||
""" | ||
); | ||
} | ||
} |