PDA

View Full Version : EBNF definition of LWS



dulo
08-08-2012, 10: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 ..

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

dulo
08-08-2012, 11:13 AM
http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form
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 ..

dulo
08-10-2012, 03: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
@property
def SceneText(self):
return self.__sceneText
@SceneText.setter
def SceneText(self, sceneText):
self.__sceneText = sceneText
@SceneText.deleter
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)