From 398ba52c0b1bd67b302e1c4425fef48d350d9e9e Mon Sep 17 00:00:00 2001 From: falsycat Date: Fri, 4 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Allowed the parser to parse period specification. --- sjscript/src/sjscript/Token.d | 5 +++++ sjscript/src/sjscript/parse.d | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sjscript/src/sjscript/Token.d b/sjscript/src/sjscript/Token.d index 0bdb0d4..6bc955f 100644 --- a/sjscript/src/sjscript/Token.d +++ b/sjscript/src/sjscript/Token.d @@ -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, diff --git a/sjscript/src/sjscript/parse.d b/sjscript/src/sjscript/parse.d index 42eb999..85b23af 100644 --- a/sjscript/src/sjscript/parse.d +++ b/sjscript/src/sjscript/parse.d @@ -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) {