View Full Version : EBNF definition of LWS

08-08-2012, 09:54 AM
@Newtek: Is there a EBNF definition of the lws format, or an regexp definition ? I guess/hope you have something for your own scene parsing. Can you share this definition if its existing ?

Has anyone created something like this already ? I dont wanna start from scratch, but I have to parse a lot of lws files ..

08-08-2012, 10:09 AM
Not quite sure what the EBNF definition is. Is it like a code highlighter?

08-08-2012, 10:13 AM
EBNF defines the "language" of a text or file. with an EBNF definition you can create a parser in some minutes. I guess NT uses some kind of parser generation to parse their own lws files ..

08-10-2012, 02:36 AM
I started to write a little lws parser based on simpleparse (EBNF). Its far away from working but it parses at least the first 50 lines of a lws file atm. I have a little problem with the braket definition of the plugins with "plugin" and "endplugin", but I am working on it...

from simpleparse.parser import Parser

def getLWSParser(rootString):
declaration = getParserDefinition()
parser = Parser( declaration, rootString )
return parser

def getParserDefinition():
declaration = r'''# note use of raw string when embedding in python code...

newline := "\n"
fileversion := [3-5]
letter := [a-zA-Z]
numeral := [0-9]
integer := numeral+
integerrange := integer,"-",integer
validChars := [a-zA-Z0-9_.-]
validFirstChar := [a-zA-Z.]
lettersAndNumbers := [a-zA-Z0-9_.]
identifier := validFirstChar,validChars*
namevaluepair := identifier,spaces,integer
MasterPlugin := "Plugin",space,"MasterHandler",space,integer,space,identifier,newline,"EndPlugin"
anything := [a-zA-Z0-9 -_\n{}<>".,]
anythings := anything+
space := [ ]
spaces := space+
envelope := ("{ Envelope", [.]+, "}")
key := ("Key", space, integer, space)
# known elements
FileHeader := ("LWSC",newline,fileversion,newline)
RenderRangeType := "RenderRangeType", spaces, integer
FirstFrame := "FirstFrame", spaces, integer
LastFrame := "LastFrame", spaces, integer
FrameStep := "FrameStep", spaces, integer
RenderRangeObject := "RenderRangeObject", spaces, integer
RenderRangeArbitrary := "RenderRangeArbitrary", spaces, integerrange
PreviewFirstFrame := "PreviewFirstFrame", spaces, integer
PreviewLastFrame := "PreviewLastFrame", spaces, integer
PreviewFrameStep := "PreviewFrameStep", spaces, integer
CurrentFrame := "CurrentFrame", spaces, integer
FramesPerSecond := "FramesPerSecond", spaces, integer
ChangeScene := "ChangeScene", spaces, integer

knownelements := MasterPlugin / MasterPlugin2 / FileHeader / RenderRangeType / FirstFrame/LastFrame/FrameStep/RenderRangeObject/RenderRangeArbitrary/PreviewFirstFrame/PreviewLastFrame/PreviewFrameStep/CurrentFrame/FramesPerSecond/ChangeScene/newline/spaces

token := FileHeader / newline / fileversion / integerrange / namevaluepair / spaces / identifier / integer
document := knownelements+
return declaration

class SceneParser:
def __init__(self):
self.__sceneText = None
self.__parser = None
def SceneText(self):
return self.__sceneText
def SceneText(self, sceneText):
self.__sceneText = sceneText
def SceneText(self):
del self.__sceneText
def Load (self, path):
f = file(path)
self.SceneText = f.read()
def ParseLWS(self):
if self.__parser is None:
self.__parser = getLWSParser("document")
return self.__parser.parse(self.SceneText)