workingish
This commit is contained in:
parent
8dcd5fc41a
commit
fe4230994f
23
dexter.c
23
dexter.c
|
@ -187,7 +187,7 @@ 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;
|
||||
c->expr = c->string ? myparse(astrdup(json_object_get_string(c->json)), NULL) : NULL;
|
||||
|
||||
// printf("5\n");
|
||||
c->full_expr = full_expr(context, c->filter);
|
||||
|
@ -261,7 +261,7 @@ char* dex_key_filter(char* key) {
|
|||
int l = strlen(expr);
|
||||
if(l <= 1) return NULL;
|
||||
*(expr + l - 1) = 0; // clip ")"
|
||||
return myparse(expr);
|
||||
return myparse(expr, NULL);
|
||||
}
|
||||
|
||||
void __dex_recurse(contextPtr context) {
|
||||
|
@ -271,22 +271,25 @@ void __dex_recurse(contextPtr context) {
|
|||
keyPtr keys;
|
||||
contextPtr c;
|
||||
json_object_object_foreach(context->json, key, val) {
|
||||
// printf("Y\n");
|
||||
c = deeper_context(context, key, val);
|
||||
// printf("Z\n");
|
||||
sprintbuf(c->buf, "<%s>\n", c->tag);
|
||||
if(c->string) {
|
||||
if(c->array) {
|
||||
sprintbuf(c->buf, "<dexter:groups><xsl:for-each select=\"%s\"><dexter:group>\n", c->expr);
|
||||
sprintbuf(c->buf, "<xsl:value-of select=\".\" />\n");
|
||||
sprintbuf(c->buf, "</dexter:group></xsl:for-each></dexter:groups>\n");
|
||||
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, "</dexter:group></xsl:for-each></dexter:groups>\n");
|
||||
} else {
|
||||
sprintbuf(c->buf, "<dexter:groups><xsl:for-each select=\"%s\"><dexter:group>\n", c->expr);
|
||||
sprintbuf(c->buf, "<xsl:value-of select=\".\" />\n");
|
||||
sprintbuf(c->buf, "</dexter:group></xsl:for-each></dexter:groups>\n");
|
||||
}
|
||||
} else {
|
||||
sprintbuf(c->buf, "<xsl:value-of select=\"%s\" />\n", c->expr);
|
||||
}
|
||||
} else { // if c->object !string
|
||||
if(c->array) { // scoped
|
||||
|
||||
// printf("d\n");
|
||||
|
||||
if(c->filter != NULL) {
|
||||
|
||||
// printf("e\n");
|
||||
|
@ -297,7 +300,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)));
|
||||
tmp = myparse(astrdup(inner_key_of(c->json)), NULL);
|
||||
sprintbuf(c->buf, "<dexter:groups><xsl:for-each select=\"%s\">\n", filter_intersection(context->magic, tmp));
|
||||
|
||||
|
||||
|
|
20
parser.y
20
parser.y
|
@ -11,6 +11,7 @@
|
|||
#define YYSTYPE char *
|
||||
|
||||
static char* parsed_answer;
|
||||
static char* parse_magic_key;
|
||||
|
||||
int yylex (void);
|
||||
void yyerror (char const *);
|
||||
|
@ -20,7 +21,7 @@ void cleanup_parse(void);
|
|||
void start_debugging(void);
|
||||
|
||||
int yyparse(void);
|
||||
char* myparse(char*);
|
||||
char* myparse(char*, char*);
|
||||
void answer(char*);
|
||||
|
||||
#endif
|
||||
|
@ -211,9 +212,17 @@ AbbreviatedAxisSpecifier
|
|||
| { $$ = ""; }
|
||||
;
|
||||
Expr
|
||||
: LPAREN Expr RPAREN %dprec 1
|
||||
| OrExpr %dprec 2
|
||||
| selectors_group %dprec 3
|
||||
: 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, ")");
|
||||
}
|
||||
}
|
||||
;
|
||||
PrimaryExpr
|
||||
: VariableReference
|
||||
|
@ -549,8 +558,9 @@ OptS
|
|||
|
||||
%%
|
||||
|
||||
char* myparse(char* string){
|
||||
char* myparse(char* string, char* key){
|
||||
// start_debugging();
|
||||
parse_magic_key = key;
|
||||
prepare_parse(string);
|
||||
yyparse();
|
||||
cleanup_parse();
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"magics": [{
|
||||
"head": "h1",
|
||||
"para(p)": ["substring-after(., ':')"]
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<html>
|
||||
<body>
|
||||
<h1>head1</h1>
|
||||
<p>p1: a</p>
|
||||
<p>p2: b</p>
|
||||
<h1>head2</h1>
|
||||
<p>p3: Z</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue