简体   繁体   English

Tsung.xml中的嵌入式Erlang动态变量无法解析If表达式

[英]Embedded Erlang in Tsung.xml Dynamic Variable fails to parse for If expressions

I've been trying to remove some complications in a build process by bringing some external Erlang code into my Tsung config file (tsung.xml) and setting some dynamic variables with it, but have found that a few expressions just don't seem to work properly. 我一直试图通过将一些外部Erlang代码放入我的Tsung配置文件(tsung.xml)并使用它设置一些动态变量来消除构建过程中的一些复杂问题,但是发现一些表达式似乎没有好好工作。

When trying to use If statements, cases or even function definitions (funs or normal), either Tsung complains with an "unexpected_char" message (but no mention of what possible char), or for the latter, Erlang returns a "syntax error before '[]'" parse error. 当尝试使用If语句,案例甚至函数定义(操作或正常)时,Tsung都会抱怨“unexpected_char”消息(但没有提到可能的char),或者对于后者,Erlang会在“之前”返回“语法错误” []'“ 解析错误。

<setdynvars sourcetype="eval"
               code="fun({Pid,DynVars}) ->
                        {Var_Scale, ScaleUp} = {3, 100},
                        Random=random:uniform() * 100 * ScaleUp,
                        Compare=round(Var_Scale * ScaleUp),
                        if
                                 Random =< Compare ->
                                     Return = 1;
                                 true ->
                                     Return = 0
                        end,
                        Return.
                        ">
            <var name="someVariable" />

The same result occurs if the whole of the function expression is just the if expression: 如果整个函数表达式只是if表达式,则会出现相同的结果:

<setdynvars sourcetype="eval"
               code="fun({Pid,DynVars}) ->
                        if
                            1 < 2 -> Return = 2;
                            true -> Return = 3
                        end.
                        ">
            <var name="anotherVariable" />
        </setdynvars>

And for an inlined or anonymous function 对于内联或匿名函数

<setdynvars ...
  Compare=round(Var_Scale * ScaleUp),
  Fn = fun() -> a
  end.
">

which results in the aforementioned parse error. 这导致上述解析错误。

I'm kind of new to Erlang and Tsung, so perhaps I've misinterpreted how these commands need to be structured, or what Tsung's eval in ts_utils needs to be fed. 我对Erlang和Tsung有点新意,所以也许我误解了这些命令是如何构建的,或者是tsung在ts_utils中的评估需要得到什么。 It seems to use the standard Erlang scan, parse and eval methods, so I'd imagine that it most certainly supports branching operations and functions. 它似乎使用标准的Erlang扫描,解析和eval方法,所以我认为它肯定支持分支操作和函数。

So my question itself boils down to: Is this code (syntactically) correct and does Tsung simply not support this, and secondly, is there a better or more idiomatically correct way of doing this? 所以我的问题本身归结为:这个代码(语法上)是否正确并且Tsung根本不支持这个,其次,是否有更好或更正确的方法来做到这一点?

I'd guess it's unhappy about < and > characters being embedded in XML attributes. 我猜它对于嵌入在XML属性中的<>字符感到不满意。 Try entering them as &lt; 尝试输入它们&lt; and &gt; &gt; . Also, unlike named functions a fun needs a matching end token: 此外,与命名函数不同, fun需要匹配的end标记:

<setdynvars sourcetype="eval"
               code="fun({Pid,DynVars}) -&gt;
                        if
                            1 &lt; 2 -&gt; Return = 2;
                            true -&gt; Return = 3
                        end
                     end.
                        ">
            <var name="anotherVariable" />
        </setdynvars>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM