aboutsummaryrefslogtreecommitdiff
path: root/src/parse.h
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2016-03-07 15:00:21 +0000
committerIan C <ianc@noddybox.co.uk>2016-03-07 15:00:21 +0000
commit77e8708934c5c792b1435fa11dfe3c0a6f636a8c (patch)
tree8c68ecddaf2c2c0730ba310b8d1b9e0f1bd16132 /src/parse.h
parent6e9c9c9205d6eec1ff1cfb3fa407c6714854145a (diff)
Updated README and copied latest version in.
Diffstat (limited to 'src/parse.h')
-rw-r--r--src/parse.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/parse.h b/src/parse.h
new file mode 100644
index 0000000..ee1e37d
--- /dev/null
+++ b/src/parse.h
@@ -0,0 +1,123 @@
+/*
+
+ casm - Simple, portable assembler
+
+ Copyright (C) 2003-2015 Ian Cowburn (ianc@noddybox.demon.co.uk)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ -------------------------------------------------------------------------
+
+ Tokeniser and parser.
+
+*/
+
+#ifndef CASM_PARSE_H
+#define CASM_PARSE_H
+
+/* ---------------------------------------- TYPES
+*/
+
+/* Represents a tokenised line.
+
+ no_tokens is the number of tokens that can be accessed via token[i].
+
+ If quoted[i] is non-zero it contains the opening character that was used to
+ quote argument [i]. Note that '(' counts as a quote in command arguments.
+
+ If first_column is true then the first column held a parsable character.
+
+*/
+typedef struct Line
+{
+ int no_tokens;
+ int first_column;
+ int *quoted;
+ char **token;
+ char *comment;
+} Line;
+
+
+/* Used to represent a table of string/value pairs. The table is ended with
+ a NULL in str.
+*/
+typedef struct ValueTable
+{
+ const char *str;
+ int value;
+} ValueTable;
+
+
+/* ---------------------------------------- MACROS
+*/
+
+
+/* Defines the set of values allowed for boolean strings and generates table
+ entries using the passed 'tv' and 'fv' for true and false respictively.
+*/
+#define YES_NO_ENTRIES(tv, fv) \
+ {"on", tv}, \
+ {"true", tv}, \
+ {"yes", tv}, \
+ {"off", fv}, \
+ {"false", fv}, \
+ {"no", fv}
+
+/* ---------------------------------------- INTERFACES
+*/
+
+/* Parses a line. Returns TRUE if line parsed OK, otherwise returns FALSE.
+ ParseError() will return the reason for any failures.
+
+ Remember that it may be possible to get a line with no tokens.
+*/
+int ParseLine(Line *line, const char *source);
+
+
+/* Free up the dynamic parts of a tokenised line
+*/
+void ParseFree(Line *line);
+
+
+/* Returns a reason for the last failure.
+*/
+const char *ParseError(void);
+
+
+/* Return a value from a table. The check is done case insensitive. Returns
+ the value item, or NULL if not found.
+*/
+const ValueTable *ParseTable(const char *str, const ValueTable *table);
+
+
+/* Parse a true/false value from a built-in table. Returns def if the value is
+ invalid.
+
+ The mappings generated from YES_NO_ENTRIES(TRUE, FALSE) are used.
+};
+
+*/
+int ParseTrueFalse(const char *str, int def);
+
+
+/* Returns true if the passed text is in the passed NULL terminated array of
+ names.
+*/
+int ParseInTable(const char *str, const char *names[]);
+
+#endif
+
+/*
+vim: ai sw=4 ts=8 expandtab
+*/