HomeForumSourceResearchGuide
Sign in to contribute to source. how it works
Component util.compiler.SyntaxParser by barry
expand copy to clipboardexpand
interface DNSyntaxParserLib {
	int construct(String searchPaths[], int addressWidth)
	ParseResult parse(int handle, char source[], char target[], KeyValue memFiles[])
	DanaType[] getTypes(int handle)
	void destroy(int handle)
}

data ConInt {
	int value
}

uses data.String

component provides SyntaxParser(Destructor) requires io.Output out, native DNSyntaxParserLib lib {

	int handle = 0
	bool parseUsed = false

	int getNativeAddressWidth()
		{
		ConInt c = new ConInt()
		return dana.serial(c).arrayLength
		}

	SyntaxParser:SyntaxParser(store String paths[], opt int aw)
		{
		int hostAddressSize = getNativeAddressWidth()

		if (isset aw)
			{
			hostAddressSize = aw
			}
		
		handle = lib.construct(paths, hostAddressSize)

		if (handle == 0) throw new Exception("failed to instantiate parsing library")
		}
	
	ParseResult SyntaxParser:parse(char source[], opt char filePath[], KeyValue memFiles[])
		{
		if (parseUsed) throw new Exception("you must create a new parser instance for each new parse")
		parseUsed = true
		return lib.parse(handle, source, filePath, memFiles)
		}
	
	DanaType[] SyntaxParser:getTypes()
		{
		return lib.getTypes(handle)
		}
	
	void Destructor:destroy()
		{
		lib.destroy(handle)
		}
	
	}
Revision history
To propose a new revision to this entity, use dana source put -uc your/new/version.dn -n util.compiler.SyntaxParser -m "reason for update" -u yourUsername
Version 1 (this version) by barry
Notes for this version: New compiler components