Initial project import

This commit is contained in:
Agila Forge Importer committed 2026-07-13 15:20:32 +00:00
commit 23f2d29e32
11957 files changed
+1754577

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
module errors
import os
import v3.token
pub fn details(file &token.File, pos token.Position, row_padding int) string {
if file.name == '' {
return 'at ${pos.line}:${pos.column}'
}
src := os.read_file(file.name) or { return 'at ${pos.line}:${pos.column} in `${file.name}`' }
line_start := if pos.line - row_padding - 1 > 0 {
file.line_start(pos.line - row_padding)
} else {
0
}
mut line_end := pos.offset + 1
for i := 0; line_end < src.len; {
if src[line_end] == `\n` {
i++
if i == row_padding + 1 {
break
}
}
line_end++
}
lines_src := src[line_start..line_end].split('\n')
line_no_start, _ := file.find_line_and_column(line_start)
mut lines_src_formatted := []string{}
for i in 0 .. lines_src.len {
line_no := line_no_start + i
line_src := lines_src[i]
line_spaces := line_src.replace('\t', ' ')
lines_src_formatted << '${line_no:5d} | ' + line_spaces
if line_no == pos.line {
space_diff := line_spaces.len - line_src.len
lines_src_formatted << ' ' + ' '.repeat(space_diff + pos.column - 1) + '^'
}
}
return lines_src_formatted.join('\n')
}
+27
View File
@@ -0,0 +1,27 @@
module errors
import v3.token
pub enum Reporter {
scanner
parser
checker
gen
}
pub struct CompilerMessage {
pub:
message string
details string
file_path string
pos token.Pos
reporter Reporter
}
pub struct Error {
CompilerMessage
}
pub struct Warning {
CompilerMessage
}
+33
View File
@@ -0,0 +1,33 @@
module errors
import v3.token
import term
pub enum Kind {
warning
notice
error
}
pub fn (e Kind) str() string {
return match e {
.warning { 'warning' }
.notice { 'notice' }
.error { 'error' }
}
}
pub fn (e Kind) color(s string) string {
return match e {
.warning { term.yellow(s) }
.notice { term.blue(s) }
.error { term.red(s) }
}
}
pub fn error(msg string, details string, kind Kind, pos token.Position) {
eprintln(pos.str() + ' -> ' + term.bold(kind.color(kind.str())) + ': ' + msg)
if details.len > 0 {
eprintln(details)
}
}