summaryrefslogtreecommitdiff
path: root/source3/aparser/token.awk
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-05-17 06:53:21 +0000
committerAndrew Tridgell <tridge@samba.org>2000-05-17 06:53:21 +0000
commitba2f726efdb97c95c6110b0365a011121e27fce3 (patch)
treeab61d7cddc2bb615a938505b817cf0fd438999e0 /source3/aparser/token.awk
parentc560164030c0b842ee06f651a2b019c5596624a2 (diff)
downloadsamba-ba2f726efdb97c95c6110b0365a011121e27fce3.tar.gz
samba-ba2f726efdb97c95c6110b0365a011121e27fce3.tar.bz2
samba-ba2f726efdb97c95c6110b0365a011121e27fce3.zip
- added typedefs
- added parse error checking - made parser more flexible (This used to be commit ab0beaf3573471fab1fda3358987b337811f99b7)
Diffstat (limited to 'source3/aparser/token.awk')
-rw-r--r--source3/aparser/token.awk92
1 files changed, 92 insertions, 0 deletions
diff --git a/source3/aparser/token.awk b/source3/aparser/token.awk
new file mode 100644
index 0000000000..a64700f536
--- /dev/null
+++ b/source3/aparser/token.awk
@@ -0,0 +1,92 @@
+# tokenise the input file
+
+function parse_error(msg) {
+ printf("PARSE ERROR: %s\nLine "NR" : "$0"\n", msg);
+ exit 1;
+}
+
+# ignore blank lines
+/^[ \t]*$/ {
+ next;
+}
+
+# ignore comments
+/^[ \t]*\#/ {
+ next;
+}
+
+# ignore C comments
+/^[ \t]*\/\*.*\*\// {
+ next;
+}
+
+/^[ \t]*module/ {
+ {if (module!="") parse_error("you can only specify one module name");}
+ start_module($2);
+ next;
+}
+
+{if (module=="") parse_error("you must specify the module name first");}
+
+/^[ \t]*typedef struct.*\{/ {
+ {if (current_struct!="") parse_error("you cannot have nested structures");}
+ start_struct($3);
+ next;
+}
+
+/^[ \t]*typedef.*;/ {
+ {if (current_struct!="") parse_error("typedefs must be global");}
+ split($0,a,"[ \t;]*");
+ parse_typedef(a[2], a[3]);
+ next;
+}
+
+/^[ \t]*struct.*\{/ {
+ {if (current_struct!="") parse_error("you cannot have nested structures");}
+ start_struct($2);
+ next;
+}
+
+{if (current_struct=="") parse_error("this must appear inside a structure");}
+
+/^[ \t]*union.*\{/ {
+ {if (current_union!="") parse_error("you cannot have nested unions");}
+ start_union($2);
+ next;
+}
+
+/^[ \t]*case.*;/ {
+ {if (current_union=="") parse_error("this must appear inide a union");}
+ split($0,a,"[ \t;]*");
+ parse_case(a[3],a[4],a[5]);
+ next;
+}
+
+/^[ \t]*\}$/ {
+ {if (current_union=="") parse_error("this must appear inside a union");}
+ end_union();
+ next;
+}
+
+{if (current_union!="") parse_error("this cannot appear inside a union");}
+
+/^[ \t]*\};/ {
+ end_struct("");
+ next;
+}
+
+/^[ \t]*\} .*;/ {
+ split($0,a,"[ \t;]*");
+ end_struct(a[2]);
+ next;
+}
+
+/^.*;/ {
+ split($0,a,"[ \t;]*");
+ add_struct_elem(a[2], a[3]);
+ next;
+}
+
+{
+ parse_error("Unknown construct.");
+}