functions working
This commit is contained in:
parent
733217750c
commit
fc71b61a2a
2
TODO
2
TODO
|
@ -19,6 +19,8 @@
|
|||
? - optional field
|
||||
- fix not()/set-difference
|
||||
- debugging options
|
||||
- fix position()
|
||||
- shortcut functions
|
||||
- complain if empty / runtime no-match errors
|
||||
- CSS equations
|
||||
- saxon compatibility?!
|
||||
|
|
21
dexter.c
21
dexter.c
|
@ -187,12 +187,13 @@ contextPtr deeper_context(contextPtr context, char* key, struct json_object * va
|
|||
if(context->filter != NULL && !c->array) c->magic = NULL;
|
||||
c->buf = context->buf;
|
||||
// printf("%d\n", c->string);
|
||||
c->expr = c->string ? myparse(astrdup(json_object_get_string(c->json)), NULL) : NULL;
|
||||
c->raw_expr = c->string ? myparse(astrdup(json_object_get_string(c->json))) : NULL;
|
||||
|
||||
// printf("5\n");
|
||||
c->full_expr = full_expr(context, c->filter);
|
||||
c->full_expr = full_expr(c, c->expr);
|
||||
c->expr = filter_intersection(c->magic, c->expr);
|
||||
c->full_expr = full_expr(c, c->raw_expr);
|
||||
|
||||
c->expr = filter_intersection(c->magic, c->raw_expr);
|
||||
c->filter = filter_intersection(c->magic, c->filter);
|
||||
c->parent = context;
|
||||
// printf("2\n");
|
||||
|
@ -261,7 +262,7 @@ char* dex_key_filter(char* key) {
|
|||
int l = strlen(expr);
|
||||
if(l <= 1) return NULL;
|
||||
*(expr + l - 1) = 0; // clip ")"
|
||||
return myparse(expr, NULL);
|
||||
return myparse(expr);
|
||||
}
|
||||
|
||||
void __dex_recurse(contextPtr context) {
|
||||
|
@ -277,7 +278,7 @@ void __dex_recurse(contextPtr context) {
|
|||
if(c->array) {
|
||||
if(c->filter){
|
||||
sprintbuf(c->buf, "<dexter:groups><xsl:for-each select=\"%s\"><dexter:group>\n", c->filter);
|
||||
sprintbuf(c->buf, "<xsl:value-of select=\"%s\" />\n", c->expr);
|
||||
sprintbuf(c->buf, "<xsl:value-of select=\"%s\" />\n", c->raw_expr);
|
||||
sprintbuf(c->buf, "</dexter:group></xsl:for-each></dexter:groups>\n");
|
||||
} else {
|
||||
sprintbuf(c->buf, "<dexter:groups><xsl:for-each select=\"%s\"><dexter:group>\n", c->expr);
|
||||
|
@ -285,7 +286,13 @@ void __dex_recurse(contextPtr context) {
|
|||
sprintbuf(c->buf, "</dexter:group></xsl:for-each></dexter:groups>\n");
|
||||
}
|
||||
} else {
|
||||
sprintbuf(c->buf, "<xsl:value-of select=\"%s\" />\n", c->expr);
|
||||
if(c->filter){
|
||||
sprintbuf(c->buf, "<xsl:for-each select=\"%s\"><xsl:if test=\"position()=1\">\n", c->filter);
|
||||
sprintbuf(c->buf, "<xsl:value-of select=\"%s\" />\n", c->raw_expr);
|
||||
sprintbuf(c->buf, "</xsl:if></xsl:for-each>\n");
|
||||
} else {
|
||||
sprintbuf(c->buf, "<xsl:value-of select=\"%s\" />\n", c->expr);
|
||||
}
|
||||
}
|
||||
} else { // if c->object !string
|
||||
if(c->array) { // scoped
|
||||
|
@ -300,7 +307,7 @@ void __dex_recurse(contextPtr context) {
|
|||
|
||||
// printf("f\n");
|
||||
sprintbuf(c->buf, "<xsl:variable name=\"%s__context\" select=\".\"/>\n", c->name);
|
||||
tmp = myparse(astrdup(inner_key_of(c->json)), NULL);
|
||||
tmp = myparse(astrdup(inner_key_of(c->json)));
|
||||
sprintbuf(c->buf, "<dexter:groups><xsl:for-each select=\"%s\">\n", filter_intersection(context->magic, tmp));
|
||||
|
||||
|
||||
|
|
1
dexter.h
1
dexter.h
|
@ -44,6 +44,7 @@ typedef struct __dex_context {
|
|||
char* tag;
|
||||
char* filter;
|
||||
char* expr;
|
||||
char* raw_expr;
|
||||
char* full_expr;
|
||||
char* name;
|
||||
char* magic;
|
||||
|
|
25
parser.y
25
parser.y
|
@ -11,7 +11,6 @@
|
|||
#define YYSTYPE char *
|
||||
|
||||
static char* parsed_answer;
|
||||
static char* parse_magic_key;
|
||||
|
||||
int yylex (void);
|
||||
void yyerror (char const *);
|
||||
|
@ -21,7 +20,7 @@ void cleanup_parse(void);
|
|||
void start_debugging(void);
|
||||
|
||||
int yyparse(void);
|
||||
char* myparse(char*, char*);
|
||||
char* myparse(char*);
|
||||
void answer(char*);
|
||||
|
||||
#endif
|
||||
|
@ -137,9 +136,9 @@ Root
|
|||
;
|
||||
|
||||
LocationPath
|
||||
: RelativeLocationPath
|
||||
| AbsoluteLocationPath
|
||||
| selectors_group
|
||||
: RelativeLocationPath %dprec 1
|
||||
| AbsoluteLocationPath %dprec 1
|
||||
| selectors_group %dprec 3
|
||||
;
|
||||
|
||||
AbsoluteLocationPath
|
||||
|
@ -212,17 +211,8 @@ AbbreviatedAxisSpecifier
|
|||
| { $$ = ""; }
|
||||
;
|
||||
Expr
|
||||
: LPAREN Expr RPAREN %dprec 1 { $$ = $2; }
|
||||
| OrExpr %dprec 2 {
|
||||
if(parse_magic_key != NULL) {
|
||||
$$ = astrcat7("set:intersection(key('", parse_magic_key, "__key', $", parse_magic_key, "__index), ", $1, ")");
|
||||
}
|
||||
}
|
||||
| selectors_group %dprec 3 {
|
||||
if(parse_magic_key != NULL) {
|
||||
$$ = astrcat7("set:intersection(key('", parse_magic_key, "__key', $", parse_magic_key, "__index), ", $1, ")");
|
||||
}
|
||||
}
|
||||
: LPAREN Expr RPAREN %dprec 2 { $$ = $2; }
|
||||
| OrExpr %dprec 1
|
||||
;
|
||||
PrimaryExpr
|
||||
: VariableReference
|
||||
|
@ -558,9 +548,8 @@ OptS
|
|||
|
||||
%%
|
||||
|
||||
char* myparse(char* string, char* key){
|
||||
char* myparse(char* string){
|
||||
// start_debugging();
|
||||
parse_magic_key = key;
|
||||
prepare_parse(string);
|
||||
yyparse();
|
||||
cleanup_parse();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"magics": [{
|
||||
"head": "h1",
|
||||
"para(p)": ["substring-after(., ':')"]
|
||||
"para(p)": ["substring-after(., ':')"],
|
||||
"single(p)": "substring-after(., ':')"
|
||||
}]
|
||||
}
|
|
@ -1 +1 @@
|
|||
{ "magics": [ { "head": "head1", "para": [ " a", " b" ] }, { "head": "head2", "para": [ " Z" ] } ] }
|
||||
{ "magics": [ { "head": "head1", "para": [ " a", " b" ], "single": " a" }, { "head": "head2", "para": [ " Z" ], "single": " Z" } ] }
|
Loading…
Reference in New Issue