我还在和ANTLR一起学习.我已经构建了一个语法,并且在很大程度上它完成了我的期望,但是我需要它能够以静默方式运行(没有输出到stdout或stderr).
grammar MyPredicate;
options
{
output=AST;
}
parse : expression EOF
;
expression
: field WS? OPERATOR_BINARY WS? value
;
OPERATOR_BINARY
: '=' | '<' | '>' | '<=' | '>=' | '!=' | 'has'
;
value : VALUE_STRING
| VALUE_NUMERIC
| VALUE_BOOLEAN
;
VALUE_STRING
: '""'
| '"' (ESC_SEQ | ~('\\'|'"'))+ '"'
;
VALUE_NUMERIC
: ('0'..'9')+ ('.' ('0'..'9')+)?
;
VALUE_BOOLEAN
: 'true'
| 'false'
;
field : FIELD_NAME
;
FIELD_NAME
: ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
ESC_SEQ
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') …Run Code Online (Sandbox Code Playgroud) 我有一个List<T1>项目和第二个List<T2>项目.两个列表都按属性A按字母顺序排序.我知道项目列表List<T2>是其中的一个子集,List<T1>并且没有List<T2>存在的项目List<T1>.
我需要迭代List<T1>并在每次匹配变量时更改变量List<T2>.什么是最快和最好的方法?我假设我需要迭代两个列表,但我知道做一个嵌套的foreach没有意义.
我的示例字典是这样的
data_dictionary = {1:'blue',2:'green',3:'red',4:'orange',5:'purple',6:'mauve'}
Run Code Online (Sandbox Code Playgroud)
data_dictionary可以有更多元素,具体取决于传入的数据.第一个值是我们称之为payload_index的值.我总是得到payload_index 1到4.
我需要从中汇编一个列表.满容易:
for payload_index in data_dictionary :
assembled_packet.append(data_dictionary[payload_index])
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要总是跳过第3个元素.我想我可以做一个if但这样效率很低:
for payload_index in data_dictionary :
if payload_index <> 3:
assembled_packet.append(data_dictionary[payload_index])
Run Code Online (Sandbox Code Playgroud)
我可以分两步完成前三个元素,但问题是我无法弄清楚如何获得其余的因为第三个元素之后的元素数量变化.我尝试使用一个不可能的高指数(下图)但显然失败了:
#get element 1 and two
for index in range(0,3):
assembled_packet.append(data_dictionary[index])
#get element 1 and two
for index in range(4,999):
assembled_packet.append(data_dictionary[index])
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢!
我尝试定义这样一个简单的特征:
scala> trait T { def p[A,B]: Map[A,B] }
defined trait T
scala> new T { def p = Map(0 -> 1) }
<console>:7: error: object creation impossible, since method p in trait T of type [A,B]Map[A,B] is not defined
new T { def p = Map(0 -> 1) }
^
Run Code Online (Sandbox Code Playgroud)
怎么会?
谢谢
我有一堆存储过程名称.我想导出每个存储过程的创建脚本.最好的方法是什么?
现在我在SSMS中手动选择存储过程并选择"Script stored procedure as -> Drop and Create to".这似乎很乏味.我希望有更好的方法来解决这个问题.谢谢.
我在unix上运行Java进程.
我需要运行一个外部进程,该进程由主进程使用ProcessBuilder生成.主进程等待外部进程完成,然后生成下一个外部进程.我一直在这里工作.
public static void main(String[] args) {
for(...) {
int exitVal = runExternalProcess(args);
if(exitVal !=0) {
failedProcess.add(args);
}
}
}
private int runExternalProcess(String[] args) {
ProcessBuilder pb = new ProcessBuilder(args[0], args[1], args[2]);
pb.redirectErrorStream(true);
Process proc = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
String line = null;
while ( (line = br.readLine()) != null)
LOG.log(Level.SEVERE, line);
//Main thread waits for external process to complete.
//What I need to do is.
// If proc.executionTime() > TIMEOUT
// kill proc; …
Run Code Online (Sandbox Code Playgroud)Run Code Online (Sandbox Code Playgroud) 我必须读取两个csv文件,合并行并将结果写入第三个csv文件.第一个csv文件在第一个colunm中有五行带有用户名.(总共25个colunm)第二个csv文件在第一个colunm中有五行用户名,在第二个colunm中有用户id.(只有2个colunm)
第三个csv文件将包含用户名+ userid和第一个文件的所有剩余24列.
data = open(os.path.join("c:\\transales","AccountID+ContactID-source1.csv"),"rb").read().replace(";",",").replace("\0","")
data2 = open(os.path.join("c:\\transales","AccountID+ContactID-source2.csv"),"rb").read().replace(";",",").replace("\0","")
i = 0
j = 0
Info_Client_source1=StringIO.StringIO(data)
Info_Client_source2=StringIO.StringIO(data2)
for line in csv.reader(Info_Client_source1):
name= line[1]
i=i+1
print "i= ",i
for line2 in csv.reader(Info_Client_source2):
print "j = :",j
j=j+1
if line[1] == line2[2]:
continue
Run Code Online (Sandbox Code Playgroud)
结果:
i= 1
j = : 0
j = : 1
j = : 2
j = : 3
j = : 4
j = : 5
j = : 6
i= 2
i= 3
i= 4
i= 5 …Run Code Online (Sandbox Code Playgroud) 我们遇到了一个奇怪的问题ConcurrentHashMap,其中两个线程似乎在调用put(),然后在方法内永远等待Unsafe.park().从外面看,它看起来像是一个僵局ConcurrentHashMap.
到目前为止,我们只看到过这种情况.
谁能想到任何可能导致这些症状的事情?
编辑:相关线程的线程转储在这里:
"[redacted] Thread 2" prio=10 tid=0x000000005bbbc800 nid=0x921 waiting on condition [0x0000000040e93000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00002aaaf1207b40> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:747)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:778)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1114)
at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186)
at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262)
at java.util.concurrent.ConcurrentHashMap$Segment.put(ConcurrentHashMap.java:417)
at java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:883)
at [redacted]
"[redacted] Thread 0" prio=10 tid=0x000000005bf38000 nid=0x91f waiting on condition [0x000000004151d000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00002aaaf1207b40> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
at … 我从用户那里得到一个url字符串,并希望将其转换为合法的http url:
" http://one.two/three?四五 "应该变成" http://one.two/three?four%20five "
但是,URLEncoder没有帮助,因为它编码整个字符串(包括合法的"://").
救命?
我使用vim以我喜欢的方式进行了一些代码对齐 - 然后尝试将其粘贴到VS2008中.Voila,2008决定重新格式化它,删除我添加的所有空格,使一些声明精美对齐.
有没有办法让VS2008(A)粘贴而不改变空格或(B)对齐代码,如下所示?
public int SomePropertyName { get; set; }
public Nullable<string> SomeOtherProperty { get; set; }
public Nullable<int> YetAnotherProperty { get; set; }
Run Code Online (Sandbox Code Playgroud)
当我将其粘贴到VS2008中时,它会像这样结束:
public int SomePropertyName { get; set; }
public Nullable<string> SomeOtherProperty { get; set; }
public Nullable<int> YetAnotherProperty { get; set; }
Run Code Online (Sandbox Code Playgroud) java ×3
python ×2
.net ×1
.net-3.5 ×1
antlr ×1
c# ×1
c#-3.0 ×1
concurrency ×1
copy-paste ×1
eof ×1
scala ×1
sql-server ×1
t-sql ×1
urlencode ×1