[update] Allowed the parser to parse period specification.

This commit is contained in:
falsycat 2019-10-04 00:00:00 +00:00
parent 3d51830ec7
commit 398ba52c0b
2 changed files with 16 additions and 3 deletions

View File

@ -64,12 +64,17 @@ enum TokenType {
@TextCompleteMatcher!"{" OpenBrace,
@TextCompleteMatcher!"}" CloseBrace,
@TextCompleteMatcher!"[" OpenBracket,
@TextCompleteMatcher!"]" CloseBracket,
@TextCompleteMatcher!"(" OpenParen,
@TextCompleteMatcher!")" CloseParen,
@TextCompleteMatcher!"," Comma,
@TextCompleteMatcher!";" SemiColon,
@TextCompleteMatcher!".." DoubleDot,
@TextCompleteMatcher!"=" Assign,
@TextCompleteMatcher!"+=" AddAssign,

View File

@ -1,6 +1,8 @@
/// License: MIT
module sjscript.parse;
import std.conv;
import dast.parse;
import sjscript.Expression,
@ -13,7 +15,7 @@ unittest {
import dast.tokenize : Tokenize;
enum src = q"EOS
framebuffer 0 {
framebuffer [0..5] {
a = 0;
b += 0;
}
@ -60,8 +62,14 @@ private class RuleSet {
target.text, period, params, CreateTokenPos(target, closebrace));
}
static Period ParsePeriod(@(TokenType.Number) Token) { // TODO
return Period(0, 0);
static Period ParsePeriod(
@(TokenType.OpenBracket) Token,
@(TokenType.Number) Token begin,
@(TokenType.DoubleDot) Token,
@(TokenType.Number) Token end,
@(TokenType.CloseBracket) Token) {
return Period(
begin.text.to!float.to!int, end.text.to!float.to!int);
}
static Parameter[] ParseParameterListFirstItem(Parameter param) {