Allow shortening locations from 1:x-1:y to x-y 🩳

This commit is contained in:
Laurenz 2021-01-30 16:46:16 +01:00
parent bcb2c46a10
commit e3139ed3ee
17 changed files with 59 additions and 57 deletions

View File

@ -17,11 +17,11 @@
,)}
// Missing closing paren.
// Error: 1:3-1:3 expected closing paren
// Error: 3-3 expected closing paren
{(}
// Not an array.
// Error: 1:2-1:3 expected expression, found closing paren
// Error: 2-3 expected expression, found closing paren
{)}
// Missing comma and bad expression.
@ -30,17 +30,17 @@
{(1*/2)}
// Bad expression.
// Error: 1:6-1:8 expected expression, found invalid token
// Error: 6-8 expected expression, found invalid token
{(1, 1u 2)}
// Leading comma is not an expression.
// Error: 1:3-1:4 expected expression, found comma
// Error: 3-4 expected expression, found comma
{(,1)}
// Missing expression makes named pair incomplete, making this an empty array.
// Error: 1:5-1:5 expected expression
// Error: 5-5 expected expression
{(a:)}
// Named pair after this is already identified as an array.
// Error: 1:6-1:10 expected expression, found named pair
// Error: 6-10 expected expression, found named pair
{(1, b: 2)}

View File

