WriteLine(); being funky

I'm writing a linker and for some reason print is doing REALLY weird things, as you see in the image
string filedir = Path.GetDirectoryName(mainfile);
filedir = filedir + "\\";
//get the include file
string includefile = line.Split(' ')[1];
//remove quotes
includefile = includefile.Replace("\"", "");
//replace / with \
includefile = includefile.Replace("/", "\\");
string fullincludefile = filedir + includefile;
//check if the file exists
if (!File.Exists(fullincludefile))
{
//Throw error, file does not exist, cannot include, and the line number. then underline the line with ^^^
Console.WriteLine($"Error: File {fullincludefile} does not exist, cannot include, line {cline}");
Console.WriteLine();

Console.WriteLine(line);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(new string('^', line.Length - 1));
Console.ResetColor();
FailedLink = true;
}
if (includedfiles.Contains(line.Split(' ')[1]))
{
//if the included file is not in pragmaoncefiles, then open it and append to entirenewfile withouth the includes
if (!pragmaoncefiles.Contains(line.Split(' ')[1]))
{
string[] filecontents = File.ReadAllLines(line.Split(' ')[1]);
foreach (string fileline in filecontents)
{
if (fileline.Contains("%include"))
{
continue;
}
entirenewfile.Append(fileline);
}
}
continue;
}
string include = line.Split(' ')[1];
//remove quotes
include = include.Replace("\"", "");
includes.Add(include);
string filedir = Path.GetDirectoryName(mainfile);
filedir = filedir + "\\";
//get the include file
string includefile = line.Split(' ')[1];
//remove quotes
includefile = includefile.Replace("\"", "");
//replace / with \
includefile = includefile.Replace("/", "\\");
string fullincludefile = filedir + includefile;
//check if the file exists
if (!File.Exists(fullincludefile))
{
//Throw error, file does not exist, cannot include, and the line number. then underline the line with ^^^
Console.WriteLine($"Error: File {fullincludefile} does not exist, cannot include, line {cline}");
Console.WriteLine();

Console.WriteLine(line);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(new string('^', line.Length - 1));
Console.ResetColor();
FailedLink = true;
}
if (includedfiles.Contains(line.Split(' ')[1]))
{
//if the included file is not in pragmaoncefiles, then open it and append to entirenewfile withouth the includes
if (!pragmaoncefiles.Contains(line.Split(' ')[1]))
{
string[] filecontents = File.ReadAllLines(line.Split(' ')[1]);
foreach (string fileline in filecontents)
{
if (fileline.Contains("%include"))
{
continue;
}
entirenewfile.Append(fileline);
}
}
continue;
}
string include = line.Split(' ')[1];
//remove quotes
include = include.Replace("\"", "");
includes.Add(include);
No description
69 Replies
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
This chunk has the code for printing
if (!File.Exists(fullincludefile))
{
//Throw error, file does not exist, cannot include, and the line number. then underline the line with ^^^
Console.WriteLine($"Error: File {fullincludefile} does not exist, cannot include, line {cline}");
Console.WriteLine();

Console.WriteLine(line);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(new string('^', line.Length - 1));
Console.ResetColor();
FailedLink = true;
}
if (!File.Exists(fullincludefile))
{
//Throw error, file does not exist, cannot include, and the line number. then underline the line with ^^^
Console.WriteLine($"Error: File {fullincludefile} does not exist, cannot include, line {cline}");
Console.WriteLine();

Console.WriteLine(line);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(new string('^', line.Length - 1));
Console.ResetColor();
FailedLink = true;
}
leowest
leowestโ€ข10mo ago
can you provide a bit more code explaining/showing what line is also to avoid issues I would change this bit
string filedir = Path.GetDirectoryName(mainfile);
//get the include file
string includefile = line.Split(' ')[1];
//remove quotes
includefile = includefile.Replace("\"", "");
//replace / with \
includefile = includefile.Replace("/", "\\");
string fullincludefile = Path.Combine(filedir, includefile);
string filedir = Path.GetDirectoryName(mainfile);
//get the include file
string includefile = line.Split(' ')[1];
//remove quotes
includefile = includefile.Replace("\"", "");
//replace / with \
includefile = includefile.Replace("/", "\\");
string fullincludefile = Path.Combine(filedir, includefile);
Depending what line is I might use different methods to get the filename this removes the need to add \\ at the end of filedir and potentially avoid duplicated empty dir
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
Mainfile is passed here
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Hydro.Lexing;
using Hydro.Tokens;
using Hydro.Parsing;
using Hydro.Linking;
namespace Hydro
{
public class Program
{
public string gccpath = ".\\mingw64\\bin\\g++.exe";
public static void Main(string[] args)
{
HydroLinker linker = new HydroLinker(args[0]);
linker.Link();
if (linker.FailedLink)
{
Console.WriteLine("Linking failed");
}
else
{
Console.WriteLine("Linking succeeded");
}
}
}
}
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Hydro.Lexing;
using Hydro.Tokens;
using Hydro.Parsing;
using Hydro.Linking;
namespace Hydro
{
public class Program
{
public string gccpath = ".\\mingw64\\bin\\g++.exe";
public static void Main(string[] args)
{
HydroLinker linker = new HydroLinker(args[0]);
linker.Link();
if (linker.FailedLink)
{
Console.WriteLine("Linking failed");
}
else
{
Console.WriteLine("Linking succeeded");
}
}
}
}
it gets the file path and then check if it exists, pretty simple, then if it doesnt, it throws an error and for some reason print is screwing up
public void Link()
{
//open main file and get includes, then open those files and get includes, etc.
string mainfilecontents = File.ReadAllText(mainfile);
//get full path of main file
mainfile = Path.GetFullPath(mainfile);
string[] includes = getIncludes(mainfilecontents, mainfile);
}
public void Link()
{
//open main file and get includes, then open those files and get includes, etc.
string mainfilecontents = File.ReadAllText(mainfile);
//get full path of main file
mainfile = Path.GetFullPath(mainfile);
string[] includes = getIncludes(mainfilecontents, mainfile);
}
leowest
leowestโ€ข10mo ago
I think the red checks u see are a powershell thing, try running your code from prompt instead I would assume % evaluates to something in powershell and its marking it as wrong syntax or something
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
No, if you look at the code, It is there made by me Console.WriteLine(new string('^', line.Length - 1)); It all works fine, but for some reason it can't print right
leowest
leowestโ€ข10mo ago
you mean this part not printing to the console?
No description
leowest
leowestโ€ข10mo ago
or what is not right I might be missing something and have u tried it outside powershell to see if the result is the same out of curiosity
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
Power shell shouldnโ€™t be the issue, but I can try I donโ€™t like cmd But if it works it works It is not a power shell issue, just tried
leowest
leowestโ€ข10mo ago
yeah I am just rying to rule out the output being the issue
leowest
leowestโ€ข10mo ago
ah from the line input yeah makes sense
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
I hate that, bash doesnt do that, but ol windows and it's \n\r
leowest
leowestโ€ข10mo ago
u could just have a [1].Trim()
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
true ig but I've been programing on linux for a few weeks so I forgot
leowest
leowestโ€ข10mo ago
yeah that was one of the reasons I was curious about what the line was because u were oddly removing some stuff from it
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
It was so It looked print friendly the path would look like this "..\..\..\standard\hello.hyd" plus "F:\Projects\Hydro\bin\debug\net8.0\..\..\..\standard\hello.hyd like that
leowest
leowestโ€ข10mo ago
yeah that's awful
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
truly this "F:\Projects\Hydro\bin\debug\net8.0/../../../standard/hello.hyd" imagine that
leowest
leowestโ€ข10mo ago
but if all u want is hyd files can't u just do a recursive file search on root and that gives u all hyd files with their respective full path
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
well it's a programming language
// Hydro Test Program
// This program is a simple test program for the Hydro language.
%include "standard/hello.hyd"
![pragma] once
int main()
{
hello("Hello, world!");
}
// Hydro Test Program
// This program is a simple test program for the Hydro language.
%include "standard/hello.hyd"
![pragma] once
int main()
{
hello("Hello, world!");
}
I only want to link what the user wants
leowest
leowestโ€ข10mo ago
I see so, I guess you're doing - read file selected by user - get the includes from the top of that file - format the includes - verify the include exists
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
It doesn't get them from the top, it gets them from anywhere, and yes
leowest
leowestโ€ข10mo ago
sure you read all lines for what starts with %include
leowest
leowestโ€ข10mo ago
well glad you figured it out ๐Ÿ˜‰
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
// Hydro Test Program
// This program is a simple test program for the Hydro language.
%include "standard/hello.hyd"

![pragma] once
int main()
{
%include "this.hyd"
hello("Hello, world!");
}
//Useless
%include "standard/uselessfile.hyd"
// Hydro Test Program
// This program is a simple test program for the Hydro language.
%include "standard/hello.hyd"

![pragma] once
int main()
{
%include "this.hyd"
hello("Hello, world!");
}
//Useless
%include "standard/uselessfile.hyd"
includes anywhere now let me make that file path and hope it works
leowest
leowestโ€ข10mo ago
when u distribute the files do u expect it to be on the root of the executable or what
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
As in? It gets the path of the main hyd file and bases it off that
leowest
leowestโ€ข10mo ago
ah I see so if I pass in the command line argument c:\x\y\z.hyd it will assume c:\x\y
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
yeah as the dir Im so proud bc I program in C and ASM so high level langs like this are a bit odd to me classes
leowest
leowestโ€ข10mo ago
I mean u could have done it in c just as easily then
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
yeah but it's a lot more work bc I have to use malloc and free ALL the time I cant just do char* hello = "Hello"; char* world = "World"; hello += world; bc char pointers I have to use strcpy(hello, world, strlen(world)); or
#include <stdio.h>
#include <stdlib.h>
int main()
{
char* response = malloc(100);
printf("Name?");
scanf("%s", response);
printf("Your name is: %s", response);
free(response);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
char* response = malloc(100);
printf("Name?");
scanf("%s", response);
printf("Your name is: %s", response);
free(response);
return 0;
}
that is C right there painful but useful
leowest
leowestโ€ข10mo ago
I mean I know c and c++ all I am saying is that not a whole lot of more code to make it so incovinient
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
I know but memory management in a compiler is hard and C# just had so many features useful to it Plus I use C differently
leowest
leowestโ€ข10mo ago
GC is not always that great thou keep that in mind
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
I know but im lazy so C is too much work unless adhd hyperfixation
leowest
leowestโ€ข10mo ago
var path = Path.GetDirectoryName(filename);
foreach (var line in File.ReadAllLines(filename))
{
if (string.IsNullOrEmpty(line)) continue;
if (line.Contains("%include"))
{
var library = line.Trim().Split(' ')[1].Replace("\"", "");
Console.WriteLine(Path.Combine(path, library));
}
}
var path = Path.GetDirectoryName(filename);
foreach (var line in File.ReadAllLines(filename))
{
if (string.IsNullOrEmpty(line)) continue;
if (line.Contains("%include"))
{
var library = line.Trim().Split(' ')[1].Replace("\"", "");
Console.WriteLine(Path.Combine(path, library));
}
}
leowest
leowestโ€ข10mo ago
reason I am not replacing / is because windows recognizes both patterns so not sure its actually needed. for folder path
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
I replace it so it looks nice to the user
leowest
leowestโ€ข10mo ago
yeah normalized I would say but you probably have more checks in place in the event split fails or the result is empty I assume
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
it's a feature now if you make a typo sure that works
leowest
leowestโ€ข10mo ago
split on the quote instead ๐Ÿ˜›
leowest
leowestโ€ข10mo ago
what the a symbolizes in this new feature
leowest
leowestโ€ข10mo ago
Never heard of hydro got to check that later
leowest
leowestโ€ข10mo ago
is that a language you're creating or
leowest
leowestโ€ข10mo ago
u would have to do something like
leowest
leowestโ€ข10mo ago
fixed code that gets the entrypoint and dereference it
~โœฐ ๐’ฎ๐“‰๐‘’๐“๐“๐’ถ๐“‡ โœฐ~
it's horrible and amazing putting the C in C#
Want results from more Discord servers?
Add your server