29 lines
2.0 KiB
C#
29 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
using System.Text;
|
|
|
|
namespace ln.parse.tokenizer
|
|
{
|
|
public abstract class TokenMatcher
|
|
{
|
|
|
|
public TokenMatcher()
|
|
{
|
|
}
|
|
|
|
public abstract bool Match(SourceBuffer sourceBuffer, out Token token);
|
|
|
|
public static readonly TokenMatcher INTEGER = new RegularExpressionMatcher("^(?<value>-?\\d+)", (SourceBuffer sourceBuffer, int start, int length, string value) => new Token.IntegerToken(sourceBuffer, start, length, value));
|
|
public static readonly TokenMatcher FLOAT = new RegularExpressionMatcher("^(?<value>-?\\d+\\.\\d*)", (SourceBuffer sourceBuffer, int start, int length, string value) => new Token.FloatToken(sourceBuffer, start, length, value));
|
|
public static readonly TokenMatcher STRING = new RegularExpressionMatcher("^\\\"(?<value>(\\\\\"|.)*?)\\\"", (SourceBuffer sourceBuffer, int start, int length, string value) => new Token.StringToken(sourceBuffer, start, length, value));
|
|
public static readonly TokenMatcher IDENTIFIER = new RegularExpressionMatcher("^(?<value>[\\w][a-zA-Z0-9_]*)", (SourceBuffer sourceBuffer, int start, int length, string value) => new Token.IdentifierToken(sourceBuffer, start, length, value));
|
|
public static readonly TokenMatcher OPERATOR = new RegularExpressionMatcher("(?<value>\\+|\\-|\\*|\\/|\\||\\&|\\|\\||\\&\\&|\\;|\\:)", (SourceBuffer sourceBuffer, int start, int length, string value) => new Token.OperatorToken(sourceBuffer, start, length, value));
|
|
public static readonly TokenMatcher WHITESPACE = new RegularExpressionMatcher("^(?<value>\\s+)", (SourceBuffer sourceBuffer, int start, int length, string value) => new Token.WhiteSpaceToken(sourceBuffer, start, length, value));
|
|
public static readonly TokenMatcher BRACKET = new RegularExpressionMatcher("^(?<value>[(){}\\[\\]])", (SourceBuffer sourceBuffer, int start, int length, string value) => new Token.BracketToken(sourceBuffer, start, length, value));
|
|
|
|
}
|
|
|
|
}
|