irods
4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems. Fossies Dox: irods-4.2.8.tar.gz ("unofficial" and yet experimental doxygen-generated source code documentation) 
|
Go to the documentation of this file.
32 {
"not like regex", 2, 4},
104 char *
keywords[
nKeywords] = {
"in",
"let",
"match",
"with",
"for",
"forExec",
"while",
"whileExec",
"foreach",
"forEachExec",
"if",
"ifExec",
"then",
"else",
"data",
"constructor",
"on",
"or",
"oron"};
108 if ( strcmp(
keywords[i], text ) == 0 ) {
118 while ( ch != -1 && ( ch ==
' ' || ch ==
'\t' || ch ==
'\r' || ch ==
'\n' ) ) {
124 while ( ch !=
'\n' && ch != -1 ) {
129 char *
e = expr + strlen( expr );
130 while (
e != expr ) {
132 if ( *
e ==
' ' || *
e ==
'\t' || *
e ==
'\r' || *
e ==
'\n' ) {
135 if ( *
e ==
'\\' || *
e ==
',' || *
e ==
';' || *
e ==
'|' || *
e ==
'#' ) {
149 if ( ( ( *token )->type !=
TK_TEXT && ( *token )->type !=
TK_OP && ( *token )->type !=
TK_MISC_OP ) || strcmp( ( *token )->text, text ) != 0 ) {
161 if ( context->
tqp != context->
tqtop ) {
188 if ( ch ==
'{' || ch ==
'}' || ch ==
'[' || ch ==
']' || ch ==
'(' || ch ==
')' || ch ==
',' || ch ==
'@' || ( ch ==
'|' && ( !rulegen ||
lookAhead(
e, 1 ) !=
'|' ) ) || ch ==
';' || ch ==
'?' ) {
195 else if ( ch ==
'#' ) {
210 else if ( ch ==
'-' || ch ==
'=' ) {
221 else if ( ch ==
':' ) {
240 else if ( ch ==
'*' || ch ==
'$' ) {
244 if ( ch ==
'_' || isalpha( ch ) ) {
246 while ( ch ==
'_' || isalnum( ch ) ) {
257 else if ( pathLiteral && ch ==
'/' ) {
266 for ( i = 0; i <
num_ops; i++ ) {
267 int len = strlen(
new_ops[i].
string );
268 if ( strncmp(
op,
new_ops[i].
string, len ) == 0 &&
269 ( !isalpha(
new_ops[i].
string[0] )
270 || !isalnum(
op[len] ) ) ) {
281 if ( isdigit( ch ) || ch ==
'.' ) {
283 while ( isdigit( ch ) || ch ==
'.' ) {
295 else if ( ch ==
'_' || isalpha( ch ) || ch ==
'~' ) {
297 while ( ch ==
'_' || isalnum( ch ) ) {
304 else if ( ch ==
'\"' ) {
312 else if ( ch ==
'\'' ) {
320 else if ( ch ==
'`' ) {
356 if ( context->
tqp == context->
tqtop ) {
365 return ch ==
'\n' || ch ==
'\r';
407 TTEXT(
"constructor" );
436 if ( strcmp( rk, "FUNC" ) == 0 ) {
437 BUILD_NODE( TK_BOOL, "true", FPOS, 0, 0 );
440 OPTIONAL_BEGIN( semicolon )
442 OPTIONAL_END( semicolon )
443 BUILD_NODE( N_RULE, "RULE
", &start, 5, 5 );
444 BUILD_NODE( N_RULE_PACK, rk, &start, 1, 1 );
445 /* } else if(PARSER_LAZY) {
446 char buf[MAX_RULE_LEN];
448 getRuleCode(buf, e, rulegen, context);
449 BUILD_NODE(N_RULE_CODE, buf, &rcpos, 0, 0);
450 BUILD_NODE(N_UNPARSED,"UNPARSED
", &start,2, 2);
451 BUILD_NODE(N_RULE_PACK,rk, &start,1, 1); */
453 else if ( rulegen ) {
454 int numberOfRules = 0;
465 END_TRY( rulePackCond )
466 NT2( Term, 1, MIN_PREC );
468 NT2( Actions, 1, 0 );
471 BUILD_NODE( N_RULE, "RULE
", &start, 5, 4 );
475 TRY( rulePackUncond )
479 END_TRY( rulePackUncond )
480 BUILD_NODE( TK_BOOL, "true", FPOS, 0, 0 );
482 NT2( Actions, 1, 0 );
485 BUILD_NODE( N_RULE, "RULE
", &start, 5, 4 );
489 ABORT( numberOfRules == 0 );
493 ABORT( numberOfRules != 0 );
494 BUILD_NODE( TK_BOOL, "true", FPOS, 0, 0 );
495 NT2( Actions, 1, 0 );
499 BUILD_NODE( N_RULE, "RULE
", &start, 5, 4 );
505 BUILD_NODE( N_RULE_PACK, rk, &start, numberOfRules, numberOfRules );
510 /* empty condition */
512 BUILD_NODE( TK_BOOL, "true", FPOS, 0, 0 );
514 if ( backwardCompatible >= 0 ) {
515 NT1( ExprBackwardCompatible, 0 );
518 NT2( Term, 0, MIN_PREC );
521 BUILD_NODE( N_TUPLE, TUPLE, &pos, 1, 1 );
525 NT2( Actions, 0, backwardCompatible >= 0 ? 1 : 0 );
527 NT2( Actions, 0, backwardCompatible >= 0 ? 1 : 0 );
529 Label metadataStart = *FPOS;
530 OPTIONAL_BEGIN( ruleId )
533 BUILD_NODE( TK_STRING, "id", &pos, 0, 0 );
534 BUILD_NODE( TK_STRING, token->text, &pos, 0, 0 );
535 BUILD_NODE( TK_STRING, "", &pos, 0, 0 );
536 BUILD_NODE( N_AVU, AVU, &pos, 3, 3 );
538 OPTIONAL_END( ruleId )
539 BUILD_NODE( N_META_DATA, META_DATA, &metadataStart, n, n );
540 BUILD_NODE( N_RULE, "RULE
", &start, 5, 5 );
541 BUILD_NODE( N_RULE_PACK, rk, &start, 1, 1 );
545 BUILD_NODE(TK_VAR, token->text, &pos, 0, 0);
547 NT2(Term, 0, MIN_PREC);
548 BUILD_NODE(N_RULE_PACK, "GLOBAL
", &start, 2, 2);*/
550 PARSER_FUNC_END( Rule )
552 PARSER_FUNC_BEGIN( RuleName )
555 char *ruleName = cpStringExt( token->text, context->region );
556 Label paramListStart = *FPOS;
561 NT2( Term, rulegen, MIN_PREC );
563 CHOICE_BEGIN( paramType )
564 BRANCH_BEGIN( paramType )
567 BRANCH_END( paramType )
568 BRANCH_BEGIN( paramType )
569 BUILD_NODE( T_UNSPECED, NULL, FPOS, 0, 0 );
570 BRANCH_END( paramType )
571 CHOICE_END( paramType )
572 CHOICE_BEGIN( paramDelim )
573 BRANCH_BEGIN( paramDelim )
575 BRANCH_END( paramDelim )
576 BRANCH_BEGIN( paramDelim )
579 BRANCH_END( paramDelim )
580 CHOICE_END( paramDelim )
583 BUILD_NODE( N_PARAM_TYPE_LIST, "paramTypelist
", ¶mListStart, n, n );
585 BUILD_NODE( N_PARAM_LIST, "paramlist
", ¶mListStart, n, n );
588 OPTIONAL_BEGIN( epl )
592 BUILD_NODE( N_PARAM_LIST, "paramlist
", ¶mListStart, 0, 0 );
593 BUILD_NODE( N_PARAM_TYPE_LIST, "paramTypelist
", ¶mListStart, 0, 0 );
600 BUILD_NODE( T_UNSPECED, NULL, FPOS, 0, 0 );
602 BUILD_NODE( N_RULE_NAME, ruleName, &start, 3, 3 );
603 PARSER_FUNC_END( RuleName )
605 PARSER_FUNC_BEGIN( Metadata )
608 LOOP_BEGIN( metadata )
613 BUILD_NODE( TK_STRING, token->text, &pos, 0, 0 );
616 BUILD_NODE( TK_STRING, token->text, &pos, 0, 0 );
620 BUILD_NODE( TK_STRING, token->text, &pos, 0, 0 );
624 BUILD_NODE( TK_STRING, "", &pos, 0, 0 );
626 BUILD_NODE( N_AVU, AVU, &pos, 3, 3 );
632 BUILD_NODE( N_META_DATA, META_DATA, &start, n, n );
633 PARSER_FUNC_END( Metadata )
636 PARSER_FUNC_BEGIN( FuncExpr )
638 NT2( Term, 1, MIN_PREC );
642 NT2( Term, 1, MIN_PREC );
645 BUILD_APP_NODE( "nop", FPOS, 0 );
648 PARSER_FUNC_END( FuncExpr )
650 PARSER_FUNC_BEGIN2( Actions, int rulegen, int backwardCompatible )
653 ABORT( backwardCompatible );
654 TTEXT_LOOKAHEAD( "}
" );
656 LOOP_BEGIN( actions );
657 if ( !backwardCompatible ) {
658 NT2( Term, rulegen, MIN_PREC );
661 NT( TermBackwardCompatible );
667 NT2( Term, rulegen, MIN_PREC );
670 BUILD_APP_NODE( "nop", NULL, 0 );
676 OPTIONAL_BEGIN( actionSemiColon )
678 OPTIONAL_END( actionSemiColon )
679 OPTIONAL_BEGIN( actionSemiColonBrace )
680 TTEXT_LOOKAHEAD( "}
" );
682 OPTIONAL_END( actionSemiColonBrace )
685 CHOICE_BEGIN( actionDelim )
686 BRANCH_BEGIN( actionDelim )
688 BRANCH_END( actionDelim )
689 BRANCH_BEGIN( actionDelim )
691 BRANCH_END( actionDelim )
692 CHOICE_END( actionDelim )
699 BUILD_NODE( N_ACTIONS, "ACTIONS
", &start, n, n );
702 BUILD_NODE( N_ACTIONS, "ACTIONS
", &start, n, n );
705 PARSER_FUNC_END( Actions )
707 PARSER_FUNC_BEGIN( ActionsToStrings )
710 #define bufferSize 10000
711 char actiBuffer[bufferSize], recoBuffer[bufferSize];
712 int actiP = 0, recoP = 0;
714 memset( &start, 0, sizeof( start ) );
715 memset( &finish, 0, sizeof( finish ) );
717 TTEXT_LOOKAHEAD( "}
" );
719 LOOP_BEGIN( actions );
721 NT2( Term, rulegen, MIN_PREC );
724 ABORT( actiP + finish.exprloc - start.exprloc + 1 >= bufferSize );
725 dupString( e, &start, finish.exprloc - start.exprloc, actiBuffer + actiP );
726 actiP += finish.exprloc - start.exprloc;
727 actiBuffer[actiP++] = ';';
733 NT2( Term, rulegen, MIN_PREC );
736 ABORT( finish.exprloc - start.exprloc + 1 + recoP >= bufferSize );
737 dupString( e, &start, finish.exprloc - start.exprloc, recoBuffer + recoP );
738 recoP += finish.exprloc - start.exprloc;
739 recoBuffer[actiP++] = ';';
742 ABORT( recoP + 4 >= bufferSize );
743 strcpy( recoBuffer + recoP, "nop;
" );
750 OPTIONAL_BEGIN( actionSemiColon )
752 OPTIONAL_END( actionSemiColon )
753 OPTIONAL_BEGIN( actionSemiColonBrace )
754 TTEXT_LOOKAHEAD( "}
" );
756 OPTIONAL_END( actionSemiColonBrace )
759 CHOICE_BEGIN( actionDelim )
760 BRANCH_BEGIN( actionDelim )
762 BRANCH_END( actionDelim )
763 BRANCH_BEGIN( actionDelim )
765 BRANCH_END( actionDelim )
766 CHOICE_END( actionDelim )
770 actiBuffer[actiP] = recoBuffer[recoP] = '\0';
771 BUILD_NODE( TK_STRING, actiBuffer, &start, 0, 0 );
772 BUILD_NODE( TK_STRING, recoBuffer, &start, 0, 0 );
773 PARSER_FUNC_END( ActionsToStrings )
775 PARSER_FUNC_BEGIN1( TermSystemBackwardCompatible, int level )
781 NT1( ExprBackwardCompatible, 0 );
784 NT2( Term, 0, MIN_PREC );
787 NT2( Actions, 0, level );
789 NT2( Actions, 0, level );
791 NT2( Actions, 0, level );
793 NT2( Actions, 0, level );
795 BUILD_APP_NODE( "if", &start, 5 );
797 TTEXT( "whileExec
" );
800 NT1( ExprBackwardCompatible, 0 );
803 NT2( Term, 0, MIN_PREC );
806 NT2( Actions, 0, level );
808 NT2( Actions, 0, level );
810 BUILD_APP_NODE( "while", &start, 3 );
812 TTEXT( "forEachExec
" );
814 TTYPE( TK_LOCAL_VAR );
815 BUILD_NODE( TK_VAR, token->text, &start, 0, 0 );
817 NT2( Actions, 0, level );
819 NT2( Actions, 0, level );
821 BUILD_APP_NODE( "foreach", &start, 3 );
826 TTYPE( TK_LOCAL_VAR );
827 BUILD_NODE( TK_VAR, token->text, &pos, 0, 0 );
831 NT1( ExprBackwardCompatible, 1 );
833 NT( ActionArgumentBackwardCompatible );
837 NT2( Term, 0, MIN_PREC );
841 BUILD_APP_NODE( "assignStr
", &start, 2 );
844 BUILD_APP_NODE( "assign
", &start, 2 );
849 NT2( Term, 0, MIN_PREC );
851 NT2( Term, 0, MIN_PREC );
853 NT2( Term, 0, MIN_PREC );
855 NT2( Actions, 0, level );
857 NT2( Actions, 0, level );
859 BUILD_APP_NODE( "for", &start, 5 );
861 TTEXT( "breakExec
" );
862 BUILD_APP_NODE( "break", &start, 0 );
866 NT( ActionArgumentBackwardCompatible )
869 nextActionArgumentStringBackwardCompatible( e, &strtoken );
870 if ( strtoken.type != TK_STRING ) {
871 BUILD_NODE( N_ERROR, "reached the
end of stream
while parsing an
action argument
", FPOS, 0, 0 );
874 BUILD_NODE( TK_STRING, strtoken.text, &pos, 0, 0 );
877 nextActionArgumentStringBackwardCompatible( e, &strtoken );
878 if ( strtoken.type != TK_STRING ) {
879 BUILD_NODE( N_ERROR, "reached the
end of stream
while parsing an
action argument
", FPOS, 0, 0 );
882 BUILD_NODE( TK_STRING, strtoken.text, &pos, 0, 0 );
885 BUILD_APP_NODE( "delayExec", &start, 3 );
890 NT( ActionArgumentBackwardCompatible )TTEXT( ",
" );
891 NT( ActionArgumentBackwardCompatible )TTEXT( ",
" );
893 nextActionArgumentStringBackwardCompatible( e, &strtoken );
894 if ( strtoken.type != TK_STRING ) {
895 BUILD_NODE( N_ERROR, "reached the
end of stream
while parsing an
action argument
", FPOS, 0, 0 );
898 BUILD_NODE( TK_STRING, strtoken.text, &pos, 0, 0 );
901 nextActionArgumentStringBackwardCompatible( e, &strtoken );
902 if ( strtoken.type != TK_STRING ) {
903 BUILD_NODE( N_ERROR, "reached the
end of stream
while parsing an
action argument
", FPOS, 0, 0 );
906 BUILD_NODE( TK_STRING, strtoken.text, &pos, 0, 0 );
911 PARSER_FUNC_END( TermSystemBackwardCompatible )
913 PARSER_FUNC_BEGIN1( ExprBackwardCompatible, int level )
917 NT( TermBackwardCompatible );
920 NT1( ExprBackwardCompatible, level );
925 OPTIONAL_BEGIN( term2 )
927 char *fn = cpStringExt( token->text, context->region );
928 ABORT( !isBinaryOp( token ) );
929 if ( TOKEN_TEXT( "like
" ) || TOKEN_TEXT( "not like
" ) || TOKEN_TEXT( "==
" ) || TOKEN_TEXT( "!=
" ) ) {
930 BUILD_APP_NODE( "str
", FPOS, 1 );
931 NT( ActionArgumentBackwardCompatible );
933 else if ( TOKEN_TEXT( "+
" ) || TOKEN_TEXT( "-
" ) || TOKEN_TEXT( "*
" ) || TOKEN_TEXT( "/
" ) || TOKEN_TEXT( "<
" ) || TOKEN_TEXT( "<=
" ) || TOKEN_TEXT( ">
" ) || TOKEN_TEXT( ">=
" ) ) {
934 BUILD_APP_NODE( "double", FPOS, 1 );
935 NT1( ExprBackwardCompatible, 1 );
936 BUILD_APP_NODE( "double", FPOS, 1 );
938 else if ( TOKEN_TEXT( "%%
" ) || TOKEN_TEXT( "&&
" ) ) {
939 BUILD_APP_NODE( "bool", FPOS, 1 );
940 NT1( ExprBackwardCompatible, 1 );
941 BUILD_APP_NODE( "bool", FPOS, 1 );
944 BUILD_APP_NODE( "str
", FPOS, 1 );
945 NT1( ExprBackwardCompatible, 1 );
946 BUILD_APP_NODE( "str
", FPOS, 1 );
948 BUILD_APP_NODE( fn, &start, 2 );
949 OPTIONAL_END( term2 )
950 PARSER_FUNC_END( ExprBackwardCompatible )
952 PARSER_FUNC_BEGIN( TermBackwardCompatible )
955 NT1( TermSystemBackwardCompatible, 1 );
959 char *fn = cpStringExt( token->text, context->region );
962 BUILD_APP_NODE( fn, &start, 0 );
966 char *fn = cpStringExt( token->text, context->region );
970 NT( ActionArgumentBackwardCompatible );
972 CHOICE_BEGIN( paramDelim )
973 BRANCH_BEGIN( paramDelim )
975 BRANCH_END( paramDelim )
976 BRANCH_BEGIN( paramDelim )
979 BRANCH_END( paramDelim )
980 CHOICE_END( paramDelim )
982 BUILD_APP_NODE( fn, &start, n );
985 char *fn = cpStringExt( token->text, context->region );
986 BUILD_APP_NODE( fn, &start, 0 );
990 PARSER_FUNC_END( ValueBackwardCompatible )
993 PARSER_FUNC_BEGIN( ActionArgumentBackwardCompatible )
998 TTYPE( TK_LOCAL_VAR );
999 char *vn = cpStringExt( token->text, context->region );
1000 TTEXT3( ",
", "|
", ")
" );
1002 BUILD_NODE( TK_VAR, vn, &vpos, 0, 0 );
1004 syncTokenQueue( e, context );
1006 nextActionArgumentStringBackwardCompatible( e, &strtoken );
1007 if ( strtoken.type != TK_STRING ) {
1008 BUILD_NODE( N_ERROR, "reached the
end of stream
while parsing an
action argument
", FPOS, 0, 0 );
1011 NT1( StringExpression, &strtoken );
1014 PARSER_FUNC_END( ActionArgumentBackwardCompatible )
1016 PARSER_FUNC_BEGIN2( Term, int rulegen, int prec )
1019 TTEXT2( "SELECT
", "select
" );
1020 LOOP_BEGIN( columns )
1027 END_TRY( columnDelim )
1029 OPTIONAL_BEGIN( where )
1030 TTEXT2( "WHERE
", "where
" );
1031 LOOP_BEGIN( queryConds )
1034 TRY( queryCondDelim )
1035 TTEXT2( "AND
", "and
" );
1036 OR( queryCondDelim )
1038 END_TRY( queryCondDelim )
1039 LOOP_END( queryConds )
1040 OPTIONAL_END( where )
1041 BUILD_NODE( N_QUERY, "QUERY
", &start, n, n );
1042 BUILD_APP_NODE( "query
", &start, 1 );
1049 NT2( Term, 1, MIN_PREC );
1051 OPTIONAL_BEGIN( ifThen )
1053 OPTIONAL_END( ifThen )
1055 NT2( Actions, 1, 0 );
1059 TTEXT_LOOKAHEAD( "if" );
1060 NT2( Term, 1, MIN_PREC );
1061 BUILD_NODE( N_ACTIONS, "ACTIONS
", &pos, 1, 1 );
1062 BUILD_APP_NODE( "nop", FPOS, 0 );
1063 BUILD_NODE( N_ACTIONS, "ACTIONS
", FPOS, 1, 1 );
1067 NT2( Actions, 1, 0 );
1070 BUILD_APP_NODE( "nop", FPOS, 0 );
1071 BUILD_NODE( N_ACTIONS, "ACTIONS
", FPOS, 1, 1 );
1072 BUILD_APP_NODE( "nop", FPOS, 0 );
1073 BUILD_NODE( N_ACTIONS, "ACTIONS
", FPOS, 1, 1 );
1076 BUILD_APP_NODE( "if", &start, 5 );
1079 NT2( Term, rulegen, MIN_PREC );
1081 NT2( Term, 1, MIN_PREC );
1082 BUILD_APP_NODE( "nop", FPOS, 0 );
1084 NT2( Term, 1, MIN_PREC );
1085 BUILD_APP_NODE( "nop", FPOS, 0 );
1087 BUILD_APP_NODE( "if2
", &start, 5 );
1094 TTEXT( "whileExec
" );
1097 NT2( Term, 1, MIN_PREC );
1100 NT2( Actions, 1, 0 );
1102 BUILD_APP_NODE( "while", &start, 3 );
1108 TTEXT( "forEachExec
" );
1111 TTYPE( TK_LOCAL_VAR );
1112 BUILD_NODE( TK_VAR, token->text, &pos, 0, 0 );
1116 NT2( Actions, 1, 0 );
1118 BUILD_APP_NODE( "foreach", &start, 3 );
1121 NT2( Term, 1, MIN_PREC );
1124 NT2( Actions, 1, 0 ); TTEXT( "}
" );
1125 BUILD_APP_NODE( "foreach2", &start, 4 ); END_TRY( foreach2 )
1134 NT2( Term, 1, MIN_PREC );
1136 NT2( Term, 1, MIN_PREC );
1138 NT2( Term, 1, MIN_PREC );
1141 NT2( Actions, 1, 0 );
1143 BUILD_APP_NODE( "for", &start, 5 );
1148 NT2( Term, 1, MIN_PREC );
1150 NT2( Term, 1, MIN_PREC );
1154 Label actionsStart = *FPOS;
1155 NT2( Actions, 1, 0 );
1158 Label actionsFinish = *FPOS;
1160 dupString( e, &actionsStart, actionsFinish.exprloc - actionsStart.exprloc, buf );
1161 BUILD_NODE( TK_STRING, buf, &actionsStart, 0, 0 );
1162 BUILD_NODE( TK_STRING, "", &actionsFinish, 0, 0 );
1168 NT2( Term, 1, MIN_PREC );
1172 Label actionsStart = *FPOS;
1173 NT2( Actions, 1, 0 );
1176 Label actionsFinish = *FPOS;
1178 dupString( e, &actionsStart, actionsFinish.exprloc - actionsStart.exprloc, buf );
1179 BUILD_NODE( TK_STRING, buf, &actionsStart, 0, 0 );
1180 BUILD_NODE( TK_STRING, "", &actionsFinish, 0, 0 );
1181 BUILD_APP_NODE( "delayExec", &start, 3 );
1187 NT2( Term, 1, MIN_PREC );
1189 NT2( Term, 1, MIN_PREC );
1190 BUILD_APP_NODE( "let
", &start, 3 );
1197 OPTIONAL_BEGIN( semicolon )
1199 OPTIONAL_END( semicolon )
1202 NT2( Term, 1, MIN_PREC );
1204 NT2( Term, 1, MIN_PREC );
1205 BUILD_NODE( N_TUPLE, TUPLE, &cpos, 2, 2 );
1213 BUILD_APP_NODE( "match", &start, n + 1 );
1216 NT1( Value, rulegen );
1218 while ( !done && NO_SYNTAX_ERROR ) {
1219 CHOICE_BEGIN( term )
1220 BRANCH_BEGIN( term )
1222 ABORT( !isBinaryOp( token ) );
1223 if ( prec >= getBinaryPrecedence( token ) ) {
1229 if ( TOKEN_TEXT( "=
" ) ) {
1235 NT2( Term, rulegen, getBinaryPrecedence( token ) );
1236 #ifdef DEBUG_VERBOSE
1238 generateErrMsg( fn, FPOS->exprloc, "ftest
", err );
1239 printf( "%s
", err );
1241 BUILD_APP_NODE( fn, &start, 2 );
1245 BRANCH_BEGIN( term )
1246 TRY( syntacticalArg )
1247 TTEXT_LOOKAHEAD( "(
" );
1248 OR( syntacticalArg )
1249 TTEXT_LOOKAHEAD( "[
" );
1250 END_TRY( syntacticalArg )
1253 strcpy( appToken.text, "@
@" );
1254 NT2( Term, rulegen, getBinaryPrecedence( &appToken ) );
1255 BUILD_NODE( N_APPLICATION, APPLICATION, &start, 2, 2 );
1257 BRANCH_BEGIN( term )
1266 OPTIONAL_BEGIN(typeascription)
1269 BUILD_NODE( N_EXTERN_DEF, "EXTERN
", &start, 2, 2 );
1270 OPTIONAL_END(typeascription)
1271 PARSER_FUNC_END( Term )
1273 PARSER_FUNC_BEGIN1( StringExpression, Token *tk )
1275 Token *strToken = NULL;
1285 long startLoc = strToken->exprloc;
1286 char *str = strToken->text;
1291 end[0] = strlen( str );
1292 while ( strToken->vars[i] != -1 ) {
1293 /* this string contains reference to vars */
1294 int vs = strToken->vars[i];
1296 if ( !isalpha( str[vs + 1] ) && str[vs + 1] != '_' ) {
1301 while ( isalnum( str[ve] ) || str[ve] == '_' ) {
1304 end[noi] = end[noi - 1];
1309 char sbuf[MAX_RULE_LEN];
1312 strncpy( sbuf, str + st[0], end[0] - st[0] );
1313 strcpy( sbuf + end[0] - st[0], delim );
1314 pos.exprloc = startLoc + st[0];
1315 int startloc = pos.exprloc;
1316 BUILD_NODE( TK_STRING, sbuf, &pos, 0, 0 );
1319 strncpy( sbuf, str + end[k - 1], st[k] - end[k - 1] ); /* var */
1320 strcpy( sbuf + st[k] - end[k - 1], delim );
1321 pos.exprloc = startLoc + end[k - 1];
1322 BUILD_NODE( TK_VAR, sbuf, &pos, 0, 0 );
1324 BUILD_APP_NODE( "str
", &pos, 1 );
1326 pos.exprloc = startloc;
1327 BUILD_APP_NODE( "++
", &pos, 2 );
1329 strncpy( sbuf, str + st[k], end[k] - st[k] );
1330 strcpy( sbuf + end[k] - st[k], delim );
1331 pos.exprloc = startLoc + st[k];
1332 BUILD_NODE( TK_STRING, sbuf, &pos, 0, 0 );
1334 pos.exprloc = startloc;
1335 BUILD_APP_NODE( "++
", &pos, 2 );
1338 PARSER_FUNC_END( StringExpression )
1340 PARSER_FUNC_BEGIN( PathExpression )
1346 /* need to reparse */
1348 syncTokenQueue( e, context );
1351 NT1( StringExpression, token );
1352 BUILD_APP_NODE( "path
", &start, 1 );
1353 PARSER_FUNC_END( PathExpression )
1355 PARSER_FUNC_BEGIN1( T, int rulegen )
1357 TTYPE( TK_LOCAL_VAR );
1358 BUILD_NODE( TK_VAR, token->text, &pos, 0, 0 );
1360 TTYPE( TK_SESSION_VAR );
1361 BUILD_NODE( TK_VAR, token->text, &pos, 0, 0 );
1364 BUILD_NODE( TK_INT, token->text, &start, 0, 0 );
1367 BUILD_NODE( TK_DOUBLE, token->text, &start, 0, 0 );
1369 PARSER_FUNC_END( T )
1371 PARSER_FUNC_BEGIN1( Value, int rulegen )
1375 TTEXT2( "true", "false" );
1376 BUILD_NODE( TK_BOOL, token->text, &pos, 0, 0 );
1381 BUILD_NODE( N_TUPLE, TUPLE, &start, 0, 0 );
1383 NT2( Term, rulegen, MIN_PREC );
1385 LOOP_BEGIN( tupleLoop )
1388 NT2( Term, rulegen, MIN_PREC );
1393 END_TRY( tupleComp )
1394 LOOP_END( tupleLoop )
1395 BUILD_NODE( N_TUPLE, TUPLE, &start, n, n );
1402 NT2( Actions, rulegen, 0 );
1404 BUILD_NODE( N_ACTIONS_RECOVERY, "ACTIONS_RECOVERY
", &start, 2, 2 );
1410 ABORT( !isUnaryOp( token ) );
1411 NT2( Term, rulegen, getUnaryPrecedence( token ) );
1413 if ( strcmp( token->text, "-
" ) == 0 ) {
1419 BUILD_APP_NODE( fn, &start, 1 );
1422 NT( PathExpression );
1426 NT1( TermSystemBackwardCompatible, 0 );
1429 ABORT( rulegen && isKeyword( token->text ) );
1430 char *fn = cpStringExt( token->text, context->region );
1431 BUILD_NODE( TK_TEXT, fn, &start, 0, 0 );
1432 #ifdef DEBUG_VERBOSE
1434 generateErrMsg( fn, start.exprloc, start.base, err );
1435 printf( "%s, %ld\n
", err, start.exprloc );
1438 TTEXT_LOOKAHEAD( "(
" );
1440 TTEXT_LOOKAHEAD( "[
" );
1443 BUILD_APP_NODE( n->text, &start, 0 );
1447 NT1( StringExpression, NULL );
1449 PARSER_FUNC_END( Value )
1451 PARSER_FUNC_BEGIN( Column )
1455 Label colFuncStart = *FPOS;
1456 char *columnFunc = NULL;
1458 TTEXT2( "count
", "COUNT
" );
1459 columnFunc = "count
";
1461 TTEXT2( "sum
", "SUM
" );
1464 TTEXT2( "order_desc
", "ORDER_DESC
" );
1465 columnFunc = "order_desc
";
1467 TTEXT2( "order_asc
", "ORDER_ASC
" );
1468 columnFunc = "order
";
1470 TTEXT2( "order
", "ORDER
" );
1471 columnFunc = "order
";
1472 END_TRY( columnFunc )
1474 Label colStart = *FPOS;
1476 BUILD_NODE( TK_COL, token->text, &colStart, 0, 0 );
1478 BUILD_NODE( N_ATTR, columnFunc, &colFuncStart, 1, 1 );
1480 Label colStart = *FPOS;
1482 BUILD_NODE( TK_COL, token->text, &colStart, 0, 0 );
1483 BUILD_NODE( N_ATTR, "", &colStart, 1, 1 );
1485 PARSER_FUNC_END( Column )
1487 PARSER_FUNC_BEGIN( QueryCond )
1494 LOOP_BEGIN( Junction )
1497 TTEXT2( "=
", "==
" );
1499 BUILD_NODE( N_QUERY_COND, "=
", &l, 1, 1 );
1501 TTEXT2( "<>
", "!=
" );
1503 BUILD_NODE( N_QUERY_COND, "<>
", &l, 1, 1 );
1507 BUILD_NODE( N_QUERY_COND, ">
", &l, 1, 1 );
1511 BUILD_NODE( N_QUERY_COND, "<
", &l, 1, 1 );
1515 BUILD_NODE( N_QUERY_COND, ">=
", &l, 1, 1 );
1519 BUILD_NODE( N_QUERY_COND, "<=
", &l, 1, 1 );
1521 TTEXT2( "in
", "IN
" );
1523 BUILD_NODE( N_QUERY_COND, "in
", &l, 1, 1 );
1525 TTEXT2( "between
", "BETWEEN
" );
1528 BUILD_NODE( N_QUERY_COND, "between
", &l, 2, 2 );
1530 TTEXT2( "like
", "LIKE
" );
1532 BUILD_NODE( N_QUERY_COND, "like
", &l, 1, 1 );
1534 TTEXT2( "not
", "NOT
" );
1535 TTEXT2( "like
", "LIKE
" );
1537 BUILD_NODE( N_QUERY_COND, "not like
", &l, 1, 1 );
1538 END_TRY( QueryCondOp )
1542 ABORT( op != NULL && strcmp( op, "||
" ) != 0 );
1546 ABORT( op != NULL && strcmp( op, "&&
" ) != 0 );
1551 LOOP_END( Junction )
1552 BUILD_NODE( N_QUERY_COND_JUNCTION, op, &start, n + 1, n + 1 );
1554 END_TRY( QueryCond )
1555 PARSER_FUNC_END( QueryCond )
1557 int nextStringBase2( Pointer *e, char *value, int max_len, char* delim ) {
1558 char *value0 = value;
1560 int ch = nextChar( e );
1561 while ( ch != -1 ) {
1562 if (value >= value0 + max_len) {
1565 if ( delim[0] == ch && delim[1] == lookAhead( e, 1 ) ) {
1566 if ( delim[0] == delim[1] ) {
1567 while ( lookAhead( e, 2 ) == delim[1] ) {
1568 *( value++ ) = delim[0];
1569 if (value >= value0 + max_len) { return -1; }
1585 * return number of vars or -1 if no string found
1587 int nextStringBase( Pointer *e, char *value, int max_len, char* delim, int consumeDelim, char escape, int cntOffset, int vars[] ) {
1588 int mode = 1; /* 1 string 3 escape */
1590 char* value0 = value;
1591 *value = lookAhead( e, 0 );
1593 int ch = nextChar( e );
1594 while ( ch != -1 ) {
1595 if (value >= value0 + max_len) {
1601 if ( ch == escape ) {
1605 else if ( strchr( delim, ch ) != NULL ) {
1606 if ( consumeDelim ) {
1608 trimquotes( value0 );
1617 else if ( ( ch == '*' || ch == '$' ) &&
1618 isalpha( lookAhead( e, 1 ) ) ) {
1619 vars[nov++] = value - value0 - cntOffset;
1628 else if ( ch == 't' ) {
1631 else if ( ch == 'r' ) {
1634 else if ( ch == '0' ) {
1647 int nextStringParsed( Pointer *e, char *value, int max_len, char* deliml, char *delimr, char *delim, int consumeDelim, int vars[] ) {
1648 int mode = 0; /* level */
1650 char* value0 = value;
1651 int ch = lookAhead( e, 0 );
1652 while ( ch != -1 ) {
1653 if (value >= value0 + max_len) {
1657 if ( strchr( deliml, ch ) != NULL ) {
1660 else if ( mode > 0 && strchr( delimr, ch ) != NULL ) {
1663 else if ( mode == 0 && strchr( delim, ch ) ) {
1664 if ( consumeDelim ) {
1666 trimquotes( value0 );
1675 else if ( ( ch == '*' || ch == '$' ) &&
1676 isalpha( lookAhead( e, 1 ) ) ) {
1677 vars[nov++] = value - value0;
1684 int nextString( Pointer *e, char *value, int vars[] ) {
1685 return nextStringBase( e, value, MAX_TOKEN_TEXT_LEN, "\
"", 1,
'\\', 1, vars );
1693 for ( i = 0; i <
num_ops; i++ ) {
1702 for ( i = 0; i <
num_ops; i++ ) {
1711 for ( i = 0; i <
num_ops; i++ ) {
1713 if (
new_ops[i].arity == 1 ) {
1722 for ( i = 0; i <
num_ops; i++ ) {
1724 if (
new_ops[i].arity == 2 ) {
1733 for ( i = 0; i <
num_ops; i++ ) {
1741 char* trimmed = str;
1742 while ( *trimmed ==
'\t' || *trimmed ==
' ' ) {
1745 int l = strlen( trimmed ) - 1;
1746 while (
l >= 0 && ( trimmed[
l] ==
'\t' || trimmed[
l] ==
' ' ) ) {
1749 trimmed[
l + 1] =
'\0';
1754 int len = strlen(
string ) - 2;
1755 memmove(
string,
string + 1, len *
sizeof(
char ) );
1761 char buf[128], buf2[128];
1784 strcpy( iotype,
"" );
1786 strcat( iotype,
"i" );
1789 strcat( iotype,
"o" );
1792 strcat( iotype,
"d" );
1795 strcat( iotype,
"e" );
1798 strcat( iotype,
"a" );
1803 for ( i = 0; i < n->
degree; i++ ) {
1814 snprintf( t.
text,
sizeof( t.
text ),
"%s", fn );
1817 if ( opPrec < prec ) {
1818 PRINT(
p, s,
"%s",
"(" );
1821 PRINT(
p, s,
" %s ", fn );
1823 if ( opPrec < prec ) {
1824 PRINT(
p, s,
"%s",
")" );
1835 PRINT(
p, s,
"%s",
"<unsupported>" );
1839 PRINT(
p, s,
"%s",
"(" );
1841 for ( i = 0; i < n->
degree; i++ ) {
1843 PRINT(
p, s,
"%s",
"," );
1847 PRINT(
p, s,
"%s",
")" );
1857 PRINT(
p, s,
"%s",
"\"" );
1859 for ( k = 0; k < strlen( n->
text ); k++ ) {
1860 switch ( n->
text[k] ) {
1862 PRINT(
p, s,
"%s",
"\\t" );
1865 PRINT(
p, s,
"%s",
"\\n" );
1868 PRINT(
p, s,
"%s",
"\\r" );
1875 PRINT(
p, s,
"%s",
"\\" );
1883 PRINT(
p, s,
"%s",
"\"" );
1886 PRINT(
p, s,
"%s",
"<unsupported>" );
1897 if ( strcmp( fn,
"if" ) == 0 ) {
1898 PRINT(
p, s,
"%s",
"if (" );
1900 PRINT(
p, s,
"%s",
") " );
1902 PRINT(
p, s,
"%s",
" else " );
1906 if ( strcmp( fn,
"if2" ) == 0 ) {
1907 PRINT(
p, s,
"%s",
"if " );
1909 PRINT(
p, s,
"%s",
" then " );
1911 PRINT(
p, s,
"%s",
" else " );
1915 if ( strcmp( fn,
"while" ) == 0 ) {
1916 PRINT(
p, s,
"%s",
"while (" );
1918 PRINT(
p, s,
"%s",
") " );
1922 if ( strcmp( fn,
"foreach" ) == 0 ) {
1923 PRINT(
p, s,
"%s",
"foreach (" );
1925 PRINT(
p, s,
"%s",
") " );
1929 if ( strcmp( fn,
"foreach2" ) == 0 ) {
1930 PRINT(
p, s,
"%s",
"foreach (" );
1932 PRINT(
p, s,
"%s",
" in " );
1934 PRINT(
p, s,
"%s",
") " );
1938 if ( strcmp( fn,
"for" ) == 0 ) {
1939 PRINT(
p, s,
"%s",
"for (" );
1941 PRINT(
p, s,
"%s",
";" );
1943 PRINT(
p, s,
"%s",
";" );
1945 PRINT(
p, s,
"%s",
") " );
1949 if ( strcmp( fn,
"let" ) == 0 ) {
1950 PRINT(
p, s,
"%s",
"let " );
1952 PRINT(
p, s,
"%s",
" = " );
1954 PRINT(
p, s,
"%s",
" in " );
1958 if ( strcmp( fn,
"match" ) == 0 ) {
1959 PRINT(
p, s,
"%s",
"match " );
1961 PRINT(
p, s,
"%s",
" with" );
1964 PRINT(
p, s,
"%s",
"\n" );
1966 PRINT(
p, s,
"%s",
"| " );
1968 PRINT(
p, s,
"%s",
" => " );
1973 if ( strcmp( fn,
"assign" ) == 0 ) {
1975 PRINT(
p, s,
"%s",
" = " );
1979 if ( strcmp( fn,
"query" ) == 0 ) {
1982 PRINT(
p, s,
"%s",
"select" );
1984 for ( i = 0; i < queNode->
degree; i++ ) {
1987 PRINT(
p, s,
"%s",
"," );
1999 PRINT(
p, s,
" %s",
"where" );
2003 PRINT(
p, s,
" %s",
"and" );
2018 snprintf( t.
text,
sizeof( t.
text ),
"%s", fn );
2021 if ( opPrec < prec ) {
2022 PRINT(
p, s,
"%s",
"(" );
2025 PRINT(
p, s,
" %s ", fn );
2027 if ( opPrec < prec ) {
2028 PRINT(
p, s,
"%s",
")" );
2037 PRINT(
p, s,
"%s",
"(" );
2039 for ( i = 0; i < n->
degree; i++ ) {
2041 PRINT(
p, s,
"%s",
"," );
2045 PRINT(
p, s,
"%s",
")" );
2055 PRINT(
p, s,
"%s", quote ?
"\'" :
"\"" );
2057 for ( k = 0; k < strlen( n->
text ); k++ ) {
2058 switch ( n->
text[k] ) {
2060 PRINT(
p, s,
"%s",
"\\t" );
2063 PRINT(
p, s,
"%s",
"\\n" );
2066 PRINT(
p, s,
"%s",
"\\r" );
2073 PRINT(
p, s,
"%s",
"\\" );
2082 PRINT(
p, s,
"%s", quote ?
"\'" :
"\"" );
2085 PRINT(
p, s,
"%s",
"<unsupported>" );
2090 for ( i = 0; i <
indent; i++ ) {
2091 PRINT(
p, s,
"%s",
" " );
2099 PRINT(
p, s,
"%s",
"{\n" );
2100 for ( i = 0; i < n; i++ ) {
2104 PRINT(
p, s,
"%s",
":::" );
2107 if ( ( *
p )[-1] !=
'}' ) {
2108 PRINT(
p, s,
"%s",
";" );
2110 PRINT(
p, s,
"%s",
"\n" );
2113 PRINT(
p, s,
"%s",
"}" );
2119 for ( i = 0; i < n; i++ ) {
2121 PRINT(
p, s,
"%s",
"@(" );
2123 PRINT(
p, s,
"%s",
", " );
2125 PRINT(
p, s,
"%s",
", " );
2127 PRINT(
p, s,
"%s",
")\n" );
2133 PRINT(
p, s,
"%s",
"(" );
2137 PRINT(
p, s,
"%s",
"," );
2141 PRINT(
p, s,
"%s",
")" );
2147 PRINT(
p, s,
"%s ",
"input output" );
2150 PRINT(
p, s,
"%s ",
"output" );
2153 PRINT(
p, s,
"%s ",
"dynamic" );
2156 PRINT(
p, s,
"%s ",
"actions" );
2159 PRINT(
p, s,
"%s ",
"expression" );
2164 PRINT(
p, s,
" %s",
"{" );
2168 PRINT(
p, s,
"%s",
" " );
2170 PRINT(
p, s,
"%s",
"}" );
2174 if ( strcmp( etype->
text,
FUNC ) == 0 ) {
2178 PRINT(
p, s,
" %s",
"?" );
2181 PRINT(
p, s,
" %s",
"*" );
2184 PRINT(
p, s,
" %s",
"+" );
2186 PRINT(
p, s,
" %s ",
"->" );
2194 PRINT(
p, s,
"%s",
"(" );
2197 PRINT(
p, s,
"%s ",
"," );
2201 PRINT(
p, s,
"%s",
")" );
2212 PRINT(
p, s,
" %s ",
"=>" );
2217 PRINT(
p, s,
"%s",
"unit" );
2221 PRINT(
p, s,
"%s",
"<" );
2226 PRINT(
p, s,
" %s ",
"*" );
2231 PRINT(
p, s,
"%s",
">" );
2259 PRINT(
p, s,
"%s",
" " );
2261 strcmp( subt->
text,
"true" ) != 0 ) {
2262 PRINT(
p, s,
"%s",
"{\n" );
2264 PRINT(
p, s,
"%s",
"on " );
2266 PRINT(
p, s,
"%s",
" " );
2274 PRINT(
p, s,
"%s",
"\n" );
2277 PRINT(
p, s,
"%s",
"}\n" );
2280 PRINT(
p, s,
"%s",
"\n" );
2286 PRINT(
p, s,
"%s",
" = " );
2288 PRINT(
p, s,
"%s",
"\n" );
2293 PRINT(
p, s,
"%s",
" : " );
2295 PRINT(
p, s,
"%s",
"\n" );
2299 PRINT(
p, s,
"%s ",
"data" );
2301 PRINT(
p, s,
"%s",
"\n" );
2306 PRINT(
p, s,
"%s",
"\n" );
2317 PRINT(
p, s,
"%s(", fn );
2320 for ( i = 0; i < n; i++ ) {
2324 PRINT(
p, s,
"%s", res );
2334 PRINT(
p, s,
"%s",
", " );
2337 PRINT(
p, s,
"%s",
")" );
2344 strcmp( a->
text,
b->text ) == 0 &&
2347 for ( i = 0; i < a->
degree; i++ ) {
2359 strcmp( val,
b->text ) == 0 ) {
2363 strcmp( a->
text,
b->text ) == 0 &&
2366 for ( i = 0; i < a->
degree; i++ ) {
2383 if ( expr->
text[0] ==
'*' ) {
2391 for ( i = 0; i < expr->
degree; i++ ) {
2402 for ( i = 0; i < len; i++ ) {
2419 if (
p->strbuf[
p->strp] ==
'\0' ) {
2422 int ch =
p->strbuf[++
p->strp];
2443 if (
buf->isFile ) {
2453 fseek( fp, 0, SEEK_SET );
2459 p->base = (
char * )malloc( strlen( ruleBaseName ) + 2 );
2461 strcpy(
p->base + 1, ruleBaseName );
2466 p->strlen = strlen(
buf );
2469 p->base = (
char * )malloc( strlen(
buf ) + 2 );
2471 strcpy(
p->base + 1,
buf );
2476 unsigned int move = (
p->len + 1 ) / 2;
2478 int startpos =
p->len -
move;
2481 memmove(
p->buf,
p->buf +
move, startpos *
sizeof(
char ) );
2483 int count = fread(
p->buf + startpos,
sizeof(
char ), load,
p->fp );
2484 p->len = startpos + count;
2486 p->fpos +=
move *
sizeof( char );
2493 if (
p -> isFile ) {
2494 if (
p->fpos < x *
sizeof(
char ) ||
p->fpos +
p->len >= x *
sizeof(
char ) ) {
2495 int error_code = fseek(
p->fp, x *
sizeof(
char ), SEEK_SET );
2496 if ( error_code != 0 ) {
2497 rodsLog(
LOG_ERROR,
"fseek failed in seekInFile with error code %d", error_code );
2500 p->fpos = x *
sizeof( char );
2504 p->p = x *
sizeof( char ) -
p->fpos;
2514 p->fpos +=
p->len *
sizeof( char );
2529 while ( len < n && ( ch =
lookAhead(
p, 0 ) ) != -1 ) {
2530 buf[len++] = ( char ) ch;
2538 int len = strlen(
p->strbuf +
start->exprloc );
2539 len = len > n ? n : len;
2540 memcpy(
buf,
p->strbuf +
start->exprloc, len *
sizeof(
char ) );
2553 while ( ch != -1 ) {
2555 if ( i < start->exprloc ) {
2565 if ( len == n - 1 ) {
2581 coor[0] = coor[1] = 0;
2584 for ( i = 0; i < errloc->
exprloc; i++ ) {
2608 while ( i <
line && ch != -1 ) {
2621 while ( i ==
line && ch != -1 ) {
2636 if ( context ==
NULL || context->
tqtop == context->
tqp ) {
2638 l->exprloc =
p->fpos /
sizeof( char ) +
p->p;
2641 l->exprloc =
p->strp;
2653 if (
p->p + n >=
p->len ) {
2655 if (
p->p + n >=
p->len ) {
2659 return (
int )
p->buf[
p->p + n];
2662 if ( n +
p->strp >=
p->strlen ) {
2665 return (
int )
p->strbuf[
p->strp + n];
2728 char* value0 =
value;
2758 char* value0 =
value;
2853 else if ( ch ==
'\'' ) {
2862 while ( isspace(
token->
text[l0 - 1] ) ) {
2875 NT( _TypingConstraints );
2877 context->symtable = temp;
2887 context->symtable = temp;
2902 context->symtable = temp;
2956 TTEXT2(
"integer",
"int" );
3038 TTEXT2( "actions", "a" );
3044 TTEXT2( "dynamic", "d" );
3107 if ( arity != 1 || lifted ) {
3117 while ( !done2 && NO_SYNTAX_ERROR ) {
3120 OPTIONAL_BEGIN( typeVarBoundEnd )
3123 OPTIONAL_END( typeVarBoundEnd )
3126 BUILD_NODE( T_VAR, NULL, &start, n, n );
3131 PARSER_FUNC_END( TypeSet )
3133 PARSER_FUNC_BEGIN( _TypingConstraints )
3142 BUILD_NODE( TC_LT, "", &pos2, 0, 0 ); /* node for generating error messages */
3143 BUILD_NODE( TC_LT, "<=
", &pos2, 3, 3 );
3152 BUILD_NODE( TC_SET, "{}
", &start, n, n );
3153 PARSER_FUNC_END( TypingConstraints )
3155 PARSER_FUNC_BEGIN( _FuncType )
3161 vararg = OPTION_VARARG_STAR;
3164 vararg = OPTION_VARARG_PLUS;
3167 vararg = OPTION_VARARG_OPTIONAL;
3169 vararg = OPTION_VARARG_ONCE;
3173 BUILD_NODE( T_CONS, FUNC, &start, 2, 2 );
3175 setVararg( node, vararg );
3177 PARSER_FUNC_END( _FuncType )
3179 int parseRuleSet( Pointer *e, RuleSet *ruleSet, Env *funcDescIndex, int *errloc, rError_t *errmsg, Region *r ) {
3180 char errbuf[ERR_MSG_LEN];
3182 ParserContext *pc = newParserContext( errmsg, r );
3185 /* parser variables */
3186 int backwardCompatible = 0; /* 0 auto 1 true -1 false */
3188 while ( ret == 1 ) {
3189 pc->nodeStackTop = 0;
3190 pc->stackTopStackTop = 0;
3191 token = nextTokenRuleGen( e, pc, 1, 0 );
3192 switch ( token->type ) {
3194 deleteParserContext( pc );
3201 if ( token->text[0] == '#' ) {
3205 else if ( token->text[0] == '@' ) { /* directive */
3206 token = nextTokenRuleGen( e, pc, 1, 0 );
3207 if ( strcmp( token->text, "backwardCompatible
" ) == 0 ) {
3208 token = nextTokenRuleGen( e, pc, 1, 0 );
3209 if ( token->type == TK_TEXT ) {
3210 if ( strcmp( token->text, "true" ) == 0 ) {
3211 backwardCompatible = 1;
3213 else if ( strcmp( token->text, "false" ) == 0 ) {
3214 backwardCompatible = -1;
3216 else if ( strcmp( token->text, "auto" ) == 0 ) {
3217 backwardCompatible = 0;
3220 /* todo error handling */
3224 /* todo error handling */
3227 else if ( strcmp( token->text, "include
" ) == 0 ) {
3228 token = nextTokenRuleGen( e, pc, 1, 0 );
3229 if ( token->type == TK_TEXT || token->type == TK_STRING ) {
3230 int ret = readRuleSetFromFile( token->text, ruleSet, funcDescIndex, errloc, errmsg, r );
3232 deleteParserContext( pc );
3237 /* todo error handling */
3241 /* todo error handling */
3249 pushback( token, pc );
3251 Node *node = parseRuleRuleGen( e, backwardCompatible, pc );
3252 if ( node == NULL ) {
3253 addRErrorMsg( errmsg, RE_OUT_OF_MEMORY, "parseRuleSet:
out of memory.
" );
3254 deleteParserContext( pc );
3255 return RE_OUT_OF_MEMORY;
3257 else if ( getNodeType( node ) == N_ERROR ) {
3258 *errloc = NODE_EXPR_POS( node );
3259 generateErrMsg( "parseRuleSet:
error parsing rule.
", *errloc, e->base, errbuf );
3260 addRErrorMsg( errmsg, RE_PARSER_ERROR, errbuf );
3261 /* skip the current line and try to parse the rule from the next line */
3263 deleteParserContext( pc );
3264 return RE_PARSER_ERROR;
3267 int n = node->degree;
3268 Node **nodes = node->subtrees;
3269 /* if(strcmp(node->text, "UNPARSED
") == 0) {
3270 pushRule(ruleSet, newRuleDesc(RK_UNPARSED, nodes[0], r));
3272 if ( strcmp( node->text, "INDUCT
" ) == 0 ) {
3274 pushRule( ruleSet, newRuleDesc( RK_DATA, nodes[0], 0, r ) );
3275 for ( k = 1; k < n; k++ ) {
3276 if ( lookupFromEnv( funcDescIndex, nodes[k]->subtrees[0]->text ) != NULL ) {
3277 generateErrMsg( "parseRuleSet: redefinition of constructor.
", NODE_EXPR_POS( nodes[k]->subtrees[0] ), nodes[k]->subtrees[0]->base, errbuf );
3278 addRErrorMsg( errmsg, RE_TYPE_ERROR, errbuf );
3279 deleteParserContext( pc );
3280 return RE_TYPE_ERROR;
3282 insertIntoHashTable( funcDescIndex->current, nodes[k]->subtrees[0]->text, newConstructorFD2( nodes[k]->subtrees[1], r ) );
3283 pushRule( ruleSet, newRuleDesc( RK_CONSTRUCTOR, nodes[k], 0, r ) );
3286 else if ( strcmp( node->text, "CONSTR
" ) == 0 ) {
3287 if ( lookupFromEnv( funcDescIndex, nodes[0]->subtrees[0]->text ) != NULL ) {
3288 generateErrMsg( "parseRuleSet: redefinition of constructor.
", NODE_EXPR_POS( nodes[0]->subtrees[0] ), nodes[0]->subtrees[0]->base, errbuf );
3289 addRErrorMsg( errmsg, RE_TYPE_ERROR, errbuf );
3290 deleteParserContext( pc );
3291 return RE_TYPE_ERROR;
3293 insertIntoHashTable( funcDescIndex->current, nodes[0]->subtrees[0]->text, newConstructorFD2( nodes[0]->subtrees[1], r ) );
3294 pushRule( ruleSet, newRuleDesc( RK_CONSTRUCTOR, nodes[0], 0, r ) );
3296 else if ( strcmp( node->text, "EXTERN
" ) == 0 ) {
3298 if ( ( fd = ( FunctionDesc * ) lookupFromEnv( funcDescIndex, nodes[0]->subtrees[0]->text ) ) != NULL ) {
3299 generateErrMsg( "parseRuleSet: redefinition of
function.
", NODE_EXPR_POS( nodes[0]->subtrees[0] ), nodes[0]->subtrees[0]->base, errbuf );
3300 addRErrorMsg( errmsg, RE_TYPE_ERROR, errbuf );
3301 deleteParserContext( pc );
3302 return RE_TYPE_ERROR;
3304 insertIntoHashTable( funcDescIndex->current, nodes[0]->subtrees[0]->text, newExternalFD( nodes[0]->subtrees[1], r ) );
3305 pushRule( ruleSet, newRuleDesc( RK_EXTERN, nodes[0], 0, r ) );
3307 else if ( strcmp( node->text, "REL
" ) == 0 ) {
3308 int notyping = backwardCompatible >= 0 ? 1 : 0;
3310 for ( k = 0; k < n; k++ ) {
3311 Node *node = nodes[k];
3312 pushRule( ruleSet, newRuleDesc( RK_REL, node, notyping, r ) );
3313 /* printf("%s\n
", node->subtrees[0]->text);
3314 printTree(node, 0); */
3317 else if ( strcmp( node->text, "FUNC" ) == 0 ) {
3319 for ( k = 0; k < n; k++ ) {
3320 Node *node = nodes[k];
3321 pushRule( ruleSet, newRuleDesc( RK_FUNC, node, 0, r ) );
3322 /* printf("%s\n
", node->subtrees[0]->text);
3323 printTree(node, 0); */
3328 deleteParserContext( pc );
3333 * parse the string for an ExprType
3343 * <var> ({ <type> ... <type> })? variable
3344 * <type> * ... * <type> product
3345 * < <type> * ... * <type> > lifted product
3348 * <type> (*|+|?)? -> <type> function
3349 * forall <var> (in { <type> ... <type> })?, <type> universal
3351 Node* parseFuncTypeFromString( char *string, Region *r ) {
3352 Pointer *p = newPointer2( string );
3353 ParserContext *pc = newParserContext( NULL, r );
3354 nextRuleGenFuncType( p, pc );
3355 Node *exprType = pc->nodeStack[0];
3356 deleteParserContext( pc );
3360 Node* parseTypingConstraintsFromString( char *string, Region *r ) {
3361 Pointer *p = newPointer2( string );
3362 ParserContext *pc = newParserContext( NULL, r );
3363 nextRuleGenTypingConstraints( p, pc );
3364 Node *exprType = pc->nodeStack[0];
3365 /*char buf[ERR_MSG_LEN];
3366 errMsgToString(pc->errmsg, buf, ERR_MSG_LEN);
3367 printf("%s
", buf);*/
3368 deleteParserContext( pc );
3372 Node *parseRuleRuleGen( Pointer *expr, int backwardCompatible, ParserContext *pc ) {
3373 nextRuleGenRule( expr, pc, backwardCompatible );
3374 Node *rulePackNode = pc->nodeStack[0];
3376 if ( pc->errnode != NULL ) {
3377 rulePackNode = pc->errnode;
3380 rulePackNode = createErrorNode( "parser error", &pc->errloc, pc->region );
3383 return rulePackNode;
3385 Node *parseTermRuleGen( Pointer *expr, int rulegen, ParserContext *pc ) {
3386 nextRuleGenTerm( expr, pc, rulegen, 0 );
3387 Node *rulePackNode = pc->nodeStack[0];
3389 if ( pc->errnode != NULL ) {
3390 rulePackNode = pc->errnode;
3393 rulePackNode = createErrorNode( "parser error", &pc->errloc, pc->region );
3397 return rulePackNode;
3400 Node *parseActionsRuleGen( Pointer *expr, int rulegen, int backwardCompatible, ParserContext *pc ) {
3401 nextRuleGenActions( expr, pc, rulegen, backwardCompatible );
3402 Node *rulePackNode = pc->nodeStack[0];
3404 if ( pc->errnode != NULL ) {
3405 rulePackNode = pc->errnode;
3408 rulePackNode = createErrorNode( "parser error", &pc->errloc, pc->region );
3412 return rulePackNode;
3415 char* typeName_Res( Res *s ) {
3416 return typeName_ExprType( s->exprType );
3419 char* typeName_ExprType( ExprType *s ) {
3420 switch ( getNodeType( s ) ) {
3424 return typeName_NodeType( getNodeType( s ) );
3428 char* typeName_Parser( NodeType s ) {
3465 char* typeName_NodeType( NodeType s ) {
3502 void generateErrMsgFromFile( char *msg, long errloc, char *ruleBaseName, char* ruleBasePath, char errbuf[ERR_MSG_LEN] ) {
3503 FILE *fp = fopen( ruleBasePath, "r
" );
3505 Pointer *e = newPointer( fp, ruleBaseName );
3509 generateErrMsgFromPointer( msg, &l, e, errbuf );
3514 void generateErrMsgFromSource( char *msg, long errloc, char *src, char errbuf[ERR_MSG_LEN] ) {
3515 Pointer *e = newPointer2( src );
3519 generateErrMsgFromPointer( msg, &l, e, errbuf );
3522 void generateErrMsgFromPointer( char *msg, Label *l, Pointer *e, char errbuf[ERR_MSG_LEN] ) {
3523 char buf[ERR_MSG_LEN];
3524 dupLine( e, l, ERR_MSG_LEN, buf );
3525 int len = strlen( buf );
3527 getCoor( e, l, coor );
3529 if ( len < ERR_MSG_LEN - 1 ) {
3532 for ( i = 0; i < coor[1]; i++ ) {
3533 if ( len >= ERR_MSG_LEN - 1 ) {
3536 buf[len++] = buf[i] == '\t' ? '\t' : ' ';
3538 if ( len < ERR_MSG_LEN - 2 ) {
3543 snprintf( errbuf, ERR_MSG_LEN,
3544 "%s\nline %d,
col %d, rule base %s\n%s\n
", msg, coor[0], coor[1], e->base + 1, buf );
3546 snprintf( errbuf, ERR_MSG_LEN,
3547 "%s\nline %d,
col %d\n%s\n
", msg, coor[0], coor[1], buf );
3550 void generateAndAddErrMsg( char *msg, Node *node, int errcode, rError_t *errmsg ) {
3551 char errmsgBuf[ERR_MSG_LEN];
3552 generateErrMsg( msg, NODE_EXPR_POS( node ), node->base, errmsgBuf );
3553 addRErrorMsg( errmsg, errcode, errmsgBuf );
3555 char *generateErrMsg( char *msg, long errloc, char *ruleBaseName, char errmsg[ERR_MSG_LEN] ) {
3556 char ruleBasePath[MAX_NAME_LEN];
3557 switch ( ruleBaseName[0] ) {
3559 generateErrMsgFromSource( msg, errloc, ruleBaseName + 1, errmsg );
3562 getRuleBasePath( ruleBaseName + 1, ruleBasePath );
3563 generateErrMsgFromFile( msg, errloc, ruleBaseName + 1, ruleBasePath, errmsg );
3566 rodsLog(LOG_ERROR, "generateErrMsg: ruleBaseName of unknown
type: [%s] [%ji] [%s]
", msg, static_cast<intmax_t>(errloc), ruleBaseName);
3567 snprintf( errmsg, ERR_MSG_LEN, "<unknown source
type>
" );
void rodsLog(int level, const char *formatStr,...)
#define TTYPE_LOOKAHEAD(x)
int isLocalVariableNode(Node *node)
int parseRuleSet(Pointer *e, RuleSet *ruleSet, Env *funcDescIndex, int *errloc, rError_t *errmsg, Region *r)
char * convertResToString(Res *res0)
int nextString2(Pointer *e, char *value, int vars[])
#define TTEXT_LOOKAHEAD(x)
Label * getFPos(Label *l, Pointer *p, ParserContext *context)
void nextActionArgumentStringBackwardCompatible(Pointer *e, Token *token)
#define IO_TYPE_EXPRESSION
void * region_alloc(Region *r, size_t s)
void clearBuffer(Pointer *p)
void syncTokenQueue(Pointer *e, ParserContext *context)
int isVariableNode(Node *node)
#define PARSER_FUNC_PROTO1(l, p)
int getLineRange(Pointer *p, int line, rodsLong_t range[2])
void readToBuffer(Pointer *p)
char * typeToString(ExprType *type, Hashtable *var_types, char *buf, int bufsize)
void printTree(Node *n, int indent)
void functionApplicationToString(char *buf, int size, char *fn, Node **args, int n)
char * generateErrMsg(char *msg, long errloc, char *ruleBaseName, char errmsg[1024])
void skipComments(Pointer *e)
int nextStringBase(Pointer *e, char *value, int max_len, char *delim, int consumeDelim, char escape, int cntOffset, int vars[])
int nextStringParsed(Pointer *e, char *value, int max_len, char *deliml, char *delimr, char *delim, int consumeDelim, int vars[])
ParserContext * newParserContext(rError_t *errmsg, Region *r)
int getBinaryPrecedence(Token *token)
int lookAhead(Pointer *p, unsigned int n)
char * nextRuleSection(char *buf, char *value)
int delayExec(msParam_t *condition, msParam_t *workflow, msParam_t *recoverWorkFlow, ruleExecInfo_t *rei)
#define T_VAR_DISJUNCT(x, n)
#define OPTION_VARARG_OPTIONAL
int isUnaryOp(Token *token)
auto end(const collection_iterator &) noexcept -> const collection_iterator
int eqExprNodeSyntacticVarMapping(Node *a, Node *b, Hashtable *varMapping)
char * nextStringString(char *e, char *value)
StringList * getVarNamesInExprNode(Node *expr, Region *r)
void trimquotes(char *string)
void metadataToString(char **p, int *s, int indent, Node *nm)
Hashtable * newHashTable2(int size, Region *r)
void skipWhitespace(Pointer *expr)
void printIndent(int indent)
Pointer * newPointer2(char *buf)
irods::error start(irods::default_re_ctx &_u, const std::string &_instance_name)
char * nextString2String(char *e, char *value)
void nextChars(Pointer *p, int len)
#define PRINT(p, s, f, d)
void patternToString(char **p, int *s, int indent, int prec, Node *n)
#define BUILD_NODE(type, cons, loc, deg, consume)
#define PARSER_FUNC_END(l)
#define PARSER_FUNC_PROTO2(l, p, q)
void termToString(char **p, int *s, int indent, int prec, Node *n, int quote)
void typeToStringParser(char **p, int *s, int indent, int lifted, ExprType *type)
ExprType * newSimpType(NodeType t, Region *r)
int insertIntoHashTable(Hashtable *h, const char *key, const void *value)
#define OPTION_VARARG_PLUS
#define MAX_TOKEN_TEXT_LEN
int dupLine(Pointer *p, Label *start, int n, char *buf)
auto move(rcComm_t &_comm, const path &_old_p, const path &_new_p) -> void
#define OPTION_VARARG_STAR
int remoteExec(msParam_t *hostName, msParam_t *condition, msParam_t *workflow, msParam_t *recoverWorkFlow, ruleExecInfo_t *rei)
const void * lookupFromHashTable(Hashtable *h, const char *key)
void ruleToString(char *buf, int size, RuleDesc *rd)
#define OPTION_VARARG_ONCE
#define ERROR(code_, message_)
int isSessionVariableNode(Node *node)
void indentToString(char **p, int *s, int indent)
#define PARSER_FUNC_PROTO(l)
void ruleNameToString(char **p, int *s, int indent, Node *rn)
void actionsToString(char **p, int *s, int indent, Node *na, Node *nr)
def indent(*text, **kwargs)
int getUnaryPrecedence(Token *token)
void deletePointer(Pointer *buf)
int nextString(Pointer *e, char *value, int vars[])
int match(char *pattern, char *text)
int eqExprNodeSyntactic(Node *a, Node *b)
#define PARSER_FUNC_BEGIN1(l, p)
int skip(Pointer *e, char *text, Token **token, ParserContext *pc, int rulegen)
void deleteParserContext(ParserContext *t)
int isKeyword(char *text)
void initPointer2(Pointer *p, char *buf)
void seekInFile(Pointer *p, unsigned long x)
#define T_VAR_NUM_DISJUNCTS(x)
void initPointer(Pointer *p, FILE *fp, const char *ruleBaseName)
#define PARSER_FUNC_BEGIN2(l, p, q)
char * functionParameters(char *e, char *value)
void getCoor(Pointer *p, Label *errloc, int coor[2])
#define PARSER_FUNC_BEGIN(l)
void foreach2(S &&a, T &&b, F &&f)
#define OPTIONAL_BEGIN(l)
Pointer * newPointer(FILE *fp, const char *ruleBaseName)
int dupString(Pointer *p, Label *start, int n, char *buf)
char * typeName_Parser(NodeType s)
#define T_CONS_TYPE_ARG(x, n)
Token * nextTokenRuleGen(Pointer *e, ParserContext *context, int rulegen, int pathLiteral)
char * findLineCont(char *expr)
int nextStringBase2(Pointer *e, char *value, int max_len, char *delim)
int isBinaryOp(Token *token)
char * cpStringExt(const char *str, Region *r)
StringList * getVarNamesInExprNodeAux(Node *expr, StringList *vars, Region *r)
void pushback(Token *token, ParserContext *context)
#define T_CONS_TYPE_NAME(x)