@@ -1292,125 +1292,6 @@ let lsts-parse-small-expression(tokens: List<Token>): Tuple<AST,List<Token>> = (
12921292 Tuple ( base, tokens )
12931293);
12941294
1295- let lsts-parse-match2-lhs-one(tokens: List<Token>): Tuple<AST,List<Token>> = (
1296- let expr = mk-eof();
1297- if lsts-parse-head(tokens)==c"[" {
1298- let loc = head(tokens).location;
1299- lsts-parse-expect(c"[", tokens); tokens = tail(tokens);
1300- expr = mk-app(mk-var(c"macro::lhs-tail").with-location(loc), mk-nil());
1301- let seq = [] : List<AST>;
1302- while non-zero(tokens) and lsts-parse-head(tokens)!=c"]" {
1303- (let head, tokens) = lsts-parse-match2-lhs-one-bind(tokens);
1304- if lsts-parse-head(tokens)==c"." and lsts-parse-head(tail(tokens))==c"." {
1305- lsts-parse-expect(c".", tokens); tokens = tail(tokens);
1306- lsts-parse-expect(c".", tokens); tokens = tail(tokens);
1307- seq = cons(head, seq);
1308- } else {
1309- lsts-parse-expect(c"]", tokens);
1310- expr = head;
1311- }
1312- };
1313- for s in seq {
1314- expr = mk-app( mk-var(c"macro::lhs-head"), mk-cons(s,expr) );
1315- };
1316- lsts-parse-expect(c"]", tokens); tokens = tail(tokens);
1317- } else if lsts-parse-head(tokens)==c"(" {
1318- lsts-parse-expect(c"(", tokens); tokens = tail(tokens);
1319- (expr, tokens) = lsts-parse-match2-lhs-one-bind(tokens);
1320- lsts-parse-expect(c")", tokens); tokens = tail(tokens);
1321- } else if lsts-parse-head(tokens)==c"uuid" {
1322- let loc = head(tokens).location;
1323- lsts-parse-expect(c"uuid", tokens); tokens = tail(tokens);
1324- lsts-parse-expect(c"(", tokens); tokens = tail(tokens);
1325- (let name, tokens) = lsts-parse-identifier(tokens);
1326- lsts-parse-expect(c")", tokens); tokens = tail(tokens);
1327- expr = mk-app( mk-var(c"uuid").with-location(loc), mk-var(name).with-location(loc) );
1328- } else if lsts-parse-head(tokens).is-lsts-constant {
1329- expr = lsts-make-lit(head(tokens)); tokens = tail(tokens);
1330- } else if lsts-is-enum-head(lsts-parse-head(tokens)) or (lsts-parse-head(tokens)==c"_" and lsts-parse-head(tail(tokens))==c"{") {
1331- let loc = head(tokens).location;
1332- let tag = lsts-parse-head(tokens); tokens = tail(tokens);
1333- let suffix-condition = mk-var(c"_").with-location(loc);
1334- if lsts-parse-head(tokens)==c"{" {
1335- lsts-parse-expect(c"{", tokens); tokens = tail(tokens);
1336- while non-zero(tokens) and lsts-parse-head(tokens)!=c"}" {
1337- let mode = c"macro::let-name";
1338- if lsts-parse-head(tokens)==c"set" { mode = c"macro::set-name"; tokens = tail(tokens) }
1339- else if lsts-parse-head(tokens)==c"let" { mode = c"macro::let-name"; tokens = tail(tokens) };
1340- let raw = false;
1341- if lsts-parse-head(tokens)==c"raw" { raw = true; tokens = tail(tokens) };
1342- let bind-name = c"_";
1343- (let field-name, tokens) = lsts-parse-identifier(tokens);
1344- if lsts-parse-head(tokens)==c"=" {
1345- lsts-parse-expect(c"=", tokens); tokens = tail(tokens);
1346- bind-name = field-name;
1347- (field-name, tokens) = lsts-parse-identifier(tokens);
1348- };
1349- let val = if lsts-parse-head(tokens)==c":" {
1350- lsts-parse-expect(c":", tokens); tokens = tail(tokens);
1351- (let val, tokens) = lsts-parse-match2-lhs-one(tokens);
1352- val
1353- } else {
1354- mk-var(c"_").with-location(loc)
1355- };
1356- let bind = if bind-name==c"_" then mk-var(bind-name).with-location(loc)
1357- else mk-app( mk-var(mode), mk-var(bind-name).with-location(loc) );
1358- let new-cond = if raw {
1359- mk-app( mk-var(c"macro::lhs-raw-struct-field"), mk-cons(
1360- mk-cons(
1361- bind,
1362- mk-var(field-name)
1363- ),
1364- val
1365- ));
1366- } else {
1367- mk-app( mk-var(c"macro::lhs-struct-field"), mk-cons(
1368- mk-cons(
1369- bind,
1370- mk-var(field-name)
1371- ),
1372- val
1373- ));
1374- };
1375- suffix-condition = mk-app( mk-var(c"macro::lhs-struct"), mk-cons(new-cond, suffix-condition) );
1376- if lsts-parse-head(tokens)!=c"}" {
1377- lsts-parse-expect(c",", tokens); tokens = tail(tokens);
1378- };
1379- };
1380- lsts-parse-expect(c"}", tokens); tokens = tail(tokens);
1381- };
1382- if tag == c"_" {
1383- expr = suffix-condition;
1384- } else {
1385- expr = mk-app(mk-var(c"macro::lhs-struct"), mk-cons( mk-lit(tag).with-location(loc), suffix-condition ));
1386- };
1387- } else if lsts-parse-head(tokens)==c"_" {
1388- expr = mk-var(c"_").with-location(head(tokens).location);
1389- lsts-parse-expect(c"_", tokens); tokens = tail(tokens);
1390- } else if lsts-is-ident-head(lsts-parse-head(tokens)) {
1391- (let name2, tokens) = lsts-parse-identifier(tokens);
1392- expr = mk-var(name2).with-location(head(tokens).location);
1393- } else {
1394- lsts-parse-expect(c"[Left Hand Side]", tokens);
1395- };
1396- (expr, tokens)
1397- );
1398-
1399- let lsts-parse-match2-lhs-one-bind(tokens: List<Token>): Tuple<AST,List<Token>> = (
1400- if lsts-has-assign(tokens) {
1401- let mode = c"macro::let-bind";
1402- if lsts-parse-head(tokens)==c"set" { mode = c"macro::set-bind"; tokens = tail(tokens) }
1403- else if lsts-parse-head(tokens)==c"let" { mode = c"macro::let-bind"; tokens = tail(tokens) };
1404- (let name, tokens) = lsts-parse-identifier(tokens);
1405- lsts-parse-expect(c"=", tokens); tokens = tail(tokens);
1406- (let rest, tokens) = lsts-parse-match2-lhs-one(tokens);
1407- let expr = mk-app(mk-var(mode), mk-cons(rest, mk-var(name)));
1408- (expr, tokens)
1409- } else {
1410- lsts-parse-match2-lhs-one(tokens);
1411- }
1412- );
1413-
14141295let .is-assign-lit(t: AST): Bool = (
14151296 match t {
14161297 App{ left:Var{key:c"macro::let-bind"} } => true;
@@ -1442,86 +1323,6 @@ let .is-constant(t: AST): Bool = (
14421323 }
14431324);
14441325
1445- let lsts-parse-match2-lhs(tokens: List<Token>): Tuple<AST,List<Token>> = (
1446- # prefixes
1447- # suffixes
1448- # list-likes
1449- # tuples
1450- # objects
1451- let original-tokens = tokens;
1452- (let lhs, tokens) = lsts-parse-match2-lhs-one-bind(tokens);
1453- let presufs = mk-vector(type(AST)).push(lhs);
1454- while lsts-parse-head(tokens)==c"." and lsts-parse-head(tail(tokens))==c"." {
1455- lsts-parse-expect(c".", tokens); tokens = tail(tokens);
1456- lsts-parse-expect(c".", tokens); tokens = tail(tokens);
1457- (lhs, tokens) = lsts-parse-match2-lhs-one-bind(tokens);
1458- presufs = presufs.push(lhs);
1459- };
1460- let prefixes = mk-vector(type(AST));
1461- let suffixes = mk-vector(type(AST));
1462- let starti = 0_sz;
1463- let endi = presufs.length - 1;
1464- while starti < endi and presufs[starti].is-constant or presufs[starti].is-assign-lit {
1465- prefixes = prefixes.push(presufs[starti]);
1466- starti = starti + 1;
1467- };
1468- while starti < endi and presufs[endi].is-constant or presufs[endi].is-assign-lit {
1469- suffixes = suffixes.push(presufs[endi]);
1470- endi = endi - 1;
1471- };
1472- if endi != starti then {
1473- fail("Invalid Prefix/Suffix Chain", original-tokens.formatted-location);
1474- };
1475- lhs = presufs[starti];
1476- for p in prefixes {
1477- lhs = mk-app(mk-var(c"macro::lhs-prefix"), mk-cons(p, lhs));
1478- };
1479- while suffixes.length > 0 {
1480- (let p, suffixes) = suffixes.pop-backwards-compatible();
1481- lhs = mk-app(mk-var(c"macro::lhs-suffix"), mk-cons(p, lhs));
1482- };
1483- if lsts-parse-head(tokens)==c"where" {
1484- lsts-parse-expect(c"where", tokens); tokens = tail(tokens);
1485- (let cond, tokens) = lsts-parse-ascript(tokens);
1486- lhs = mk-app( mk-var(c"macro::lhs-guard"), mk-cons(lhs,cond) );
1487- };
1488- (lhs, tokens)
1489- );
1490-
1491- let lsts-parse-match2(tokens: List<Token>): Tuple<AST,List<Token>> = (
1492- let loc = head(tokens).location;
1493- lsts-parse-expect(c"match2", tokens); tokens = tail(tokens);
1494- let raw = lsts-parse-head(tokens)==c"raw"; if raw { tokens = tail(tokens); };
1495- (let expr, tokens) = lsts-parse-small-expression(tokens);
1496- if raw then expr = mk-app(mk-var(c"macro::bind-raw"), expr);
1497- let case-root = mk-app(mk-var(c"fail"),mk-cons(
1498- mk-lit(c"Pattern Match Failure").ascript(t0(c"String") && t0(c"Literal")),
1499- mk-app(mk-var(c"macro::location"),mk-var(c"here").with-location(loc))
1500- ));
1501- lsts-parse-expect(c"{", tokens); tokens = tail(tokens);
1502- let cases = [] : List<(AST,AST)>;
1503- while non-zero(tokens) and lsts-parse-head(tokens)!=c"}" {
1504- (let lhs, tokens) = lsts-parse-match2-lhs(tokens);
1505- lsts-parse-expect(c"=", tokens); tokens = tail(tokens);
1506- lsts-parse-expect(c">", tokens); tokens = tail(tokens);
1507- if lsts-parse-head(tokens) == c"{" {
1508- fail("Please wrap map literals in match cases in parenthesis. At \{tokens.formatted-location}\n");
1509- };
1510- (let rhs, tokens) = lsts-parse-small-expression(tokens);
1511- lsts-parse-expect(c";", tokens); tokens = tail(tokens);
1512- cases = cons( (lhs,rhs), cases );
1513- };
1514- for Tuple{lhs=first,rhs=second} in cases {
1515- case-root = mk-app(
1516- mk-var(c"macro::match-case"),
1517- mk-cons(mk-cons(lhs,rhs),case-root)
1518- );
1519- };
1520- lsts-parse-expect(c"}", tokens); tokens = tail(tokens);
1521- let result-expr = mk-app(mk-var(c"macro::match"), mk-cons(expr, case-root));
1522- (result-expr, tokens);
1523- );
1524-
15251326let lsts-parse-assign(tokens: List<Token>): Tuple<AST,List<Token>> = (
15261327 let base = mk-eof();
15271328 if lsts-has-assign(tokens) {
@@ -1898,8 +1699,6 @@ let lsts-parse-atom-without-tail(tokens: List<Token>): Tuple<AST,List<Token>> =
18981699 )
18991700 )
19001701 );
1901- } else if lsts-parse-head(tokens)==c"match2" {
1902- (term, tokens) = lsts-parse-match2(tokens);
19031702 } else if lsts-parse-head(tokens)==c"match" {
19041703 let loc = head(tokens).location; tokens = tail(tokens);
19051704 let raw = if lsts-parse-head(tokens)==c"raw" {
@@ -1941,6 +1740,9 @@ let lsts-parse-atom-without-tail(tokens: List<Token>): Tuple<AST,List<Token>> =
19411740 );
19421741 } else if lsts-parse-head(tokens).has-suffix(c"_ss") {
19431742 (term, tokens) = lsts-parse-lit(tokens);
1743+ } else if lsts-parse-head(tokens).has-suffix(c"_l") {
1744+ term = mk-lit(lsts-parse-head(tokens).remove-suffix(c"_l").get-or-panic).ascript(t0(c"L"));
1745+ tokens = tail(tokens);
19441746 } else if lsts-parse-head(tokens).has-suffix(c"_rl") {
19451747 term = mk-lit(lsts-parse-head(tokens).remove-suffix(c"_rl").get-or(c""));
19461748 tokens = tail(tokens);
0 commit comments