Skip to content

Commit 28bcfb0

Browse files
authored
Merge branch 'develop' into tolga/toml-options-rebased
2 parents 97e46ef + 9c0d15c commit 28bcfb0

27 files changed

+5150
-5124
lines changed

pyk/src/pyk/__main__.py

-1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,5 @@ def exec_json_to_kore(options: JsonToKoreOptions) -> None:
382382
kore.write(sys.stdout)
383383
sys.stdout.write('\n')
384384

385-
386385
if __name__ == '__main__':
387386
main()

pyk/src/pyk/cli/pyk.py

+2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class ProveOptions(LoggingOptions, SpecOptions, SaveDirOptions):
222222
definition_dir: Path | None
223223
type_inference_mode: TypeInferenceMode | None
224224
failure_info: bool
225+
kore_rpc_command: str | Iterable[str] | None
225226
max_depth: int | None
226227
max_iterations: int | None
227228
show_kcfg: bool
@@ -232,6 +233,7 @@ def default() -> dict[str, Any]:
232233
'definition_dir': None,
233234
'type_inference_mode': None,
234235
'failure_info': False,
236+
'kore_rpc_command': None,
235237
'max_depth': None,
236238
'max_iterations': None,
237239
'show_kcfg': False,

pyk/src/pyk/kast/outer_lexer.py

+39-23
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ class Loc(NamedTuple):
6464

6565
def __add__(self, other: object) -> Loc:
6666
if isinstance(other, str):
67+
"""Return the line,column after the additional text"""
6768
line, col = self.line, self.col
6869
for c in other:
69-
col += 1
7070
if c == '\n':
7171
line += 1
7272
col = 0
73+
col += 1
7374
return Loc(line, col)
7475
return NotImplemented
7576

@@ -190,23 +191,36 @@ class State(Enum):
190191

191192

192193
class LocationIterator(Iterator[str]):
193-
_line: int = 1
194-
_col: int = 0
194+
"""A string iterator which tracks the line and column information of the characters in the string"""
195+
196+
_line: int
197+
_col: int
195198
_iter: Iterator[str]
199+
_nextline: bool
196200

197-
def __init__(self, x: Iterable[str]) -> None:
198-
self._iter = iter(x)
201+
def __init__(self, text: Iterable[str], line: int = 1, col: int = 0) -> None:
202+
self._iter = iter(text)
203+
self._line = line
204+
self._col = col
205+
self._nextline = False
199206

200207
def __next__(self) -> str:
201208
la = next(self._iter)
202209
self._col += 1
203-
if la == '\n':
210+
if self._nextline:
204211
self._line += 1
205-
self._col = 0
212+
self._col = 1
213+
self._nextline = la == '\n'
206214
return la
207215

208216
@property
209217
def loc(self) -> Loc:
218+
"""Returns the line,column of the last character returned by the iterator
219+
220+
If no character has been returned yet, it will be the location that this
221+
iterator was initialized with. The default is (1,0), which is the only
222+
time the column will be 0.
223+
"""
210224
return Loc(self._line, self._col)
211225

212226

@@ -617,7 +631,7 @@ def _bubble_or_context(la: str, it: LocationIterator, *, context: bool = False)
617631
bubble, final_token, la, bubble_loc = _raw_bubble(la, it, keywords)
618632
if bubble is not None:
619633
label_tokens, bubble, bubble_loc = _strip_bubble_label(bubble, bubble_loc)
620-
bubble, attr_tokens = _strip_bubble_attr(bubble)
634+
bubble, attr_tokens = _strip_bubble_attr(bubble, bubble_loc)
621635

622636
tokens = label_tokens
623637
if bubble:
@@ -723,23 +737,23 @@ def _strip_bubble_label(bubble: str, loc: Loc) -> tuple[list[Token], str, Loc]:
723737
Token(':', TokenType.COLON, colon_loc),
724738
],
725739
match['rest'],
726-
loc + bubble[: match.start('rest')],
740+
colon_loc + bubble[match.start('colon') : match.start('rest')],
727741
)
728742

729743

730-
def _strip_bubble_attr(bubble: str) -> tuple[str, list[Token]]:
744+
def _strip_bubble_attr(bubble: str, loc: Loc) -> tuple[str, list[Token]]:
731745
for i in range(len(bubble) - 1, -1, -1):
732746
if bubble[i] != '[':
733747
continue
734748

735749
prefix = bubble[:i]
736-
suffix = bubble[i:]
750+
suffix = bubble[i + 1 :]
751+
start_loc = loc + prefix
737752

738-
it = iter(suffix)
739-
next(it) # skip "["
753+
it = LocationIterator(suffix, *start_loc)
740754
la = next(it, '')
741755

