This project has moved and is read-only. For the latest updates, please go here.

Parsing qml problem

Nov 26, 2014 at 8:51 AM
Edited Nov 26, 2014 at 8:53 AM
Hi I've got a bit of a problem, I have started doing a qml parser, but I've got a problem with nested qml Objects. For the following qml structure:
     objects: Obj 
     //opacity: 0.5
I'm gettng a Syntax error like
Syntax error, expected: qmlLabel, SingleLineComment, DelimitedComment, }
The code that I'm using looks like that:
var qmlLabel = new IdentifierTerminal("qmlLabel","0123456789_");
            var qmlPropertylabel = new IdentifierTerminal("qmlLabel", "0123456789_");
            var qmlString = new StringLiteral("string", "\"");
            var qmlNumber = new NumberLiteral("number");
            var qmlObjectName = new IdentifierTerminal("ObjectName", "0123456789_");
            CommentTerminal SingleLineComment = new CommentTerminal("SingleLineComment", "//", "\r", "\n", "\u2085", "\u2028", "\u2029");
            CommentTerminal DelimitedComment = new CommentTerminal("DelimitedComment", "/*", "*/");
            var qmlObject = new NonTerminal("qmlObject");
            var qmlObjectBody = new NonTerminal("qmlObjectBody");
            var qmlObjectBodyBarced = new NonTerminal("qmlobjectBodyBraced");

            var qmlPropertyValue = new NonTerminal("qmlPropertyValue");
            var qmlPropertyKeyValue = new NonTerminal("qmlPropertyKeyValue");
            var qmlPropertyKey = new NonTerminal("qmlPropertyKey");

            qmlObject.Rule = qmlObjectName + qmlObjectBodyBarced;
            qmlObjectBodyBarced.Rule = "{" + qmlObjectBody + "}";
            qmlObjectBody.Rule = MakeStarRule(qmlObjectBody, qmlPropertyKeyValue | SingleLineComment | DelimitedComment);

            qmlPropertyKeyValue.Rule = qmlPropertyKey + ":" + qmlPropertyValue;
            qmlPropertyKey.Rule = qmlPropertylabel;
            qmlPropertyValue.Rule = qmlObject | qmlLabel | qmlString | qmlNumber;

            this.Root = qmlObject;
Perhaps this is a silly question but I don't really understand what is wrong, and besides I'm quite new to Irony (and BNF stuff) and it is quite hard to move around without docs and simple examples ;)
If BNF would help I can post it I don't want to clutter the post more than needed.
It works quite ok for any property that is not an qml Object or reference to other object's property (that's for later), but the problem is with the nasty nesting.

Best Regards,
Dec 8, 2014 at 9:43 PM
one troubled thing I see - qmlObjectBodyRule. Do NOT use expression as second parameter of MakeStarRule, define term explicitly. And really strange thing - what is the delimiter for object 'parts'? NewLine symbol? Or no delimiter, just whitespace? From your source, it looks like it should be newLine, but from qmlObjectBody it looks like just a whitespace.
Another thing - do not use comment terminals in Rules, it's enough if you added them to NonGrammarTErminals