Add line number to parser nodes
[babeltrace.git] / formats / ctf / metadata / ctf-parser.y
index c59f2e751f086f3bc04b8be007dff4d9c84ab9c4..30f4c949870bb53e86a40f6cbf565f60a0f8ee3c 100644 (file)
  *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
  */
 
 #include <stdio.h>
@@ -31,7 +39,7 @@
 #include "ctf-parser.h"
 #include "ctf-ast.h"
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yydebug;
 
 /* Join two lists, put "add" at the end of "head".  */
@@ -47,16 +55,20 @@ _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
        }
 }
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yyparse(struct ctf_scanner *scanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yylex_destroy(yyscan_t yyscanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 void yyrestart(FILE * in_str, yyscan_t scanner);
+BT_HIDDEN
+int yyget_lineno(yyscan_t yyscanner);
+BT_HIDDEN
+char *yyget_text(yyscan_t yyscanner);
 
 struct gc_string {
        struct bt_list_head gc;
@@ -93,7 +105,7 @@ static const char *node_type_to_str[] = {
        [ NODE_STRUCT ] = "NODE_STRUCT",
 };
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 const char *node_type(struct ctf_node *node)
 {
        if (node->type < NR_NODE_TYPES)
@@ -124,7 +136,7 @@ static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
  * gsrc will be garbage collected immediately, and gstr might be.
  * Should only be used to append characters to a string literal or constant.
  */
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
                                   struct gc_string *gstr,
                                   struct gc_string *gsrc)
@@ -203,7 +215,7 @@ static int lookup_type(struct ctf_scanner_scope *s, const char *id)
        return ret;
 }
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int is_type(struct ctf_scanner *scanner, const char *id)
 {
        struct ctf_scanner_scope *it;
@@ -238,6 +250,7 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
                return NULL;
        memset(node, 0, sizeof(*node));
        node->type = type;
+       node->lineno = yyget_lineno(scanner->scanner);
        BT_INIT_LIST_HEAD(&node->tmp_head);
        bt_list_add(&node->gc, &ast->allocated_nodes);
        bt_list_add(&node->siblings, &node->tmp_head);
@@ -807,13 +820,15 @@ static int set_parent_node(struct ctf_node *node,
        return 0;
 }
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 void yyerror(struct ctf_scanner *scanner, const char *str)
 {
-       fprintf(stderr, "error %s\n", str);
+       fprintf(stderr, "error at line %d, token \"%s\": %s\n",
+               yyget_lineno(scanner->scanner),
+               yyget_text(scanner->scanner), str);
 }
  
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yywrap(void)
 {
        return 1;
@@ -928,6 +943,7 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
 
 %define api.pure
        /* %locations */
+%error-verbose
 %parse-param {struct ctf_scanner *scanner}
 %lex-param {struct ctf_scanner *scanner}
 /*
This page took 0.025023 seconds and 4 git commands to generate.