@ -5,13 +5,13 @@
{1}
// Bad expression.
// Error: 1:2-1:4 expected expression, found invalid token
// Error: 2-4 expected expression, found invalid token
{1u}
// Missing closing brace in nested block.
// Error: 1:5-1:5 expected closing brace
// Error: 5-5 expected closing brace
{({1) + 1}
// Missing closing bracket in template expression.
// Error: 1:11-1:11 expected closing bracket
// Error: 11-11 expected closing bracket
{[_] + [3_}

View File

@ -33,14 +33,14 @@
#[f|f|f]
// With body.
// Error: 1:7-1:8 expected identifier, found integer
// Error: 7-8 expected identifier, found integer
#[f | 1 | box][💕]
// Error: 2:3-2:3 expected identifier
// Error: 1:4-1:4 expected identifier
#[||f true]
// Error: 1:7-1:7 expected identifier
// Error: 7-7 expected identifier
#[f 1|]
// Error: 2:3-2:3 expected identifier
@ -55,23 +55,23 @@
#[box width: 1cm | image "res/rhino.png"]
---
// Error: 1:5-1:7 expected expression, found end of block comment
// Error: 5-7 expected expression, found end of block comment
#[f */]
// Error: 1:8-1:9 expected expression, found colon
// Error: 8-9 expected expression, found colon
#[f a:1:]
// Error: 1:6-1:6 expected comma
// Error: 6-6 expected comma
#[f 1 2]
// Error: 2:5-2:6 expected identifier
// Error: 1:7-1:7 expected expression
#[f 1:]
// Error: 1:5-1:6 expected identifier
// Error: 5-6 expected identifier
#[f 1:2]
// Error: 1:5-1:8 expected identifier
// Error: 5-8 expected identifier
#[f (x):1]
---
@ -80,7 +80,7 @@
#let x = "string"
#[x]
// Error: 1:3-1:4 expected identifier, found invalid token
// Error: 3-4 expected identifier, found invalid token
#[# 1]
// Error: 4:1-4:1 expected identifier

View File

@ -12,7 +12,7 @@ C/*
, 1]
// End should not appear without start.
// Error: 1:7-1:9 unexpected end of block comment
// Error: 7-9 unexpected end of block comment
/* */ */
// Unterminated is okay.

View File

@ -5,7 +5,7 @@
{(one: 1, two: 2)}
// Simple expression after this is already identified as a dictionary.
// Error: 1:9-1:10 expected named pair, found expression
// Error: 9-10 expected named pair, found expression
{(a: 1, b)}
// Identified as dictionary by initial colon.

View File

@ -19,9 +19,9 @@
\u{41} vs. \\u\{41\}
// Unicode codepoint does not exist.
// Error: 1:1-1:11 invalid unicode escape sequence
// Error: 1-11 invalid unicode escape sequence
\u{FFFFFF}
// Unterminated.
// Error: 1:6-1:6 expected closing brace
// Error: 6-6 expected closing brace
\u{41*Bold*

View File

@ -3,7 +3,7 @@
#let a = 2
#let b = 4
// Error: 1:14-1:17 cannot apply '+' to string
// Error: 14-17 cannot apply '+' to string
#let error = +""
// Paren call.
@ -77,16 +77,16 @@
{ x = "some" } #[test x, "some"]
{ x += "thing" } #[test x, "something"]
// Error: 1:3-1:4 unknown variable
// Error: 3-4 unknown variable
{ z = 1 }
// Error: 1:3-1:6 cannot assign to this expression
// Error: 3-6 cannot assign to this expression
{ (x) = "" }
// Error: 1:3-1:8 cannot assign to this expression
// Error: 3-8 cannot assign to this expression
{ 1 + 2 = 3}
// Error: 1:3-1:6 cannot assign to a constant
// Error: 3-6 cannot assign to a constant
{ box = "hi" }
// Works if we define box before (since then it doesn't resolve to the standard
@ -98,23 +98,23 @@
#[test (2), 2]
#[test (1+2)*3, 9]
// Error: 1:3-1:3 expected expression
// Error: 3-3 expected expression
{-}
// Error: 1:11-1:11 expected expression
// Error: 11-11 expected expression
#[test {1+}, 1]
// Error: 1:11-1:11 expected expression
// Error: 11-11 expected expression
#[test {2*}, 2]
// Error: 1:8-1:17 cannot apply '-' to boolean
// Error: 8-17 cannot apply '-' to boolean
#[test -not true, error]
// Error: 1:2-1:8 cannot apply 'not' to array
// Error: 2-8 cannot apply 'not' to array
{not ()}
// Error: 1:3-1:10 cannot apply '+' to integer and string
// Error: 3-10 cannot apply '+' to integer and string
{(1 + "2")}
// Error: 1:2-1:12 cannot apply '<=' to relative and relative
// Error: 2-12 cannot apply '<=' to relative and relative
{30% <= 40%}

View File

@ -6,7 +6,7 @@
====== Six
// Too many hashtags.
// Warning: 1:1-1:8 should not exceed depth 6
// Warning: 1-8 should not exceed depth 6
======= Seven
---

View File

@ -39,7 +39,7 @@ a#if true {"b"} #else {"?"} c \
#let x = true
// Needs condition.
// Error: 1:6-1:7 expected expression, found closing brace
// Error: 6-7 expected expression, found closing brace
a#if }
// Needs if-body.
@ -48,17 +48,17 @@ a#if }
a#if x b#if (x)c
// Needs else-body.
// Error: 1:20-1:20 expected body
// Error: 20-20 expected body
a#if true [b] #else c
// Lone else.
// Error: 1:1-1:6 unexpected keyword `#else`
// Error: 1-6 unexpected keyword `#else`
#else []
// Condition must be boolean. If it isn't, neither branch is evaluated.
// Error: 1:5-1:14 expected boolean, found string
// Error: 5-14 expected boolean, found string
#if "a" + "b" { "nope" } #else { "nope" }
// No coercing from empty array or or stuff like that.
// Error: 1:5-1:7 expected boolean, found array
// Error: 5-7 expected boolean, found array
#if () { "nope" } #else { "nope" }

View File

@ -21,24 +21,24 @@
#let x = "a"; #let y = "b"; #[test x + y, "ab"]
// Invalid name.
// Error: 1:6-1:7 expected identifier, found integer
// Error: 6-7 expected identifier, found integer
#let 1
// Invalid name.
// Error: 1:6-1:7 expected identifier, found integer
// Error: 6-7 expected identifier, found integer
#let 1 = 2
// Missing binding name.
// Error: 1:5-1:5 expected identifier
// Error: 5-5 expected identifier
#let
x = 5
// Missing right-hand side.
// Error: 1:9-1:9 expected expression
// Error: 9-9 expected expression
#let a =
// No name at all.
// Error: 1:11-1:11 expected identifier
// Error: 11-11 expected identifier
The Fi#let;rst
// Terminated with just a line break.
@ -58,9 +58,9 @@ The#let v = "a"; Fourth #[test v, "a"]
The#let array = (1, 2 + ;Fifth #[test array, (1, 2)]
// Not terminated.
// Error: 1:16-1:16 expected semicolon or line break
// Error: 16-16 expected semicolon or line break
The#let v = "a"Sixth #[test v, "a"]
// Not terminated.
// Error: 1:16-1:16 expected semicolon or line break
// Error: 16-16 expected semicolon or line break
The#let v = "a" #[test v, "a"] Seventh

View File

@ -9,7 +9,7 @@
{ke-bab} \
{α} \
// Error: 1:2-1:3 unknown variable
// Error: 2-3 unknown variable
{_}
// Literal values.

View File

@ -19,7 +19,7 @@
// Set stretch (not available, matching closest).
#[font stretch: ultra-condensed][Condensed]
// Error: 1:8-1:13 unexpected argument
// Error: 8-13 unexpected argument
#[font false]
// Error: 3:15-3:19 expected font style, found font weight
@ -27,10 +27,10 @@
// Error: 1:44-1:45 expected font family or array of font families, found integer
#[font style: bold, weight: "thin", serif: 0]
// Warning: 1:16-1:20 should be between 100 and 900
// Warning: 16-20 should be between 100 and 900
#[font weight: 2700]
// Error: 1:8-1:28 unexpected argument
// Error: 8-28 unexpected argument
#[font something: "invalid"]
---

View File

@ -11,7 +11,7 @@ Add #[h 10pt] #[h 10pt] up
Relative #[h 100%] spacing
// Missing spacing.
// Error: 1:12-1:12 missing argument: spacing
// Error: 12-12 missing argument: spacing
Totally #[h] ignored
// Swapped axes.

View File

@ -7,10 +7,10 @@
// Load an RGB JPEG image.
#[image "res/tiger.jpg"]
// Error: 1:9-1:30 failed to load image
// Error: 9-30 failed to load image
#[image "path/does/not/exist"]
// Error: 1:9-1:30 failed to load image
// Error: 9-30 failed to load image
#[image "typ/image-error.typ"]
---

View File

@ -21,10 +21,10 @@
// Ensure that specific margins override general margins.
#[page margins: 0pt, left: 20pt][Overriden]
// Error: 1:8-1:19 unknown variable
// Error: 8-19 unknown variable
#[page nonexistant]
// Error: 1:18-1:21 aligned axis
// Error: 18-21 aligned axis
#[page main-dir: ltr]
// Flipped predefined paper.

View File

@ -8,7 +8,7 @@
// Warning: 1:12-1:16 should be between 0.0 and 1.0
#[rgb -30, 15.5, 0.5]
// Error: 1:7-1:11 missing argument: blue component
// Error: 7-11 missing argument: blue component
#[rgb 0, 1]
// Error: 3:6-3:6 missing argument: red component

View File

@ -262,7 +262,9 @@ fn parse_metadata(src: &str, map: &LineMap) -> (bool, SpanVec<Diag>) {
}
let pos = |s: &mut Scanner| -> Pos {
let (delta, _, column) = (num(s), s.eat_assert(':'), num(s));
let first = num(s);
let (delta, column) =
if s.eat_if(':') { (first, num(s)) } else { (1, first) };
let line = i as u32 + 1 + delta;
map.pos(Location::new(line, column)).unwrap()
};