import re#Python #code 停,不用 regex 了,我们用 pyparsing!
pat_cdecl = re.compile(r"(\w+)\s+(\w+)\((((\w+)\s+(\w+))(,\s*(\w+)\s+(\w+))*)?\);")
ctype = {
"void*": c_void, "char*": c_char_p,
"int": c_int, "double": c_double
}.__getitem__
def foreign(cdecl):
"""t_result name(type name, ...args);"""
m = pat_cdecl.match(cdecl).groups()
t_result, name = m[0:2]
if m[3] == None: return cfunc(name, ctype(t_result))
args = [(m[i+2], ctype(m[i+1])) for i in range(3, len(m), 3)]
return cfunc(name, ctype(t_result), *args)
注: pyparsing 是老项目了,设计表现力和 ParserKt 有点像 https://github.com/pyparsing/pyparsing/blob/master/examples/jsonParser.py
GitHub
pyparsing/examples/jsonParser.py at master · pyparsing/pyparsing
Python library for creating PEG parsers. Contribute to pyparsing/pyparsing development by creating an account on GitHub.
Forwarded from Margatroid
以下哪些行为是违法犯罪行为?
Anonymous Quiz
15%
污染整个地区的 DNS 请求,返回无效 IP
5%
在主干网上进行劫持,对特定网站发起 HTTPS MitM 攻击
9%
篡改 HTTP 响应并插入攻击脚本,对特定网站发起 DDoS 攻击
71%
使用多线程下载百度云
t0 = time()基本上主要逻辑就这些
t1 = None
def giveSegment():
nonlocal t1
t2 = time()
reducer.accept( (t1-t0, t2-t0, synth.last_pitch) )
t1 = t2 #< new start
synth.last_pitch = next(pitchz, 50)
def nextPitch():
try: return next(pitchz)
except StopIteration: raise NonlocalReturn("done")
def doSplit(): synth.noteSwitch(nextPitch())
def onEvent(event):
nonlocal t1
if event.type == pygame.KEYDOWN:
key = chr(event.key)
if key == 'a':
t1 = time()
synth.noteon(synth.last_pitch)
elif event.type == pygame.KEYUP:
key = chr(event.key)
if key == 'a':
synth.noteoff()
synth.last_pitch = nextPitch()
giveSegment()
elif key == 's' and not is_hot: doSplit(); giveSegment()
elif key == ' ': onPausePlay()
……出 bug, 修复了 ,果然简单才是真理啊! 根本不该有什么 init update 顺序的问题,emmm
Telegram
duangsues.is_a? SaltedFish
t0 = time()
t1 = None
def nextPitch():
try: return next(pitchz)
except StopIteration: raise NonlocalReturn("done")
def doSplit():
synth.noteSwitch(nextPitch())
def giveSegment():
nonlocal t1
t2 = time()
reducer.accept( (t1-t0, t2-t0, synth.last_pitch)…
t1 = None
def nextPitch():
try: return next(pitchz)
except StopIteration: raise NonlocalReturn("done")
def doSplit():
synth.noteSwitch(nextPitch())
def giveSegment():
nonlocal t1
t2 = time()
reducer.accept( (t1-t0, t2-t0, synth.last_pitch)…
[45, 45, 52, 52, 54, 54, 52, 50, 50, 49, 49, 47, 47, 45, 52, 52, 50, 50, 49, 49, 47, 52, 52, 50, 50, 49, 49, 47, 45, 45, 52, 52, 54, 54, 52, 50, 50, 49, 49, 47, 47, 45] 这是一首《小星星》的谱子音高表 🤔