`
jetway
  • 浏览: 483650 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

comments

阅读更多
Item Description
Comments Specified using ## or //and extend to the end of line, e.g.
## This is a comment
Also specified using //, e.g.
// This is a comment
Multiple lines comments are specified using /*...*/, e.g.
/* This is a
            multi-line comment */
Identifiers / variables Must start with a-z, A-Z, _ or $. Can then be followed by 0-9, a-z, A-Z, _ or $. e.g.
  • Valid: var1,_a99,$1
  • Invalid: 9v,!a99,1$

Variable names are case-sensitive, e.g. var1 and Var1 are different variables.

NOTE: JEXL does not support variables with hyphens in them, e.g.

commons-logging // invalid variable name (hyphenated)
is not a valid variable, but instead is treated as a subtraction of the variable logging from the variable commons

 

JEXL also supports ant-style variables, the following is a valid variable name:

my.dotted.var

 

N.B. the following keywords are reserved, and cannot be used as a variable name or property when using the dot operator: or and eq ne lt gt le ge div mod not null true false new For example, the following is invalid:

my.new.dotted.var // invalid ('new' is keyword)
In such cases, the [ ] operator can be used, for example:
my['new'].dotted.var

 

Scripts A script in Jexl is made up of zero or more statements. Scripts can be read from a String, File or URL.
Statements A statement can be the empty statement, the semicolon (;) , block, assignment or an expression. Statements are optionally terminated with a semicolon.
Block A block is simply multiple statements inside curly braces ({, }).
Assignment Assigns the value of a variable (my.var = 'a value') using a JexlContext as initial resolver. Both beans and ant-ish variables assignment are supported.
Method calls Calls a method of an object, e.g.
"hello world".hashCode()
will call the hashCode method of the "hello world" String.

In case of multiple arguments and overloading, Jexl will make the best effort to find the most appropriate non ambiguous method to call.

Literals

Item Description
Integer Literals 1 or more digits from 0 to 9
Floating point Literals 1 or more digits from 0 to 9, followed by a decimal point and then one or more digits from 0 to 9.
String literals Can start and end with either ' or " delimiters, e.g.
"Hello world"
and
'Hello world'
are equivalent.

The escape character is \; it only escapes the string delimiter

Boolean literals The literals true and false can be used, e.g.
val1 == true
Null literal The null value is represented as in java using the literal null, e.g.
val1 == null
Array literal A [ followed by one or more expressions separated by , and ending with ], e.g.
[ 1, 2, "three" ]

This syntax creates an Object[].

JEXL will attempt to strongly type the array; if all entries are of the same class or if all entries are Number instance, the array literal will be an MyClass[] in the former case, a Number[] in the latter case.

Furthermore, if all entries in the array literal are of the same class and that class has an equivalent primitive type, the array returned will be a primitive array. e.g. [1, 2, 3] will be interpreted as int[].

Map literal A { followed by one or more sets of key : value pairs separated by , and ending with }, e.g.
{ "one" : 1, "two" : 2, "three" : 3, "more": "many more" }

This syntax creates a HashMap<Object,Object>.

Functions

Function Description
empty Returns true if the expression following is either:
  1. null
  2. An empty string
  3. An array of length zero
  4. A collection of size zero
  5. An empty map
empty(var1)
size Returns the information about the expression:
  1. Length of an array
  2. Size of a List
  3. Size of a Map
  4. Size of a Set
  5. Length of a string
size("Hello")
returns 5.
new Creates a new instance using a fully-qualified class name or Class:
new("java.lang.Double", 10)
returns 10.0.

Note that the first argument of new can be a variable or any expression evaluating as a String or Class; the rest of the arguments are used as arguments to the constructor for the class considered.

In case of multiple constructors, Jexl will make the best effort to find the most appropriate non ambiguous constructor to call.

ns:function A JexlEngine can register objects or classes used as function namespaces. This can allow expressions like:
math:cosinus(23.0)

Operators

Operator Description
Boolean and The usual && operator can be used as well as the word and, e.g.
cond1 and cond2
and
cond1 && cond2
are equivalent
Boolean or The usual || operator can be used as well as the word or, e.g.
cond1 or cond2
and
cond1 || cond2
are equivalent
Boolean not The usual ! operator can be used as well as the word not, e.g.
!cond1
and
not cond1
are equivalent
Bitwise and The usual & operator is used, e.g.
33 & 4
, 0010 0001 & 0000 0100 = 0.
Bitwise or The usual | operator is used, e.g.
33 | 4
, 0010 0001 | 0000 0100 = 0010 0101 = 37.
Bitwise xor The usual ^ operator is used, e.g.
33 ^ 4
, 0010 0001 ^ 0000 0100 = 0010 0100 = 37.
Bitwise complement The usual ~ operator is used, e.g.
~33
, ~0010 0001 = 1101 1110 = -34.
Ternary conditional ?: The usual ternary conditional operator condition ? if_true : if_false operator can be used as well as the abbreviation value ?: if_false which returns the value if its evaluation is defined, non-null and non-false, e.g.
val1 ? val1 : val2
and
val1 ?: val2 
are equivalent.

NOTE: The condition will evaluate to false when it refers to an undefined variable or null for all JexlEngine flag combinations. This allows explicit syntactic leniency and treats the condition 'if undefined or null or false' the same way in all cases.

Equality The usual == operator can be used as well as the abbreviation eq. For example
val1 == val2
and
val1 eq val2
are equivalent.
  1. null is only ever equal to null, that is if you compare null to any non-null value, the result is false.
  2. Equality uses the java equals method
Inequality The usual != operator can be used as well as the abbreviation ne. For example
val1 != val2
and
val1 ne val2
are equivalent.
Less Than The usual < operator can be used as well as the abbreviation lt. For example
val1 < val2
and
val1 lt val2
are equivalent.
Less Than Or Equal To The usual <= operator can be used as well as the abbreviation le. For example
val1 <= val2
and
val1 le val2
are equivalent.
Greater Than The usual > operator can be used as well as the abbreviation gt. For example
val1 > val2
and
val1 gt val2
are equivalent.
Greater Than Or Equal To The usual >= operator can be used as well as the abbreviation ge. For example
val1 >= val2
and
val1 ge val2
are equivalent.
Regex match =~ The Perl inspired =~ operator can be used to check that a string matches a regular expression (expressed either a Java String or a java.util.regex.Pattern). For example "abcdef" =~ "abc.* returns true.
Regex no-match !~ The Perl inspired !~ operator can be used to check that a string does not match a regular expression (expressed either a Java String or a java.util.regex.Pattern). For example "abcdef" !~ "abc.* returns false.
Addition The usual + operator is used. For example
val1 + val2
Subtraction The usual - operator is used. For example
val1 - val2
Multiplication The usual * operator is used. For example
val1 * val2
Division The usual / operator is used, or one can use the div operator. For example
val1 / val2
or
val1 div val2
Modulus (or remainder) The % operator is used. An alternative is the mod operator. For example
5 mod 2
gives 1 and is equivalent to
5 % 2
Negation The unary - operator is used. For example
-12
Array access Array elements may be accessed using either square brackets or a dotted numeral, e.g.
arr1[0]
and
arr1.0
are equivalent
HashMap access Map elements are accessed using square brackets, e.g.
map[0]; map['name']; map[var];
Note that
map['7']
and
map[7]
refer to different elements. Map elements with a numeric key may also be accessed using a dotted numeral, e.g.
map[0]
and
map.0
are equivalent.

Conditional

Operator Description
if Classic, if/else statement, e.g.
if ((x * 2) == 5) {
    y = 1;
} else {
    y = 2;
}
for Loop through items of an Array, Collection, Map, Iterator or Enumeration, e.g.
for(item : list) {
    x = x + item; 
}
Where item and list are variables. The JEXL 1.1 syntax using foreach(item in list) is now deprecated.
while Loop until a condition is satisfied, e.g.
while (x lt 10) {
    x = x + 2; 
}
分享到:
评论

相关推荐

    better-comments_visualstudio2010_better-comments_BetterComments_

    标题 "better-comments_visualstudio2010_better-comments_BetterComments_" 暗示我们讨论的是一个名为 "BetterComments" 的插件,该插件专为Visual Studio 2010设计,旨在改进代码注释的体验。"better-comments" 是...

    Laravel开发-comments

    在本文中,我们将深入探讨Laravel开发中的评论系统,基于提供的标题“Laravel开发-comments”和描述“一个简单的评论包”。Laravel是一个流行的开源PHP框架,以其优雅的语法和强大的功能而闻名,常用于构建复杂且...

    VS10x Comments Extender VS2010 絕妙註解套件

    VS10x Comments Extender VS2010 絕妙註解套件

    前端开源库-json-comments

    "json-comments"是一个专为前端开发者设计的开源库,其核心功能是允许在JSON配置文件中添加注释。这在实际开发中尤其有用,因为JSON(JavaScript Object Notation)本身并不支持注释,使得代码的可读性和维护性受到...

    hotel_comments.zip

    这次我们聚焦于一个名为“hotel_comments.zip”的压缩包文件,它是一个专门为训练情感分析模型而设计的语料库。这个语料库包含了4000条酒店评论,每条评论都被明确地标注为正向或负向,这样的二分类任务对于提升机器...

    Threaded Comments针对性的留言插件 for Wordpress.rar

    《WordPress中的线程评论:深度解析Brian's Threaded Comments插件》 在WordPress这个全球最受欢迎的博客和网站构建平台中,交互性是提升用户体验的重要因素之一。为了增强用户参与度和对话的连贯性,很多网站管理...

    Recent Comments插件

    Recent Comments插件的特点: •widget样式:可以定义每个边栏放置的CSS规则 •评论过滤:过滤你要输出的评论,可以更加分类、页面来显示访客的评论 •评论类型:可以选择评论显示的类型 •自定义标签:混合使用...

    comments-logging.jar

    java的comments-logging包

    comments.txt(合并后的评论)

    comments.txt(合并后的评论)

    Request For Comments (RFC)中文文档大全

    Request For Comments(RFC)是互联网工程任务组(IETF)发布的一种技术规范和标准文档,用于提出、讨论和记录互联网相关的技术和协议。这些文档详细定义了互联网的各种协议、方法、过程和概念,对于理解网络工作...

    Sexy Comments插件 for Wordpress.zip

    http://wordpress.org/extend/plugins/sexy-comments/installation/ 替换原来的评论模板,让评论区域看起来有点像论坛的风格,确实相当Sexy。

    前端项目-side-comments.zip

    前端项目-side-comments,一个接口组件,用于提供网站/app medium.com风格的评论。

    strip-json-comments, 在JSON文件中,从JSON中去除注释.zip

    strip-json-comments, 在JSON文件中,从JSON中去除注释 strip-json-comments 去除JSON注释。让你在JSON文件中使用注释 !现在是可能的:{ // rainbows "unicorn": /* ❤ */ "cake"}它将用空格替换单

    meteor-comments-ui, 在你的Meteor 应用程序中,用于注释功能的简单模板.zip

    meteor-comments-ui, 在你的Meteor 应用程序中,用于注释功能的简单模板 Meteor 注释用户界面 这里软件包允许你在几秒钟内添加注释框。 注释UI为 komentify插件提供基础,它允许你在不需要自定义后端的情况下向任何...

    Image Comments 图片注释

    vs插件 图片注释

    Laravel开发-ao-comments

    在本文中,我们将深入探讨基于Laravel框架的`ao-comments`项目,这是一个专为Laravel设计的评论系统组件。Laravel作为PHP领域的热门框架,以其优雅的语法和强大的功能受到开发者喜爱,而`ao-comments`则进一步扩展了...

    PyPI 官网下载 | django-comments-dab-1.0.1.tar.gz

    标题中的"PyPI 官网下载 | django-comments-dab-1.0.1.tar.gz"表明这是一个在Python的包索引服务(PyPI)上发布的软件包,名为`django-comments-dab`,版本号为1.0.1,且是以tar.gz格式提供的压缩文件。PyPI是Python...

    MyComment - 新增Comments而继续显示已经存在的Comments。 - MetaTrader 5程序库.zip

    《MetaTrader 5中的Comments管理:使用"MyComment"实现多层评论展示》 在金融交易领域,MetaTrader 5(MT5)是一个广泛使用的交易平台,它提供了丰富的编程接口(MQL5)供用户自定义交易策略和分析工具。在MT5中,...

    Laravel开发-laravel-comments

    在本文中,我们将深入探讨基于Laravel框架的“laravel-comments”扩展,它是一个由actuallymab创建的注释包,旨在增强网站或应用的评论功能。这个扩展允许用户以访客身份发表评论,并且支持添加更多的元信息,从而...

Global site tag (gtag.js) - Google Analytics