742-
tokens = [Token('[', TokenType.LBRACK, INIT_LOC)]
756+
tokens = [Token('[', TokenType.LBRACK, start_loc)]
743757
attr_tokens = _attr(la, it)
744758
try:
745759
while True:
@@ -757,7 +771,7 @@ def _strip_bubble_attr(bubble: str) -> tuple[str, list[Token]]:
757771
return bubble, []
758772

759773

760-
def _attr(la: str, it: Iterator[str]) -> Generator[Token, None, str]:
774+
def _attr(la: str, it: LocationIterator) -> Generator[Token, None, str]:
761775
la = _skip_ws_and_comments(la, it)
762776
if not la:
763777
raise _unexpected_character(la)
@@ -769,46 +783,48 @@ def _attr(la: str, it: Iterator[str]) -> Generator[Token, None, str]:
769783
la = _skip_ws_and_comments(la, it)
770784

771785
if la == '(': # TAG_STATE
772-
yield Token('(', TokenType.LPAREN, INIT_LOC)
786+
yield Token('(', TokenType.LPAREN, it.loc)
773787
la = next(it, '')
788+
loc = it.loc
774789

775790
if la == '"':
776791
text, token_type, la = _string(la, it)
777-
yield Token(text, token_type, INIT_LOC)
792+
yield Token(text, token_type, loc)
778793
else:
779794
content, la = _attr_content(la, it)
780795
if content:
781796
# allows 'key()'
782-
yield Token(content, TokenType.ATTR_CONTENT, INIT_LOC)
797+
yield Token(content, TokenType.ATTR_CONTENT, loc)
783798

784799
if la != ')':
785800
raise _unexpected_character(la)
786801

787-
yield Token(')', TokenType.RPAREN, INIT_LOC)
802+
yield Token(')', TokenType.RPAREN, it.loc)
788803

789804
la = next(it, '')
790805
la = _skip_ws_and_comments(la, it)
791806

792807
if la != ',':
793808
break
794809

795-
yield Token(',', TokenType.COMMA, INIT_LOC)
810+
yield Token(',', TokenType.COMMA, it.loc)
796811
la = next(it, '')
797812
la = _skip_ws_and_comments(la, it)
798813

799814
if la != ']':
800815
raise _unexpected_character(la)
801816

802-
yield Token(']', TokenType.RBRACK, INIT_LOC)
817+
yield Token(']', TokenType.RBRACK, it.loc)
803818
la = next(it, '')
804819

805820
return la # noqa: B901
806821

807822

808-
def _attr_key(la: str, it: Iterator[str]) -> tuple[Token, str]:
823+
def _attr_key(la: str, it: LocationIterator) -> tuple[Token, str]:
809824
# ["a"-"z","1"-"9"](["A"-"Z", "a"-"z", "-", "0"-"9", "."])*("<" (["A"-"Z", "a"-"z", "-", "0"-"9"])+ ">")?
810825

811826
consumed: list[str] = []
827+
loc = it.loc
812828
if la not in _LOWER and la not in _DIGIT:
813829
raise _unexpected_character(la)
814830

@@ -840,7 +856,7 @@ def _attr_key(la: str, it: Iterator[str]) -> tuple[Token, str]:
840856
la = next(it, '')
841857

842858
attr_key = ''.join(consumed)
843-
return Token(attr_key, TokenType.ATTR_KEY, INIT_LOC), la
859+
return Token(attr_key, TokenType.ATTR_KEY, loc), la
844860

845861

846862
_ATTR_CONTENT_FORBIDDEN: Final = {'', '\n', '\r', '"'}

pyk/src/pyk/kore/rpc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ def __init__(self, args: KoreServerArgs):
11401140
if not (command := args.get('command')):
11411141
self._command = ['kore-rpc']
11421142
elif type(command) is str:
1143-
self._command = [command]
1143+
self._command = command.split()
11441144
else:
11451145
self._command = list(command)
11461146

pyk/src/pyk/ktool/kprove.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ def prove_rpc(
354354
kcfg_semantics: KCFGSemantics | None = None,
355355
id: str | None = None,
356356
port: int | None = None,
357-
kore_rpc_command: str | Iterable[str] | None = None,
358357
llvm_definition_dir: Path | None = None,
359358
smt_timeout: int | None = None,
360359
smt_retry_limit: int | None = None,
@@ -376,7 +375,7 @@ def _prove_claim_rpc(claim: KClaim) -> Proof:
376375
kcfg_semantics=kcfg_semantics,
377376
id=id,
378377
port=port,
379-
kore_rpc_command=kore_rpc_command,
378+
kore_rpc_command=options.kore_rpc_command,
380379
llvm_definition_dir=llvm_definition_dir,
381380
smt_timeout=smt_timeout,
382381
smt_retry_limit=smt_retry_limit,

0 commit comments

Comments
 (0)