|
1044 | 1044 | ; true |
1045 | 1045 | ; nb_current('$file_src_depth', 0)), |
1046 | 1046 |
|
1047 | | - cont_sexpr_once(EndChar, Stream, Subr), !, |
| 1047 | + with_depth_plus_one(cont_sexpr(EndChar, Stream, Subr)), !, |
1048 | 1048 | Item = exec(Subr). |
1049 | 1049 |
|
1050 | 1050 | % allow in mettalog the special ` ,(<eval this>) ` form in intepreter |
1051 | | -cont_sexpr_from_char(EndChar, Stream, ',', Item) :- |
| 1051 | +cont_sexpr_from_char(EndChar, Stream, ',', Item) :- fail, % some cases users have written ( A,(B)) |
1052 | 1052 | peek_char(Stream, Next), |
1053 | 1053 | Next == '(', |
1054 | 1054 | %\+ paren_pair_functor(_, Next, _), |
1055 | 1055 | %Next \== ' ', |
1056 | | - cont_sexpr_once(EndChar, Stream, Subr), !, |
| 1056 | + with_depth_plus_one(cont_sexpr(EndChar, Stream, Subr)), !, |
1057 | 1057 | Item = exec(Subr). |
1058 | 1058 |
|
1059 | 1059 | % If '(', read an S-expression list. |
|
1082 | 1082 |
|
1083 | 1083 | % If '#' followed by '(', read SExpr as Prolog Expression |
1084 | 1084 | cont_sexpr_from_char(EndChar, Stream, '#', Item) :- peek_char(Stream, '('), |
1085 | | - cont_sexpr_once(EndChar, Stream, Subr), |
| 1085 | + with_depth_plus_one(cont_sexpr(EndChar, Stream, Subr)), |
1086 | 1086 | univ_maybe_var(Item, Subr). |
1087 | 1087 |
|
1088 | 1088 | % Unexpected end character |
|
1330 | 1330 | % read_char(Stream, ';'), % Skip the ';' character. |
1331 | 1331 | read_line_char(Stream, line_char(Line1, Col)), |
1332 | 1332 | %succ(Col0, Col1), |
1333 | | - read_line_to_string(Stream, Comment), |
1334 | | - atom_length(Comment,Len), EndCol is Col + Len, |
1335 | | - Range = range(line_char(Line1, Col), line_char(Line1, EndCol)), |
| 1333 | + read_line_to_string_maybe_more(Stream, Comment), |
| 1334 | + %atom_length(Comment,Len), EndCol is Col + Len, |
| 1335 | + read_line_char(Stream, line_char(Line2, EndCol)), |
| 1336 | + Range = range(line_char(Line1, Col), line_char(Line2, EndCol)), |
1336 | 1337 | push_item_range('$COMMENT'(Comment, Line1, Col), Range). |
1337 | 1338 |
|
| 1339 | + |
| 1340 | +read_line_to_string_maybe_more(Stream, Comment):- |
| 1341 | + read_line_to_string(Stream, CommentStart), |
| 1342 | + peek_string(Stream, 5, LookAhead), |
| 1343 | + (start_line_comment(LookAhead) -> |
| 1344 | + (read_line_to_string_maybe_more(Stream, CommentCont), atomics_to_string([CommentStart,"\n",CommentCont],Comment)) ; CommentStart = Comment). |
| 1345 | + |
| 1346 | +start_line_comment(Var):- var(Var), !, fail. |
| 1347 | +start_line_comment(end_of_file):- !, fail. |
| 1348 | +start_line_comment(String):- string(String), string_chars(String,Chars),!,start_line_comment(Chars). |
| 1349 | +start_line_comment(String):- atom(String), atom_chars(String,Chars),!,start_line_comment(Chars). |
| 1350 | +start_line_comment([C|Chars]):- C==';' -> true ; (C\=='\n',C\=='\r',is_like_space(C),!,start_line_comment(Chars)). |
| 1351 | + |
1338 | 1352 | %! read_position(+Stream:stream, -Line:integer, -Col:integer, -CharPos:integer) is det. |
1339 | 1353 | % |
1340 | 1354 | % Reads the current line, column, and character position from the input stream. |
|
1458 | 1472 | % @arg List The list read from the stream. |
1459 | 1473 | % @arg EndChar that denotes the end of the list. |
1460 | 1474 | read_list(EndChar, Stream, List):- |
1461 | | - nb_current('$file_src_depth', LvL), |
1462 | | - flag('$file_src_ordinal',Ordinal,Ordinal+1), |
1463 | | - succ(LvL,LvLNext), |
| 1475 | + with_depth_plus_one(( |
1464 | 1476 | read_position(Stream, Line, Col, CharPos, _), |
1465 | | - setup_call_cleanup( |
1466 | | - nb_setval('$file_src_depth', LvLNext), |
1467 | | - catch(read_list_cont(EndChar, Stream, List), |
| 1477 | + catch(read_list_cont(EndChar, Stream, List), |
1468 | 1478 | stream_error(Where,Why), |
1469 | | - throw(stream_error(Line:Col:CharPos-Where,Why))), |
1470 | | - nb_setval('$file_src_depth', LvL)). |
| 1479 | + throw(stream_error(Line:Col:CharPos-Where,Why))))). |
| 1480 | + |
| 1481 | +with_depth_plus_one(Goal):- |
| 1482 | + nb_current('$file_src_depth', LvL), |
| 1483 | + flag('$file_src_ordinal',Ordinal,Ordinal+1), |
| 1484 | + succ(LvL,LvLNext), |
| 1485 | + setup_call_cleanup( |
| 1486 | + nb_setval('$file_src_depth', LvLNext), |
| 1487 | + Goal, |
| 1488 | + nb_setval('$file_src_depth', LvL)). |
| 1489 | + |
| 1490 | + |
1471 | 1491 |
|
1472 | 1492 | read_list_cont(EndChar, Stream, List) :- |
1473 | 1493 | skip_spaces(Stream), % Skip any leading spaces before reading. |
|
0 commit comments