mirror of
https://github.com/irmen/prog8.git
synced 2024-11-22 00:31:56 +00:00
fix parser rule for identifiers (void is a keyword, not an identifier)
This commit is contained in:
parent
4b4af9b527
commit
504c80cddf
@ -249,7 +249,7 @@ private fun Asmsub_paramsContext.toAst(): List<AsmSubroutineParameter>
|
|||||||
val identifiers = vardecl.identifier()
|
val identifiers = vardecl.identifier()
|
||||||
if(identifiers.size>1)
|
if(identifiers.size>1)
|
||||||
throw SyntaxError("parameter name must be singular", identifiers[0].toPosition())
|
throw SyntaxError("parameter name must be singular", identifiers[0].toPosition())
|
||||||
val identifiername = identifiers[0].NAME() ?: identifiers[0].UNDERSCORENAME() ?: identifiers[0].VOID()
|
val identifiername = identifiers[0].NAME() ?: identifiers[0].UNDERSCORENAME()
|
||||||
AsmSubroutineParameter(identifiername.text, datatype, registerorpair, statusregister, toPosition())
|
AsmSubroutineParameter(identifiername.text, datatype, registerorpair, statusregister, toPosition())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ private fun Sub_paramsContext.toAst(): List<SubroutineParameter> =
|
|||||||
val identifiers = it.identifier()
|
val identifiers = it.identifier()
|
||||||
if(identifiers.size>1)
|
if(identifiers.size>1)
|
||||||
throw SyntaxError("parameter name must be singular", identifiers[0].toPosition())
|
throw SyntaxError("parameter name must be singular", identifiers[0].toPosition())
|
||||||
val identifiername = identifiers[0].NAME() ?: identifiers[0].UNDERSCORENAME() ?: identifiers[0].VOID()
|
val identifiername = identifiers[0].NAME() ?: identifiers[0].UNDERSCORENAME()
|
||||||
SubroutineParameter(identifiername.text, datatype, zp, it.toPosition())
|
SubroutineParameter(identifiername.text, datatype, zp, it.toPosition())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,10 +343,7 @@ private fun Assign_targetContext.toAst() : AssignTarget {
|
|||||||
return when(this) {
|
return when(this) {
|
||||||
is IdentifierTargetContext -> {
|
is IdentifierTargetContext -> {
|
||||||
val identifier = scoped_identifier().toAst()
|
val identifier = scoped_identifier().toAst()
|
||||||
if(identifier.nameInSource==listOf("void"))
|
AssignTarget(identifier, null, null, null, false, scoped_identifier().toPosition())
|
||||||
AssignTarget(null, null, null, null, true, scoped_identifier().toPosition())
|
|
||||||
else
|
|
||||||
AssignTarget(identifier, null, null, null, false, scoped_identifier().toPosition())
|
|
||||||
}
|
}
|
||||||
is MemoryTargetContext ->
|
is MemoryTargetContext ->
|
||||||
AssignTarget(null, null, DirectMemoryWrite(directmemory().expression().toAst(), directmemory().toPosition()), null, false, toPosition())
|
AssignTarget(null, null, DirectMemoryWrite(directmemory().expression().toAst(), directmemory().toPosition()), null, false, toPosition())
|
||||||
@ -357,6 +354,9 @@ private fun Assign_targetContext.toAst() : AssignTarget {
|
|||||||
val arrayindexed = ArrayIndexedExpression(arrayvar, index, ax.toPosition())
|
val arrayindexed = ArrayIndexedExpression(arrayvar, index, ax.toPosition())
|
||||||
AssignTarget(null, arrayindexed, null, null, false, toPosition())
|
AssignTarget(null, arrayindexed, null, null, false, toPosition())
|
||||||
}
|
}
|
||||||
|
is VoidTargetContext -> {
|
||||||
|
AssignTarget(null, null, null, null, true, void_().toPosition())
|
||||||
|
}
|
||||||
else -> throw FatalAstException("weird assign target node $this")
|
else -> throw FatalAstException("weird assign target node $this")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -716,7 +716,7 @@ private fun VardeclContext.toAst(type: VarDeclType, value: Expression?): VarDecl
|
|||||||
val options = decloptions()
|
val options = decloptions()
|
||||||
val zp = getZpOption(options)
|
val zp = getZpOption(options)
|
||||||
val identifiers = identifier()
|
val identifiers = identifier()
|
||||||
val identifiername = identifiers[0].NAME() ?: identifiers[0].UNDERSCORENAME() ?: identifiers[0].VOID()
|
val identifiername = identifiers[0].NAME() ?: identifiers[0].UNDERSCORENAME()
|
||||||
val name = if(identifiers.size==1) identifiername.text else "<multiple>"
|
val name = if(identifiers.size==1) identifiername.text else "<multiple>"
|
||||||
val isArray = ARRAYSIG() != null || arrayindex() != null
|
val isArray = ARRAYSIG() != null || arrayindex() != null
|
||||||
val split = options.SPLIT().isNotEmpty()
|
val split = options.SPLIT().isNotEmpty()
|
||||||
@ -744,7 +744,7 @@ private fun VardeclContext.toAst(type: VarDeclType, value: Expression?): VarDecl
|
|||||||
arrayindex()?.toAst(),
|
arrayindex()?.toAst(),
|
||||||
name,
|
name,
|
||||||
if(identifiers.size==1) emptyList() else identifiers.map {
|
if(identifiers.size==1) emptyList() else identifiers.map {
|
||||||
val idname = it.NAME() ?: it.UNDERSCORENAME() ?: it.VOID()
|
val idname = it.NAME() ?: it.UNDERSCORENAME()
|
||||||
idname.text
|
idname.text
|
||||||
},
|
},
|
||||||
value,
|
value,
|
||||||
|
@ -171,6 +171,7 @@ assign_target:
|
|||||||
scoped_identifier #IdentifierTarget
|
scoped_identifier #IdentifierTarget
|
||||||
| arrayindexed #ArrayindexedTarget
|
| arrayindexed #ArrayindexedTarget
|
||||||
| directmemory #MemoryTarget
|
| directmemory #MemoryTarget
|
||||||
|
| void #VoidTarget
|
||||||
;
|
;
|
||||||
|
|
||||||
multi_assign_target:
|
multi_assign_target:
|
||||||
@ -211,6 +212,8 @@ arrayindexed:
|
|||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
void : VOID ;
|
||||||
|
|
||||||
typecast : 'as' datatype;
|
typecast : 'as' datatype;
|
||||||
|
|
||||||
directmemory : '@' '(' expression ')';
|
directmemory : '@' '(' expression ')';
|
||||||
@ -231,7 +234,7 @@ breakstmt : 'break';
|
|||||||
|
|
||||||
continuestmt: 'continue';
|
continuestmt: 'continue';
|
||||||
|
|
||||||
identifier : NAME | UNDERSCORENAME | VOID;
|
identifier : NAME | UNDERSCORENAME ;
|
||||||
|
|
||||||
scoped_identifier : identifier ('.' identifier)* ;
|
scoped_identifier : identifier ('.' identifier)* ;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user