2using System.Text.RegularExpressions;
41 return reader.
Is(c, offset) && !reader.IsWordChar(offset + 1);
46 return reader.
Is(s, offset) && !reader.IsWordChar(offset + s.Length);
74 return reader.IsDigit(offset) ||
146 reader.SkipToEndOfLine();
147 reader.SkipNewLine();
168 reader.SkipComment();
169 reader.SkipWhiteSpaceAndNewLine();
186 if (!reader.IsWordStart())
189 $
"Expected word start character but got '{(reader.IsEof() ? "EOF
" : reader.GetCurrentChar())}'",
197 while (reader.IsWordChar())
213 if (!reader.IsNumberStart())
216 $
"Expected number start character but got '{(reader.IsEof() ? "EOF
" : reader.GetCurrentChar())}'",
223 bool hasDecimal =
false;
265 $
"Expected boolean but got '{(reader.IsEof() ? "EOF
" : reader.GetCurrentChar())}'",
300 symbols.FirstOrDefault(x => x.All(c =>
char.IsLetter(c) || c ==
'_') ? reader.IsKey(x) : reader.
Is(x));
302 return symbol ==
null ? null : reader.TryParseSymbols(symbol);
316 if (!reader.IsStringQuote() && !reader.IsStringQuote(0,
true))
319 $
"Expected string start character but got '{(reader.IsEof() ? "EOF
" : reader.GetCurrentChar())}'",
327 bool isEscaped =
false;
328 StringBuilder sb =
new StringBuilder(
"\"");
330 while (!reader.IsStringQuote(0, singleQuote))
332 if (reader.IsNewLine() || reader.
IsEof())
335 "String not terminated",
349 sb.Append(Regex.Unescape($
"\\{reader.GetCurrentChar()}"));
377 StringBuilder sb =
new StringBuilder(
"\"");
379 while (!reader.IsStringQuote())
384 "String not terminated",
424 while (reader.IsWhiteSpace(index))
Contains Static Data for the BadScript Language.
const char ESCAPE_CHARACTER
const string MULTI_LINE_COMMENT_END
static readonly char[] Whitespace
static readonly char[] NewLine
const string SINGLE_LINE_COMMENT
const string MULTI_LINE_STRING_KEY
const char DECIMAL_SEPARATOR
const string MULTI_LINE_COMMENT_START
Gets Raised if the Reader encounters an Error.
Extensions for the Source Reader.
static bool IsDigit(this BadSourceReader reader, int offset=0)
Returns true if the Current Character is a Digit.
static bool Last(this BadSourceReader reader, char c)
Returns true if the last non-whitespace character is the specified character.
static void SkipWhiteSpaceAndNewLine(this BadSourceReader reader)
Skips all whitespace and newline characters.
static BadBooleanToken ParseBoolean(this BadSourceReader reader)
Parses a BadBoolean Token.
static BadStringToken ParseString(this BadSourceReader reader)
Parses a BadStringToken.
static bool IsNewLine(this BadSourceReader reader, int offset=0)
Returns true if the Current Character is a Newline Character.
static ? BadSymbolToken TryParseSymbols(this BadSourceReader reader, IEnumerable< string > symbols)
Tries to parse a list of symbols.
static bool IsKey(this BadSourceReader reader, string s, int offset=0)
static bool IsWordStart(this BadSourceReader reader, int offset=0)
Returns true if the Current Character of the Reader is a valid Word Start Character.
static void SkipNewLine(this BadSourceReader reader)
Skips all newline characters.
static void SkipWhiteSpace(this BadSourceReader reader)
Skips all whitespace characters.
static BadNumberToken ParseNumber(this BadSourceReader reader)
Parses a BadNumberToken.
static BadNullToken ParseNull(this BadSourceReader reader)
Parses a BadNullToken.
static bool IsWordChar(this BadSourceReader reader, int offset=0)
Returns true if the Current Character of the Reader is a valid Word Character.
static void SkipComment(this BadSourceReader reader)
Skips a comment.
static bool IsNumberStart(this BadSourceReader reader, int offset=0)
Returns true if the Current Character is a valid Number Character.
static void SkipToEndOfLine(this BadSourceReader reader)
Skips all characters untile a newline is found.
static BadStringToken ParseMultiLineString(this BadSourceReader reader)
Parses a Multi Line String.
static void SkipNonToken(this BadSourceReader reader)
Skips all whitespace, newline characters and comments.
static ? BadSymbolToken TryParseSymbols(this BadSourceReader reader, string symbols)
Tries to parse symbols.
static BadWordToken ParseWord(this BadSourceReader reader)
Parses a Word Token.
static bool IsWhiteSpace(this BadSourceReader reader, int offset=0)
Returns true if the Current Character is any whitespace or newline characters.
static bool IsStringQuote(this BadSourceReader reader, int offset=0, bool singleQuote=false)
Returns true if the Current Character is a String Quote Character.
static bool IsKey(this BadSourceReader reader, char c, int offset=0)
Implements the Source Code Reader.
void MoveNext()
Moves the Reader to the next character in the source code.
void SetPosition(int index)
Sets the Current Index of the Reader.
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.
bool IsEof(int offset=0)
Returns true if the reader is at the end of the source code.
BadSourcePosition Eat(char c)
Asserts that the current character matches the specified character.
bool Is(char c, int offset=0)
Returns true if the current character matches the specified character.
Implements a Symbol Token.
Implements a Token that represents a Boolean.
Implements a Token that represents a Number.
Implements a Token that represents a String.
Contains Shared Data Structures and Functionality.
Contains the Primitive Tokens for the BadScript2 Language.
Contains the Reader Tokens for the BadScript2 Language.
Contains the Source Reader for the BadScript2 Language.