Feature: Array Iteration in NeoLang

This commit is contained in:
zt515
2017-08-09 02:38:06 +08:00
parent 44947f05aa
commit 04b73fc50e
6 changed files with 110 additions and 40 deletions

View File

@ -77,6 +77,9 @@ class NeoLangParser {
return NeoLangProgramNode.emptyNode()
}
/**
* @param attrName Only available when group is a attribute value
*/
private fun group(): NeoLangGroupNode? {
val token = currentToken ?: throw InvalidTokenException("Unexpected token: null")
@ -115,13 +118,11 @@ class NeoLangParser {
private fun array(arrayName: NeoLangStringNode): NeoLangArrayNode? {
val token = currentToken ?: throw InvalidTokenException("Unexpected token: null")
// TODO: Multiple Array
var block = blockNonArrayElement(arrayName)
var index = 0
if (block != null) {
val elements = mutableListOf(NeoLangArrayElement(index++, block))
if (match(NeoLangTokenType.COMMA)) {
@ -149,7 +150,7 @@ class NeoLangParser {
/**
* @attrName The block holder's name
* @param attrName The block holder's name
*/
private fun block(attrName: NeoLangStringNode): NeoLangBlockNode? {
val block = blockNonArrayElement(attrName)
@ -172,7 +173,10 @@ class NeoLangParser {
}
}
private fun blockNonArrayElement(attrName: NeoLangStringNode): NeoLangBlockNode? {
/**
* @param attrName Only available when group is a attribute value
*/
private fun blockNonArrayElement(attrName: NeoLangStringNode?): NeoLangBlockNode? {
val token = currentToken ?: throw InvalidTokenException("Unexpected token: null")
return when (token.tokenType) {