Kiss My App

Sunday, October 29, 2006

Extending EL Syntax Part 2

This evening, I got much of the parser updated to handle method invocation and projections. One thing I found tricky was handling embeded '{' ... '}' since my original syntax said, "whenever you hit '}', exit the expression token set and go back to literal for composite expressions" (value="Hello #{user.name}" as an example).

To get around embeded '}', I first tried to isolate a separate token set, which was dumb because it only corrected a single nesting of curly braces. Instead I added a simple stack counter such that only when we've reached more end braces than we've created, to jump back out of the expression.


| < LBRACE : "{" > { this.subExpressionCount++; }
| < RBRACE : "}" > { if (--this.subExpressionCount < 0) SwitchTo(DEFAULT); }


Anyways, here's some examples of the new parser. Some of the examples are overly complex, but only prove that the parser is working the way it should.


#{foo.a.b}
Value
Identifier[foo]
PropertySuffix[a]
PropertySuffix[b]

#{foo.a['b']}
Value
Identifier[foo]
PropertySuffix[a]
BracketSuffix
String['b']

#{3 * foo.a.b(e,c,d)}
Mult
Integer[3]
Value
Identifier[foo]
PropertySuffix[a]
MethodSuffix[b]
Identifier[e]
Identifier[c]
Identifier[d]

#{'foo'.length().food}
Value
String['foo']
MethodSuffix[length]
PropertySuffix[food]

#{foo}
Identifier[foo]

#{company.employees@name}
Value
Identifier[company]
PropertySuffix[employees]
ProjectProperty
PropertySuffix[name]

#{company.employees@getName()}
Value
Identifier[company]
PropertySuffix[employees]
ProjectMethod
MethodSuffix[getName]

#{company.employees@each{x|x.salary}}
Value
Identifier[company]
PropertySuffix[employees]
ProjectClosure[each{ x | ... }]
Value
Identifier[x]
PropertySuffix[salary]

#{company.employees@each{x|x.hashCode()}}
Value
Identifier[company]
PropertySuffix[employees]
ProjectClosure[each{ x | ... }]
Value
Identifier[x]
MethodSuffix[hashCode]

#{company.employees@each{x|x@max{y|y.salary}}} is complex
Value
Identifier[company]
PropertySuffix[employees]
ProjectClosure[each{ x | ... }]
Value
Identifier[x]
ProjectClosure[max{ y | ... }]
Value
Identifier[y]
PropertySuffix[salary]
LiteralExpression[ is complex]

1 Comments:

  • great post(s). Things like that should be on the agenda for JSF 6 ... instead of adding random-ajax-components.

    What about modify this

    #{company.employees@asc{x|x.name}}

    that you can specify only the "first 6" ?

    By Anonymous Anonymous, at 12:06 PM  

Post a Comment

<< Home