175 lines
2.9 KiB
Plaintext
175 lines
2.9 KiB
Plaintext
%namespace Bts.BooleanExpressions
|
|
%scannertype BooleanExpressionScanner
|
|
%visibility internal
|
|
%tokentype Token
|
|
|
|
%option stack, minimize, parser, verbose, persistbuffer, noembedbuffers
|
|
|
|
/* Literal Constants */
|
|
Letter [a-zA-Z]
|
|
BooleanConstant 'true'|'false'
|
|
CSStringConstant \"([^\"\\]*|\\.)*\"
|
|
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]+
|
|
StringConstant \'([^\'\\]*|\\.)*\'
|
|
|
|
/* Relational Operators */
|
|
Equal =
|
|
LessEqual <=
|
|
GreaterEqual >=
|
|
Less <
|
|
Greater >
|
|
Different !=
|
|
Different2 <>
|
|
Matches ~=
|
|
|
|
/* Logical Operators */
|
|
Or or
|
|
And and
|
|
Not not
|
|
Xor xor
|
|
|
|
Define define
|
|
BeginDef \{
|
|
EndDef \}
|
|
|
|
Identifier {Letter}({Letter}*[0-9]*_*)*
|
|
|
|
/* Utility Tokens */
|
|
OpenParenthesis \(
|
|
CloseParenthesis \)
|
|
Comma ,
|
|
Negate '!'
|
|
MapsTo ':'
|
|
IsOfType '/'
|
|
|
|
%%
|
|
|
|
{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)Token.BOOLEAN_CONSTANT;
|
|
}
|
|
|
|
{StringConstant} {
|
|
yylval.String = yytext.Substring(1, yytext.Length - 2).Replace(@"\'", "'");
|
|
return (int)Token.STRING_CONSTANT;
|
|
}
|
|
|
|
{NullConstant} {
|
|
yylval.Null = DBNull.Value;
|
|
return (int)Token.NULL_CONSTANT;
|
|
}
|
|
|
|
{DateTimeConstant} {
|
|
yylval.DateTime = DateTime.Parse(yytext);
|
|
return (int)Token.DATE_TIME_CONSTANT;
|
|
}
|
|
|
|
{IntegerConstant} {
|
|
yylval.Integer = int.Parse(yytext);
|
|
return (int)Token.INTEGER_CONSTANT;
|
|
}
|
|
|
|
{RealConstant} {
|
|
yylval.Real = double.Parse(yytext);
|
|
return (int)Token.REAL_CONSTANT;
|
|
}
|
|
|
|
{OpenParenthesis} {
|
|
return (int)Token.PARENTHESIS_OPEN;
|
|
}
|
|
|
|
{CloseParenthesis} {
|
|
return (int)Token.PARENTHESIS_CLOSE;
|
|
}
|
|
|
|
{Comma} {
|
|
return (int)Token.COMMA;
|
|
}
|
|
|
|
{Negate} {
|
|
return (int)Token.NEGATE;
|
|
}
|
|
|
|
{MapsTo} {
|
|
return (int)Token.MAPS_TO;
|
|
}
|
|
|
|
{Equal} {
|
|
return (int)Token.EQUAL;
|
|
}
|
|
|
|
{LessEqual} {
|
|
return (int)Token.LESS_EQUAL;
|
|
}
|
|
|
|
{GreaterEqual} {
|
|
return (int)Token.GREATER_EQUAL;
|
|
}
|
|
|
|
{Less} {
|
|
return (int)Token.LESS;
|
|
}
|
|
|
|
{Greater} {
|
|
return (int)Token.GREATER;
|
|
}
|
|
|
|
{Different} {
|
|
return (int)Token.DIFFERENT;
|
|
}
|
|
|
|
{Different2} {
|
|
return (int)Token.DIFFERENT2;
|
|
}
|
|
|
|
{Matches} {
|
|
return (int)Token.MATCHES;
|
|
}
|
|
|
|
{Or} {
|
|
return (int)Token.OR;
|
|
}
|
|
|
|
{And} {
|
|
return (int)Token.AND;
|
|
}
|
|
|
|
{Not} {
|
|
return (int)Token.NOT;
|
|
}
|
|
|
|
{Xor} {
|
|
return (int)Token.XOR;
|
|
}
|
|
|
|
{IsOfType} {
|
|
return (int)Token.IS_OF_TYPE;
|
|
}
|
|
|
|
{Define} {
|
|
return (int)Token.DEFINE;
|
|
}
|
|
|
|
{BeginDef} {
|
|
return (int)Token.BEGIN_DEF;
|
|
}
|
|
|
|
{EndDef} {
|
|
return (int)Token.END_DEF;
|
|
}
|
|
|
|
{Identifier} {
|
|
yylval.Identifier = yytext;
|
|
return (int)Token.IDENTIFIER;
|
|
}
|
|
|
|
%%
|