40 if (start < 0 || start >= end)
42 throw new ArgumentOutOfRangeException(nameof(start));
45 if (end > source.Length)
47 throw new ArgumentOutOfRangeException(nameof(end));
60 public BadSourceReader(
string fileName,
string source) : this(fileName, source, 0, source.Length) { }
161 public bool Is(
char c,
int offset = 0)
172 public bool Is(
string s,
int offset = 0)
174 for (
int i = 0; i < s.Length; i++)
176 if (!
Is(s[i], offset + i))
190 public bool Is(params
char[] chars)
200 public bool Is(params
string[] s)
211 public bool Is(
int offset, params
char[] chars)
213 return chars.Any(x =>
Is(x, offset));
222 public bool Is(
int offset, params
string[] s)
224 return s.Any(x =>
Is(x, offset));
239 $
"Expected '{c}' but got '{(IsEof() ? "EOF
" : GetCurrentChar())}'",
257 if (!c.Any(x =>
Is(x)))
260 $
"Expected '{string.Join("' or '", c)}' but got '{(IsEof() ? "EOF
" : GetCurrentChar())}'",
280 for (
int i = 0; i < s.Length; i++)
285 $
"Expected '{s}' but got '{(IsEof() ? "EOF
" : GetCurrentChar())}'",
304 string? str = s.FirstOrDefault(x =>
Is(x));
309 $
"Expected '{string.Join("' or '", s)}' but got '{(IsEof() ? "EOF
" : GetCurrentChar())}'",
345 public void Seek(params
char[] c)
357 public void Seek(params
string[] s)
381 public void Skip(params
char[] c)
389 if (!c.Any(ch =>
Is(ch)))
Describes a specific position inside a source file.
static BadSourcePosition Create(string fileName, string source, int index, int length)
Creates a new Source Position.
Public interface for the filesystem abstraction of the BadScript Engine.
static string ReadAllText(this IFileSystem fileSystem, string path)
Gets Raised if the Reader encounters an Error.
Implements the Source Code Reader.
readonly string m_Source
The Source Code.
void Seek(params char[] c)
Skips over any character that is not equal to any of the specified characters.
void MoveNext()
Moves the Reader to the next character in the source code.
BadSourceReader(string fileName, string source, int start, int end)
Creates a new Source Code Reader.
bool Is(params char[] chars)
Returns true if any of the characters match the specified character.
bool Is(int offset, params string[] s)
Returns true if any of the strings match the specified String.
BadSourcePosition Eat(string s)
Asserts that the current String matches the specified String.
void SetPosition(int index)
Sets the Current Index of the Reader.
static BadSourceReader FromFile(string fileName)
Creates a new Source Code Reader from a File.
void Seek(params string[] s)
Skips over any character that is not equal to any of the specified strings.
bool Is(string s, int offset=0)
Returns true if the string matches the specified character.
void Skip(char c)
If the current character is equal to the specified character, it will be skipped.
char GetCurrentChar(int offset=0)
Returns the Current Character.
BadSourcePosition MakeSourcePosition(int length)
Creates a source position with the specified length and the current index of the reader.
void Seek(char c)
Skips over any character that is not equal to the specified character.
int CurrentIndex
The Current Index of the Reader.
void Seek(string s)
Skips over any string that is not equal to the specified string.
BadSourcePosition Eat(params char[] c)
Asserts that the current character matches one of the specified characters.
char CurrentChar
The Current Character of the Reader.
bool Is(params string[] s)
Returns true if any of the strings match the specified character.
BadSourcePosition Eat(params string[] s)
Asserts that the current string matches one of the specified strings.
void Skip(params char[] c)
If the current character is equal to any of the specified characters, it will be skipped.
string Source
The Source Code.
BadSourceReader(string fileName, string source)
Creates a new Source Code Reader.
bool IsEof(int offset=0)
Returns true if the reader is at the end of the source code.
string FileName
The Filename of the Source Code.
BadSourcePosition Eat(char c)
Asserts that the current character matches the specified character.
BadSourcePosition MakeSourcePosition(int index, int length)
Creates a source position with the specified length and index.
string Preview
Preview of the Source Code.
bool Is(int offset, params char[] chars)
Returns true if any of the characters match the specified character.
bool Is(char c, int offset=0)
Returns true if the current character matches the specified character.
readonly int m_StartIndex
Start Index of the Source Code.
Contains Shared Data Structures and Functionality.
Contains IO Implementation for the BadScript2 Runtime.
Contains the Source Reader for the BadScript2 Language.