86 lines
2.1 KiB
Plaintext
86 lines
2.1 KiB
Plaintext
%namespace Bts.ColumnExpressions
|
|
%scannertype ColumnExpressionScanner
|
|
%visibility internal
|
|
%tokentype ColumnExpressionToken
|
|
|
|
%option stack, minimize, parser, verbose, persistbuffer, noembedbuffers
|
|
|
|
/* Literal Constants */
|
|
Letter [a-zA-Z]
|
|
BooleanConstant true|false
|
|
StringConstant '([^\'\\]*|\\.)*'
|
|
DateTimeConstant ([1-9]|'10'|'11'|'12')\/([1-9]|([1-2][0-9])|'30'|'31')\/[0-9][0-9][0-9]*
|
|
IntegerConstant -?[0-9]+
|
|
NullConstant 'null'
|
|
RealConstant -?[0-9]+\.[0-9]+
|
|
|
|
/* Relational Operators */
|
|
Equals =
|
|
OfType /
|
|
|
|
Identifier {Letter}({Letter}*[0-9]*_*)*
|
|
NamespacePrefix {Identifier}\.
|
|
TypeId {NamespacePrefix}*{Identifier}
|
|
|
|
/* Utility Tokens */
|
|
OpenParenthesis \(
|
|
CloseParenthesis \)
|
|
Comma ,
|
|
QuoteOpen \[
|
|
QuoteClose \]
|
|
|
|
/* Comments */
|
|
LineComment \/\/[^\n\r]*(\n|\r|\r\n)
|
|
|
|
%%
|
|
|
|
{Equals} {
|
|
return (int)ColumnExpressionToken.EQUALS;
|
|
}
|
|
|
|
{OfType} {
|
|
return (int)ColumnExpressionToken.OF_TYPE;
|
|
}
|
|
|
|
{StringConstant} {
|
|
yylval.String = yytext.Substring(1, yytext.Length - 2).Replace(@"\'","'");
|
|
return (int)ColumnExpressionToken.STRING_CONSTANT;
|
|
}
|
|
|
|
{BooleanConstant} {
|
|
yylval.Boolean = yytext.ToLower() switch {
|
|
"true" => true,
|
|
"false" => false,
|
|
_ => throw new Exception(
|
|
string.Format("Expected yytext to be 'true' or 'false' (actually '{0}')", yytext))
|
|
};
|
|
return (int)ColumnExpressionToken.BOOLEAN_CONSTANT;
|
|
}
|
|
|
|
{DateTimeConstant} {
|
|
yylval.DateTime = DateTime.Parse(yytext);
|
|
return (int)ColumnExpressionToken.DATE_TIME_CONSTANT;
|
|
}
|
|
|
|
{IntegerConstant} {
|
|
yylval.Integer = int.Parse(yytext);
|
|
return (int)ColumnExpressionToken.INTEGER_CONSTANT;
|
|
}
|
|
|
|
{RealConstant} {
|
|
yylval.Real = double.Parse(yytext);
|
|
return (int)ColumnExpressionToken.REAL_CONSTANT;
|
|
}
|
|
|
|
{Identifier} {
|
|
yylval.Identifier = yytext;
|
|
return (int)ColumnExpressionToken.IDENTIFIER;
|
|
}
|
|
|
|
{TypeId} {
|
|
yylval.TypeId = yytext;
|
|
return (int)ColumnExpressionToken.TYPE_ID;
|
|
}
|
|
|
|
%%
|