1 //
2 // Copyright (c) 2006, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 18 May 06 Brian Frank Creation
7 //
8
9 **
10 ** Location provides a source file, line number, and column number.
11 **
12 class Location
13 {
14
15 new make(Str file, Int line := null, Int col := null)
16 {
17 this.file = file
18 this.line = line
19 this.col = col
20 }
21
22 new makeFile(File file)
23 {
24 if (file != null)
25 {
26 osPath := file.osPath
27 if (osPath != null)
28 this.file = osPath
29 else
30 this.file = file.pathStr
31 }
32 }
33
34 new makeUninit()
35 {
36 }
37
38 Str filename()
39 {
40 if (file == null) return null
41 f := file
42 slash := f.indexr("/")
43 if (slash == null) slash = f.indexr("\\")
44 if (slash != null) f = f[slash+1..-1]
45 return f
46 }
47
48 Str fileUri()
49 {
50 try
51 {
52 return File.os(file).uri.toStr
53 }
54 catch
55 {
56 return file
57 }
58 }
59
60 override Str toStr()
61 {
62 return toLocationStr
63 }
64
65 Str toLocationStr()
66 {
67 StrBuf s := StrBuf.make
68 s.add(file)
69 if (line != null)
70 {
71 s.add("(").add(line)
72 if (col != null) s.add(",").add(col)
73 s.add(")")
74 }
75 return s.toStr
76 }
77
78 Str file
79 Int line
80 Int col
81
82 }
2 // Copyright (c) 2006, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 18 May 06 Brian Frank Creation
7 //
8
9 **
10 ** Location provides a source file, line number, and column number.
11 **
12 class Location
13 {
14
15 new make(Str file, Int line := null, Int col := null)
16 {
17 this.file = file
18 this.line = line
19 this.col = col
20 }
21
22 new makeFile(File file)
23 {
24 if (file != null)
25 {
26 osPath := file.osPath
27 if (osPath != null)
28 this.file = osPath
29 else
30 this.file = file.pathStr
31 }
32 }
33
34 new makeUninit()
35 {
36 }
37
38 Str filename()
39 {
40 if (file == null) return null
41 f := file
42 slash := f.indexr("/")
43 if (slash == null) slash = f.indexr("\\")
44 if (slash != null) f = f[slash+1..-1]
45 return f
46 }
47
48 Str fileUri()
49 {
50 try
51 {
52 return File.os(file).uri.toStr
53 }
54 catch
55 {
56 return file
57 }
58 }
59
60 override Str toStr()
61 {
62 return toLocationStr
63 }
64
65 Str toLocationStr()
66 {
67 StrBuf s := StrBuf.make
68 s.add(file)
69 if (line != null)
70 {
71 s.add("(").add(line)
72 if (col != null) s.add(",").add(col)
73 s.add(")")
74 }
75 return s.toStr
76 }
77
78 Str file
79 Int line
80 Int col
81
82 }