def store_goals(goals_sexp): goals = [] for g in goals_sexp: hypotheses = [] for h in g[2][1]: h_sexp = sexpdata.dumps(h[2]) hypotheses.append({ "idents": [symbol2str(ident[1]) for ident in h[0][::-1]], "term": [ None if t == [] else self.print_constr( sexpdata.dumps(t)) for t in h[1] ], "type": self.print_constr(h_sexp), "sexp": h_sexp, }) type_sexp = sexpdata.dumps(g[1][1]) goals.append({ "id": int(g[0][1]), "type": self.print_constr(type_sexp), "sexp": type_sexp, "hypotheses": hypotheses[::-1], }) return goals
def store_goals(goals_sexp): goals = [] for g in goals_sexp: hypotheses = [] for h in g[2][1]: h_sexp = sexpdata.dumps(h[2]) hypotheses.append({ 'idents': [symbol2str(ident[1]) for ident in h[0][::-1]], 'term': [ None if t == [] else self.print_constr( sexpdata.dumps(t)) for t in h[1] ], 'type': self.print_constr(h_sexp), 'sexp': h_sexp }) type_sexp = sexpdata.dumps(g[1][1]) goals.append({ 'id': int(g[0][1]), 'type': self.print_constr(type_sexp), 'sexp': type_sexp, 'hypotheses': hypotheses[::-1] }) return goals
def _parse_preceptors(self, raw_preceptors): """Takes raw preceptor data and gives usable data""" data = sexpdata.loads("(" + raw_preceptors + ")") self.time = data[0][-1][-1] self.gyr = data[2][-1][-3:] self.filter_acc(data[3][-1][-3:]) self.state = {} for arg in data[4:]: if sexpdata.dumps(arg[0]) == 'HJ': self.state[sexpdata.dumps(arg[-2][-1]).replace( 'j', 'e')] = float(arg[-1][-1]) for arg in data[4:]: if sexpdata.dumps(arg[0]) == 'See': for a in arg[1:]: if sexpdata.dumps(a[0]) == 'mypos': self.pos = a[1:] if sexpdata.dumps(a[0]) == 'myorien': self.orr = a[-1] break break # Debug # print('(_parse_preceptors) message -> ', raw_preceptors) # for s in self.state: # print("(_parse_preceptors)", s, self.state[s]) # if self.is_fallen(): # print(self.time, self.gyr, self.acc, self.pos, self.orr, self.is_fallen()) return self.state, self.acc, self.gyr, self.pos, self.orr, float( self.time), self.is_fallen(),
def node_and_port(self, e): if dumps(e) == "__": return ["__", ""] else: node = dumps(car(e)) port = dumps(car(cdr(e))) return [node, port]
def get_attributes(e): result = {} i = e while (i): key = dumps(car(i)) assert (key.startswith(":")) value = dumps(car(cdr(i))) result[key] = value i = cdr(cdr(i)) return result
def send(self, cmd): 'Send a command to SerAPI and retrieve the responses' #print(cmd) assert '\n' not in cmd self.proc.sendline(cmd) try: self.proc.expect([ '\(Answer \d+ Ack\)\x00.*\(Answer \d+ Completed\)\x00', '\(Answer \d+ Ack\)\x00.*\(Answer \d+\(CoqExn.*\)\x00' ]) except pexpect.TIMEOUT as ex: print(self.proc.before) raise CoqTimeout raw_responses = self.proc.after #print(raw_responses) ack_num = int( re.search(r'^\(Answer (?P<num>\d+)', raw_responses)['num']) for num in re.findall(r'(?<=\(Answer) \d+', raw_responses): assert int(num) == ack_num responses = [] msg_str = [] for item in raw_responses.split('\x00'): item = item.strip() if item == '': continue if not item.startswith('(Feedback') and not item.startswith( '(Answer'): m = re.search(r'\(Feedback|\(Answer', item) if m is None: continue item = item[m.span()[0]:] assert item.endswith(')') parsed_item = sexpdata.loads(item, nil=None, true=None) if 'CoqExn' in item: # an error occured in Coq assert parsed_item[2][0] == Symbol('CoqExn') raise CoqExn(sexpdata.dumps(parsed_item[2][4]), sexpdata.dumps(parsed_item[2])) if item.startswith('(Feedback'): # ignore Feedback for now try: msg = parsed_item[1][3][1] if isinstance(msg, list) and msg != [] and msg[0] == Symbol( 'Message'): msg_sexp, _ = self.send( '(Print ((pp_format PpStr)) (CoqPp %s))' % sexpdata.dumps(msg[3])) msg_str.extend( [symbol2str(x[1]) for x in msg_sexp[1][2][1]]) except IndexError: pass continue responses.append(parsed_item) msg_str = '\n'.join(msg_str) return responses, raw_responses
def arglist(self, func, cursor=None, form=None): if not isinstance(func, unicode) and not isinstance(func, str): log.debug("Expected string at: %s" % func) return None cmd = """(slime::autodoc "{0}" {1} '{2})""".format( qstr(func), dumps(cursor), dumps(form)) result = self.euslisp.exec_internal(cmd) if isinstance(result, str): return [result, False] elif result: return [dumps(result), True] return None
def send(self, cmd): "Send a command to SerAPI and retrieve the responses" # print(cmd) assert "\n" not in cmd self.proc.sendline(cmd) try: self.proc.expect([ "\(Answer \d+ Ack\)\x00.*\(Answer \d+ Completed\)\x00", "\(Answer \d+ Ack\)\x00.*\(Answer \d+\(CoqExn.*\)\x00", ]) except pexpect.TIMEOUT as ex: print(self.proc.before) raise CoqTimeout raw_responses = self.proc.after # print(raw_responses) ack_num = int( re.search(r"^\(Answer (?P<num>\d+)", raw_responses)["num"]) for num in re.findall(r"(?<=\(Answer) \d+", raw_responses): assert int(num) == ack_num responses = [] msg_str = [] for item in raw_responses.split("\x00"): item = item.strip() if item == "": continue if not item.startswith("(Feedback") and not item.startswith( "(Answer"): m = re.search(r"\(Feedback|\(Answer", item) if m is None: continue item = item[m.span()[0]:] assert item.endswith(")") parsed_item = sexpdata.loads(item, nil=None, true=None) if "CoqExn" in item: # an error occured in Coq assert parsed_item[2][0] == Symbol("CoqExn") raise CoqExn(sexpdata.dumps(parsed_item[2][4]), sexpdata.dumps(parsed_item[2])) if item.startswith("(Feedback"): # ignore Feedback for now try: msg = parsed_item[1][3][1] if (isinstance(msg, list) and msg != [] and msg[0] == Symbol("Message")): msg_sexp, _ = self.send( "(Print ((pp_format PpStr)) (CoqPp %s))" % sexpdata.dumps(msg[3])) msg_str.extend( [symbol2str(x[1]) for x in msg_sexp[1][2][1]]) except IndexError: pass continue responses.append(parsed_item) msg_str = "\n".join(msg_str) return responses, raw_responses
def crossover(offspring, p1_index, p2_index): p_1 = loads(offspring[p1_index][0]) p_2 = loads(offspring[p2_index][0]) position_1 = random.randint(0, node_number(p_1)) position_2 = random.randint(0, node_number(p_2)) p1_subtree = find_subtree(p_1, position_1, 0, p_1)[1] p2_subtree = find_subtree(p_2, position_2, 0, p_2)[1] p_1 = replace(p_1, position_1, p2_subtree, 0)[0] p_2 = replace(p_2, position_2, p1_subtree, 0)[0] return [[dumps(p_1), 0], [dumps(p_2), 0]]
def _printtree(indent, idx, m, buf): prefix = indent * ' ' e = m[idx].mexprs[0] rest = io.StringIO() print('%s(%2d) %s' % (prefix, idx, e.op), file=buf) print('%s props:' % prefix, file=buf) for k, v in m[idx].props.items(): print('%s :%s %s' % (prefix, k, sexpdata.dumps(v)), file=buf) if e.op == 'project': print('%s exprs' % prefix, ', '.join((_printscalar(indent, i, m, rest) for i in m[idx].props.cols)), file=buf) elif e.op == 'filter': print('%s filter' % prefix, _printscalar(indent, e.args[1], m, rest), file=buf) elif e.op == 'scan': print("%s table" % prefix, e.args[0]) print(file=buf) if e.op in ['project', 'filter']: _printtree(indent + 4, e.args[0], m, buf) elif e.op in ['cross']: for e in e.args: _printtree(indent + 4, e, m, buf) rest = rest.getvalue() if len(rest) > 0: print('%s----' % prefix, file=buf) print(rest, file=buf)
def missing_backend_error(dune, ppx): print( "In dune file " + dune + ", the instrumentation clause is missing; there should be one containing a backend for " + (sexpdata.dumps(ppx))) global exit_code exit_code = 1
def initialization(parents_number): max_depth = 2 pop = [] for i in range(0, parents_number): new_individual = dumps(spanning_tree(0, max_depth)) pop.append([new_individual, 0]) return pop
def main(argv): model = _model() fake_utts = [] real_utts = [] lfs = [] train_file = os.path.join( FLAGS.data_dir, "data", "{}.paraphrases.train.examples".format(FLAGS.dataset)) with open(train_file) as f: train_str = f.read() train_data = sexpdata.loads("({})".format(train_str)) num_train = len(train_data) if FLAGS.max_examples is not None: num_train = min(num_train, FLAGS.max_examples) num_train = int(num_train * FLAGS.train_frac) train_data = train_data[:num_train] for datum in train_data: real = datum[1][1] fake = datum[2][1] lf = sexpdata.dumps(datum[3][1]).replace("\\.", ".") fake_utts.append(fake) real_utts.append(real) lfs.append(lf) model.train(real_utts, fake_utts, lfs) model.save(FLAGS.write_model)
def __init__(self, text: str): self.text = text _s = sexpdata.loads(clean_sexp(text)) assert len(_s) >= 4 self._center_len = 1 self.prev_constraints: Optional[Any] = None if not self.RuleClass.is_any(_s[0]): self.prev_constraints = self.SeqRuleClass(_s[0], False) self.next_constraints: Optional[Any] = None if not self.RuleClass.is_any(_s[2]): self.next_constraints = self.SeqRuleClass(_s[2], True) self.constraints: Optional[Any] = None if not self.RuleClass.is_any(_s[1]): self.constraints = self.SeqRuleClass(_s[1], True) self._center_len = len(self.constraints) self.operations: List[Tuple[bool, str]] = [] for v in _s[3:]: feature = sexpdata.dumps(v) remove = False if feature.startswith("^"): remove = True feature = feature[1:] self.operations.append((remove, feature))
def __init__(self, constraints: List[List[Union[Symbol, List[Symbol]]]], forward: bool): self.forward = forward self.denies: Set[int] = set() self.minimum: List[Optional[int]] = [] for constraint in constraints: if isinstance(constraint, sexpdata.Symbol): _d = sexpdata.dumps(constraint) if _d == r"\?*": self.append(None) self.minimum.append(0) continue elif _d == r"*": self.minimum[-1] = 0 continue elif _d == r"\?": if len(self.minimum) == 0: # such as ( ?* ? [* * * * * ((住所末尾))] ?* ) self.append(None) self.minimum.append(1) else: self.minimum[-1] = 1 continue elif _d == r"^": self.denies.add(len(self)) continue else: raise NotImplementedError self.append(self.RuleClass(constraint)) self.minimum.append(None)
def response(self, flow: http.HTTPFlow) -> None: if self.should_persist(flow): sexp_file = Path.home() / ".cache/mitmproxy-flows.lisp" sexp = [] if os.path.isfile(sexp_file): text = Path(sexp_file).read_text() if text: # strip leading quote for sexpdata text = text[1:] sexp = sexpdata.loads(text) else: # create empty file open(sexp_file, 'a').close() obj = {} obj['url'] = flow.request.pretty_url obj['status-code'] = flow.response.status_code obj['request-content'] = \ self.get_pretty_json(flow.request.content.decode()) obj['response-content'] = \ self.get_pretty_json(flow.response.content.decode()) sexp.append(obj) # prepend a quote for valid Lisp code Path(sexp_file).write_text("'" + sexpdata.dumps(sexp))
def _get_type_name_src_dest_label_encoding_of_edge_from_sexp(self, e): first = car(e) second = car(cdr(e)) third = car(cdr(cdr(e))) rest = cdr(cdr(cdr(e))) edge_name = dumps(first) src_node_name, src_port_name = self.node_and_port(second) dest_node_name, dest_port_name = self.node_and_port(third) attributes = get_attributes(rest) edge_type = EdgeType.from_string( attributes[STRING_CONSTANTS.ATTRIBUTE_TYPE]) label = attributes[STRING_CONSTANTS.ATTRIBUTE_CONTENT] encoding = attributes[STRING_CONSTANTS.ATTRIBUTE_ENCODING] if src_node_name == "__": start_node_name = "start" + str(len(self._start_nodes)) src = StartNode(start_node_name, self) self._nodes_dict_by_name[start_node_name] = src dest = self._nodes_dict_by_name[dest_node_name] self._start_nodes.add(src) elif dest_node_name == "__": done_node_name = "done" + str(len(self._done_nodes)) src = self._nodes_dict_by_name[src_node_name] dest = DoneNode(done_node_name, self) self._nodes_dict_by_name[done_node_name] = dest self._done_nodes.add(dest) else: src = self._nodes_dict_by_name[src_node_name] dest = self._nodes_dict_by_name[dest_node_name] return edge_type, edge_name, src, src_port_name, dest, dest_port_name, label, encoding
def fields_add_entry(values_modify, re_flags=re.IGNORECASE): '''Add a list of fields to the Eeschema template.''' if type(values_modify) is not list: values_modify = [values_modify] config = read_config_file(PATH_EESCHEMA_CONFIG) values = [p for p in config if p.startswith("FieldNames")] changes = False if len(values) == 1: values = after(values[0], "FieldNames=") values = de_escape(values) values = sexpdata.loads(values) # TODO validate it, was using an undefined variable `name` if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH): values = values.replace("\\", '/') for idx, value_modify in enumerate(values_modify): value_found = False for idx, value in enumerate(values[1:]): search = value[1] if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH): search = value[1].replace("\\", '/') if re.findall(value_modify, search[1], re_flags): value_found = True if not value_found: values.append([sexpdata.Symbol('field'), [sexpdata.Symbol('name'), value_modify]]) changes = True if changes: s = sexpdata.dumps(values) config = update_config_file(config, "FieldNames", escape(s)) write_config_file(PATH_EESCHEMA_CONFIG, config)
def sp_encode(msg: dict) -> str: """ Encode the given message to S-Expression format :param msg: message to convert :return: S-Expression formatted message """ return sexpdata.dumps(msg)
def no_ppx_error(dune, ppx): print( "In dune file " + dune + ", the preprocessing clause indicates no preprocessing, but it should include " + (sexpdata.dumps(ppx))) global exit_code exit_code = 1
def bom_plugin_remove_entry(name, re_flags=re.IGNORECASE): '''Remove a BOM plugin entry to the Eeschema configuration file.''' config = read_config_file(PATH_EESCHEMA_CONFIG) bom_plugins_raw = [p for p in config if p.startswith("bom_plugins")] new_list = [] new_list.append(sexpdata.Symbol("plugins")) changes = False if len(bom_plugins_raw) == 1: bom_plugins_raw = after(bom_plugins_raw[0], "bom_plugins=") bom_plugins_raw = de_escape(bom_plugins_raw) bom_list = sexpdata.loads(bom_plugins_raw) if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH): name = name.replace("\\", '/') for plugin in bom_list[1:]: search = plugin[1] if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH): search = plugin[1].replace("\\", '/') if re.findall(name, search, re_flags): changes = True # The name in really in the 'name'. continue # We want to delete this entry. else: for entry in plugin[2:]: if entry[0] == sexpdata.Symbol('opts') and re.findall(r'nickname\s*=\s*'+name, entry[1], re_flags): changes = True continue # The name is in the 'nickname'. new_list.append(plugin) # This plugin remains on the list. if changes: s = sexpdata.dumps(new_list) config = update_config_file(config, "bom_plugins", escape(s)) write_config_file(PATH_EESCHEMA_CONFIG, config)
def fields_remove_entry(values_modify, re_flags=re.IGNORECASE): '''Remove a list of fields from the Eeschema template.''' if type(values_modify) is not list: values_modify = [values_modify] config = read_config_file(PATH_EESCHEMA_CONFIG) values = [p for p in config if p.startswith("FieldNames")] changes = False delete_list = [] if len(values) == 1: values = after(values[0], "FieldNames=") values = de_escape(values) values = sexpdata.loads(values) # TODO validate it, was using an undefined variable `name` if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH): values = values.replace("\\", '/') for value_modify in values_modify: for idx, value in enumerate(values[1:]): search = value[1] if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH): search = value[1].replace("\\", '/') if re.findall(value_modify, search[1], re_flags): changes = True # The name in really in the 'name'. delete_list.append(idx) # We want to delete this entry. for delete in sorted(set(delete_list), reverse=True): del values[delete+1] if changes: s = sexpdata.dumps(values) config = update_config_file(config, "FieldNames", escape(s)) write_config_file(PATH_EESCHEMA_CONFIG, config)
def remove_bom_plugin_entry(kicad_config_path, name, re_flags=re.IGNORECASE): # Remove a BOM plugin enttry to the Eeschema configuration file. config = read_config_file(os.path.join(kicad_config_path, "eeschema")) bom_plugins_raw = [p for p in config if p.startswith("bom_plugins")] new_list = [] new_list.append(sexpdata.Symbol("plugins")) changes = False if len(bom_plugins_raw) == 1: bom_plugins_raw = after(bom_plugins_raw[0], "bom_plugins=") bom_plugins_raw = de_escape(bom_plugins_raw) bom_list = sexpdata.loads(bom_plugins_raw) for plugin in bom_list[1:]: if re.findall(name, plugin[1], re_flags): changes = True # The name in really in the 'name'. continue # We want to delete this entry. else: for entry in plugin[2:]: if entry[0]==sexpdata.Symbol('opts') and\ re.findall('nickname\s*=\s*'+name, entry[1], re_flags): changes = True continue # The name is in the 'nickname'. new_list.append(plugin) # This plugin remains on the list. if changes: s = sexpdata.dumps(new_list) config = update_config_file(config, "bom_plugins", escape(s)) write_config_file(os.path.join(kicad_config_path, "eeschema"), config)
def missing_ppx_error(dune, ppx): print( "In dune file " + dune + ", the preprocessing clause is missing; there should be one containing " + (sexpdata.dumps(ppx))) global exit_code exit_code = 1
def step(self, command): ''' perform a single interaction the agent provides a command and get feedback from Coq valid commands include: tactics Admitted - to give up the proof Undo - to backtrack one step other valid Coq commands ''' if self.success: return self.feedback('ALREADY_SUCCEEDED') if self.failure: return self.feedback('ALREADY_FAILED') time_left = self.timeout - (time() - self.start_time) print('%d: %s: %.02f' % (self.num_tactics_left, command, time_left)) if time_left <= 0: return self.feedback('MAX_TIME_REACHED') self.serapi.push() # save the state before executing the command try: ast = sexpdata.dumps(self.serapi.query_ast(command)) if 'VernacExtend' in ast: # is a tactic if self.num_tactics_left <= 0: self.serapi.pop() return self.feedback('MAX_NUM_TACTICS_REACHED') self.num_tactics_left -= 1 command = 'timeout %d (%s).' % (time_left, command[:-1]) responses, _ = self.serapi.execute(command) self.serapi.pull() # delete the saved state if no error except CoqExn as ex: self.serapi.pop() # restore the state return self.feedback('ERROR', error=ex) except CoqTimeout as ex: self.serapi.shutdown() return self.feedback('ERROR', error=ex) if '(VernacEndProof Admitted)' in ast: self.failure = True return self.feedback('GIVEN_UP') try: fg_goals, bg_goals, shelved_goals, given_up_goals = self.serapi.query_goals() time_left = self.timeout - (time() - self.start_time) if time_left < 0: return self.feedback('MAX_TIME_REACHED') except CoqTimeout as ex: self.serapi.shutdown() return self.feedback('ERROR', error=ex) if fg_goals + bg_goals + shelved_goals + given_up_goals == []: # no goals left self.success = True return self.feedback('SUCCESS') elif shelved_goals + given_up_goals != []: self.serapi.pop() return self.feedback('ERROR', error=(shelved_goals, given_up_goals)) else: return self.feedback('PROVING', fg_goals=fg_goals, bg_goals=bg_goals, shelved_goals=shelved_goals, given_up_goals=given_up_goals)
def execute(self, cmd, return_ast=False): 'Execute a vernac command' if cmd in ['Set Printing Notations.', 'Unset Printing Notations.']: print(cmd) state_id, ast = self.send_add(cmd, return_ast) responses, _ = self.send('(Exec %d)' % state_id) return responses, sexpdata.dumps(ast)
def eval_in_emacs(method_name, args): global epc_client import sexpdata args = [sexpdata.Symbol(method_name)] + list(map(sexpdata.Quoted, args)) # type: ignore sexp = sexpdata.dumps(args) epc_client.call("eval-in-emacs", [sexp]) # type: ignore
def _generate_node_from_sexp(self, e): node_name = dumps(car(e)) node_type_str = dumps(car(cdr(e))) node_type = NodeType.from_string(node_type_str) if node_type is NodeType.ENTAILMENT: result = EntailmentNode(node_name, self) elif node_type is NodeType.AND: result = AndNode(node_name, self) elif node_type is NodeType.DONE: result = DoneNode(node_name, self) elif node_type is NodeType.MODEL_CHECKING: result = ModelCheckingNode(node_name, self) elif node_type is NodeType.DELAY_ANALYSIS: result = DelayAnalysisNode(node_name, self) else: assert (False) return result
def swank_compile_string_for_emacs(self, cmd_str, *args): # (sexp buffer-name (:position 1) (:line 1) () ()) # FIXME: This does not compile actually, just eval instead. # Although compiling it would have effect on the Call Stack cmd_str = "(lisp:progn " + cmd_str + ")" messages = [] sexp = loads(cmd_str, nil=None) for exp in sexp[1:]: if len(exp) > 2: messages.append(dumps(exp[:2] + [None], none_as='...')) else: messages.append(dumps(exp)) lock = self.euslisp.euslime_connection_lock log.debug('Acquiring lock: %s' % lock) lock.acquire() try: for res in self.euslisp.eval(cmd_str): if isinstance(res, list): yield res for msg in messages: yield [Symbol(":write-string"), "; Loaded {}\n".format(msg)] errors = [] seconds = 0.01 yield EuslispResult([ Symbol(":compilation-result"), errors, True, seconds, None, None ]) lock.release() except AbortEvaluation as e: if lock.locked(): lock.release() log.info('Aborting evaluation...') # Force-print the message, which is # by default only displayed on the minibuffer if e.message: yield [ Symbol(":write-string"), "; Evaluation aborted on {}\n".format(e.message), Symbol(":repl-result") ] yield EuslispResult(None) except Exception: if lock.locked(): lock.release() raise
def filter_parser_output(parses, word2ids, sources, targets): filtered = {} if sources and targets and parses and word2ids: for key in parses: allfound = False toKeep = set() if key in sources and key in targets and key in word2ids: allfound = True wids = word2ids[key] for w in sources[key].strip().split(): if w in wids: toKeep.update(wids[w]) else: allfound = False break for w in targets[key].strip().split(): if w in wids: toKeep.update(wids[w]) else: allfound = False break if allfound and toKeep: filtered[key] = "(O (name " + str(key) + ") (^ " o = sexpdata.loads(parses[key]) for p in o[2]: if type(p) == list: # print("p: " + str(p)) pidstring = sexpdata.dumps(p[-1]) # print("pidstring: " + pidstring) result = idPattern.match(pidstring) keep_this_one = True if result: keep_this_one = False pids = result.group(1).split(",") for pid in pids: try: pid = int(result.group(1)) \ if result else None pid = remove_thousands(pid) except ValueError: pid = None # print("pid number: " + str(pid)) if not pid or pid in toKeep: keep_this_one = True break if keep_this_one: filtered[key] += print_pred(p) # print("filtered[key]: " + filtered[key]) filtered[key] += "))" parser_output = "" if parses: for key in parses: if key in filtered: parser_output += filtered[key] + "\n" else: parser_output += parses[key] + "\n" return parser_output
def get_ppx_ndx(dune, ppxs, ppx): try: ppxs.index(ppx) except: print("In dune file " + dune + ", the preprocessing clause does not contain " + (sexpdata.dumps(ppx))) global exit_code exit_code = 1
def get_verb_katuyou(sexp, katuyou_type, verb_form): for verb_type_sexp in sexp: verb_type = verb_type_sexp[0] verb_form_sexp = verb_type_sexp[1] if verb_type == Symbol(katuyou_type): for sexp2 in verb_form_sexp: cond = False if (katuyou_type == "ナ形容詞" or katuyou_type == "ナノ形容詞" or katuyou_type == "ナ形容詞特殊") and (verb_form != "基本形") and (verb_form != "語幹") and not ("ダ列" in verb_form): cond = sexp2[0] == Symbol("ダ列" + verb_form) else: cond = sexp2[0] == Symbol(verb_form) if cond: return dumps(sexp2[1]).encode('utf-8') #例外 # print katuyou_type # print verb_form raise Exception("%s, %s" % (katuyou_type, verb_form))
def parse_custom_keywords(sexp): """Parse custom keywords from ``sexp``. Return a dictionary with corresponding symbol properties. """ plist = parse_plist(sexp) properties = {} package_version = plist.get(':package-version') if package_version: try: properties['custom-package-version'] = parse_package_version( package_version) except ValueError: pass safe_predicate = plist.get(':safe') if is_quoted(safe_predicate): properties['safe-local-variable'] = sexpdata.dumps( unquote(safe_predicate)) if plist.get(':risky'): properties['risky-local-variable'] = True return properties
def __str__(self): return sexpdata.dumps(self.expression)
def encode_object(obj, **kwds): return encode_string(dumps(obj, **kwds))
def print_pred(p): return sexpdata.dumps(p).replace(": [", ":[").encode("utf-8")
def dumps(obj, **kwargs): return sexpdata.dumps(obj, **kwargs)
def get_string(self): return sexpdata.dumps(self.data)
def dump_command(command, *args): res = [Symbol(command),] if len(args) != 0: res.extend(args) return dumps(res)
def get_katuyou_str_from_id(s_exp, katuyou_type_ind, katuyou_form_ind): ans1 = s_exp[katuyou_type_ind-1][0] ans2 = s_exp[katuyou_type_ind-1][1][katuyou_form_ind-1][0] return (dumps(ans1).encode('utf-8'), dumps(ans2).encode('utf-8'))