我是Antlr的新手,我希望使用Antlr4完成以下实现。我具有以下编写的功能。
1. FUNCTION.add(Integer a,Integer b)
2. FUNCTION.concat(String a,String b)
3. FUNCTION.mul(Integer a,Integer b)
Run Code Online (Sandbox Code Playgroud)
我正在存储这样的函数元数据。
Map<String,String> map=new HashMap<>();
map.put("FUNCTION.add","Integer:Integer,Integer");
map.put("FUNCTION.concat","String:String,String");
map.put("FUNCTION.mul","Integer:Integer,Integer");
Run Code Online (Sandbox Code Playgroud)
其中,Integer:Integer,Integerrepresent Integer是函数将返回的返回类型和输入参数Integer,Integer。
如果输入是这样的
FUNCTION.concat(Function.substring(String,Integer,Integer),String)
or
FUNCTION.concat(Function.substring("test",1,1),String)
Run Code Online (Sandbox Code Playgroud)
通过使用visitor实现,我想针对存储在地图中的功能元数据检查输入是否有效。
以下是我正在使用的词法分析器和解析器:
Lexer MyFunctionsLexer.g4:
lexer grammar MyFunctionsLexer;
FUNCTION: 'FUNCTION';
NAME: [A-Za-z0-9]+;
DOT: '.';
COMMA: ',';
L_BRACKET: '(';
R_BRACKET: ')';
Run Code Online (Sandbox Code Playgroud)
解析器MyFunctionsParser.g4:
parser grammar MyFunctionsParser;
options {
tokenVocab=MyFunctionsLexer;
}
function : FUNCTION '.' NAME '('(function | argument (',' argument)*)')';
argument: (NAME | function);
WS : [ \t\r\n]+ -> skip;
Run Code Online (Sandbox Code Playgroud)
我正在使用Antlr4。
以下是根据建议答案使用的实现。 …
使用 logback,我正在尝试记录 IP 地址。我了解了日志记录,hostname但我无法记录服务器的本地 IP。有什么办法可以使用 logback 打印服务器的本地 IP 地址。
下面是我用于主机名打印的模式。
<appender name="APP_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${org.apache.nifi.bootstrap.config.log.dir}/nifi-app.log</file>
<define name="hostname" class="ch.qos.logback.core.property.CanonicalHostNamePropertyDefiner"/>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--
For daily rollover, use 'app_%d.log'.
For hourly rollover, use 'app_%d{yyyy-MM-dd_HH}.log'.
To GZIP rolled files, replace '.log' with '.log.gz'.
To ZIP rolled files, replace '.log' with '.log.zip'.
-->
<fileNamePattern>${org.apache.nifi.bootstrap.config.log.dir}/nifi-app_%d{yyyy-MM-dd_HH}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<!-- keep 30 log files worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<immediateFlush>true</immediateFlush>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${hostname}%date %level [%thread] %logger{40} %msg%n</pattern>
</encoder>
</appender>
Run Code Online (Sandbox Code Playgroud) 在 Azure 函数中如何使用javascript调用 API 。请求是带有标头的 POST。我尝试使用XMLHttpRequest,但我遇到了异常,例如未定义 XMLHttpRequest 。
var client = new XMLHttpRequest();
var authentication = 'Bearer ...'
var url = "http://example.com";
var data = '{.........}';
client.open("POST", url, true);
client.setRequestHeader('Authorization',authentication);
client.setRequestHeader('Content-Type', 'application/json');
client.send(data);
Run Code Online (Sandbox Code Playgroud)
任何其他方法都可以实现这一点,
在 Azure 逻辑应用程序中,如何'使用替换函数转义单引号 ( )?
我有一个 JSON 有效负载,必须将单引号 ( ') 替换为双引号 ( ")。我想出的表达式如下所示:
replace(string(@triggerBody()),'/' ','/" ')
Run Code Online (Sandbox Code Playgroud)
但我的第二个转义单引号 ( ') 的表达式不起作用。
我按以下顺序调用rest API。
生成FLowfile处理器-> jsonpath处理器->文本替换处理器(用于后期数据创建)---> InvokeHTTP --->属性的XPATH处理器--->由生成流文件生成的原始流文件。
因此,在文本替换处理器之后,原始数据将被新数据替换。因此,如何获取原始数据并使用调用API后产生的属性。
我有一个 .crt 文件,我想使用 java 导入到密钥库和信任库(首先创建密钥库和信任库,然后导入)。
下面是我正在使用的代码:
import org.glassfish.tyrus.client.ClientManager;
import org.glassfish.tyrus.client.ClientProperties;
import org.glassfish.tyrus.client.SslContextConfigurator;
import org.glassfish.tyrus.client.SslEngineConfigurator;
@ClientEndpoint
public class test {
private static CountDownLatch latch;
private Logger logger = Logger.getLogger(this.getClass().getName());
@OnOpen
public void onOpen(Session session) {
logger.info("Connected ... " + session.getId());
try {
session.getBasicRemote().sendText("start");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@OnMessage
public String onMessage(String message, Session session) {
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
try {
logger.info("Received ...." + message);
String userInput = bufferRead.readLine();
return userInput;
} catch …Run Code Online (Sandbox Code Playgroud) 在Javascript中,以下代码如何工作.
var a = {
prop1: "a",
prop2: "b",
fun: function() {
return this.prop1 + " " + this.prop2;
}
}
var a2 = a;
a.fn = "v";
a = {};
if (a === a2) {
console.log(true);
} else {
console.log(false);
}Run Code Online (Sandbox Code Playgroud)
上面的代码打印错误.
但是,如果我注释掉a = {}行,则在控制台上打印的值为true.
var a = {
prop1: "a",
prop2: "b",
fun: function() {
return this.prop1 + " " + this.prop2;
}
}
var a2 = a;
a.fn = "v";
//a={};
if (a === a2) {
console.log(true); …Run Code Online (Sandbox Code Playgroud)在使用JAVA的azure函数中如何获取以json形式发送的请求负载
我的代码是这样的:
@FunctionName("hello")
public HttpResponseMessage<String> hello(
@HttpTrigger(name = "req", methods = {"post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,final ExecutionContext context) throws Exception {
context.getLogger().info("Java HTTP trigger processed a request.");
System.out.println("**********REQUEST BODY*************"+request.getBody());
String cookie = new Authenticate().authenticateAndGetCookie();
ExecuteCommands commandsExecutor = new ExecuteCommands(cookie);
String s=commandsExecutor.control(request.toString());
System.out.println(s);
JSONObject jobj=new JSONObject(s);
if (s == null) {
return request.createResponse(400, "Please pass a name on the query string or in the request body");
} else {
return request.createResponse(200,jobj.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
由于使用了 HttpRequestMessage>,当我在控制台上打印正文(如我上面粘贴的代码中所示)时,我会在控制台中获取此内容。
**********REQUEST BODY*************Optional[{
[13-06-2018 11:40:18] Java …Run Code Online (Sandbox Code Playgroud) I have JSON in which all the values have to be changed to string. The values may be a number, boolean, undefined or null.
{
"obj1": [{
"n1": "n",
"n2": 1,
"n3": true
},
{
"n1": "n",
"n2": 1,
"n3": null
}]
}
Run Code Online (Sandbox Code Playgroud)
The expected result is all the values should be formatted as a string.
Example:
{
"obj1": [{
"n1": "n",
"n2": "1",
"n3": "true"
},
{
"n1": "n",
"n2": "1",
"n3": "null"
}]
}
Run Code Online (Sandbox Code Playgroud)
By iterating through …
我想检查模式匹配,如果模式匹配,那么我想将这些文本匹配替换为测试数组中给定索引处的元素。
public class test {
public static void main(String[] args) {
String[] test={"one","two","three","four"}
Pattern pattern = Pattern.compile("\\$(\\d)+");
String text="{\"test1\":\"$1\",\"test2\":\"$5\",\"test3\":\"$3\",\"test4\":\"$4\"}";
Matcher matcher = pattern.matcher(text);
while(matcher.find()) {
System.out.println(matcher.groupCount());
System.out.println(matcher.replaceAll("test"));
}
System.out.println(text);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望最终结果文本字符串采用以下格式:
{\"test1\":\"one\",\"test2\":\"$two\",\"test3\":\"three\",\"test4\":\"four\"}
Run Code Online (Sandbox Code Playgroud)
但 while 循环在一场比赛后退出,并"test"在各处被替换,如下所示:
{"test1":"test","test2":"test","test3":"test","test4":"test"}
Run Code Online (Sandbox Code Playgroud)
使用下面的代码我得到了结果:
public class test {
public static void main(String[] args) {
String[] test={"one","two","three","four"};
Pattern pattern = Pattern.compile("\\$(\\d)+");
String text="{\"test1\":\"$1\",\"test2\":\"$2\",\"test3\":\"$3\",\"test4\":\"$4\"}";
Matcher m = pattern.matcher(text);
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, test[Integer.parseInt(m.group(1)) - 1]);
}
m.appendTail(sb);
System.out.println(sb.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我有一个像这样的替换文本数组, …