X-Sharp/XSharpPublic

Macrocompiler problem with some keywords as identifiers

Closed this issue · 3 comments

DbCreateIndex(, "REF") when there's a field named "REF" fails with Macrocompiler (1,4): error XM0101: Unexpected 'REF'
Same goes for "IS". Other keywords like "OUT", "IN", "CLASS" etc work fine.

Sample below testing with several keywords, will ad dmore if I find them causing problems. Code is written in a way that is also compilable in VO (where it always works well):

FUNCTION Start() AS VOID
	LOCAL aStruct := {} AS ARRAY
	LOCAL aKeywords AS ARRAY
	LOCAL cField AS STRING
	LOCAL cDbf AS STRING
	LOCAL oError AS USUAL
	LOCAL n AS INT

	cDbf := "c:\test\keywords"
	
	aKeywords := {"CLASS", "METHOD", "IN", "OUT", "REF", "IS", "_CAST", "IF", "FIELD", "DEFAULT", "IIF", "CHECKED", "UNCHECKED"}
	
	FOR n := 1 UPTO ALen(aKeywords)
		AAdd(aStruct , {aKeywords[n] , "N" , 10 ,0})
	NEXT
	
	FErase(cdbf+".cdx")
	DbCreate(cDbf, aStruct)
	DbUseArea(TRUE,"DBFCDX",cDbf)
	DbAppend()
	FOR n := 1 UPTO ALen(aKeywords)
		FieldPut(n,2)
	NEXT
	DbAppend()
	FOR n := 1 UPTO ALen(aKeywords)
		FieldPut(n,1)
	NEXT
	
	FOR n := 1 UPTO ALen(aKeywords)
		cField := aKeywords[n]
		? "Adding order on field", cField
		BEGIN SEQUENCE
		? DbCreateOrder(cField, cDbf, cField)
		DbSetOrder(n)
		DbGoTop()
		? "RecNo:", RecNo() , "," , iif(RecNo()==2,"OK","WRONG")
		? "Order expression:", DbOrderInfo(DBOI_EXPRESSION)
		RECOVER USING oError
			? "********* ERROR *********"
			? oError:Message
		END SEQUENCE
		? 
	NEXT
	
	DbCloseArea()

XSharp.MacroCompiler.CompilationError
Macrocompiler (1,4): error XM0101: Unexpected 'REF'

Callstack : 
XSharp.MacroCompiler.Parser.[SpecializedMethod XSharp.MacroCompiler.Parser.RequireEnd[XSharp.MacroCompiler.Syntax.Codeblock](n:XSharp.MacroCompiler.Syntax.Codeblock, error:XSharp.MacroCompiler.ErrorCode, params args:System.Object[]):XSharp.MacroCompiler.Syntax.Codeblock]
XSharp.MacroCompiler.Parser.[Method XSharp.MacroCompiler.Parser.ParseMacro():XSharp.MacroCompiler.Syntax.Codeblock]
XSharp.MacroCompiler.Compilation.[SpecializedMethod XSharp.MacroCompiler.Compilation`1[[XSharp.__Usual]].Parse(source:System.String):XSharp.MacroCompiler.Syntax.Node]
XSharp.MacroCompiler.Compilation.[SpecializedMethod XSharp.MacroCompiler.Compilation`1[[XSharp.__Usual]].Compile[XSharp.MacroCompiler.UsualMacro.MacroCodeblockDelegate](source:System.String):XSharp.MacroCompiler.Compilation`1+CompilationResult`1[[XSharp.__Usual],[XSharp.MacroCompiler.UsualMacro.MacroCodeblockDelegate]]]
XSharp.MacroCompiler.Compilation.[SpecializedMethod XSharp.MacroCompiler.Compilation`2[[XSharp.__Usual],[XSharp.MacroCompiler.UsualMacro.MacroCodeblockDelegate]].Compile(source:System.String):XSharp.MacroCompiler.Compilation`1+CompilationResult`1[[XSharp.__Usual],[XSharp.MacroCompiler.UsualMacro.MacroCodeblockDelegate]]]
XSharp.Runtime.MacroCompiler.[Method XSharp.Runtime.MacroCompiler.CompileCodeblock(macro:System.String, lAllowSingleQuotes:System.Boolean, module:System.Reflection.Module):XSharp._Codeblock]
[Method XSharp.RT.Functions.MCompile(cString:System.String, lAllowSingleQuotes:System.Boolean):XSharp._Codeblock]
[Method XSharp.RT.Functions.Evaluate(cString:System.String, lAllowSingleQuotes:System.Boolean):XSharp.__Usual]
[Method XSharp.RT.Functions.Evaluate(cString:System.String):XSharp.__Usual]
[Method XSharp.RT.Functions.OrdCreate(params Xs$Args:XSharp.__Usual[]):System.Boolean]
[Method XSharp.RT.Functions.DbCreateOrder(params Xs$Args:XSharp.__Usual[]):System.Boolean]
[Method XSharpRuntimeApp1.Exe.Functions.Start():System.Void]  :  C:\VIDE\Projects\ONE\Applications\XSharpRuntimeApp1\Prg\Start.prg  :  33

Complete list of keywords/field names that cause the macro compiler to chocke (good thing I already had the list of all keywords available in an array in XIDE!):

REF
IS
_CAST
IF
FIELD
DEFAULT
IIF
CHECKED
UNCHECKED

The macro compiler still chocks on "DEFAULT", "CHECKED" and "UNCHECKED" (all working OK in VO. "UNCHECKED" is highly unlikely to by used, but I wouldn't be surprised if there are dbfs out there with field names DEFAULT and CHECKED. I have updated the sample code here.

Confirmed fixed