[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!"{" OpenBrace,
@TextCompleteMatcher!"}" CloseBrace, @TextCompleteMatcher!"}" CloseBrace,
@TextCompleteMatcher!"[" OpenBracket,
@TextCompleteMatcher!"]" CloseBracket,
@TextCompleteMatcher!"(" OpenParen, @TextCompleteMatcher!"(" OpenParen,
@TextCompleteMatcher!")" CloseParen, @TextCompleteMatcher!")" CloseParen,
@TextCompleteMatcher!"," Comma, @TextCompleteMatcher!"," Comma,
@TextCompleteMatcher!";" SemiColon, @TextCompleteMatcher!";" SemiColon,
@TextCompleteMatcher!".." DoubleDot,
@TextCompleteMatcher!"=" Assign, @TextCompleteMatcher!"=" Assign,
@TextCompleteMatcher!"+=" AddAssign, @TextCompleteMatcher!"+=" AddAssign,

View File

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