Mesa (master): glsl/s_expression: Read and ignore Scheme-style comments.
Kenneth Graunke
kwg at kemper.freedesktop.org
Thu Jan 13 08:11:17 UTC 2011
Module: Mesa
Branch: master
Commit: 47b2af2c62fec3ac0fb501a31e93fc8d00c18cb8
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=47b2af2c62fec3ac0fb501a31e93fc8d00c18cb8
Author: Kenneth Graunke <kenneth at whitecape.org>
Date: Sat Jan 1 12:43:03 2011 -0800
glsl/s_expression: Read and ignore Scheme-style comments.
A single-semicolon until the end of the line, i.e.
; this is a comment.
---
src/glsl/s_expression.cpp | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/glsl/s_expression.cpp b/src/glsl/s_expression.cpp
index 852a049..6edbf62 100644
--- a/src/glsl/s_expression.cpp
+++ b/src/glsl/s_expression.cpp
@@ -38,15 +38,25 @@ s_list::s_list()
{
}
+static void
+skip_whitespace(const char *& src)
+{
+ src += strspn(src, " \v\t\r\n");
+ /* Also skip Scheme-style comments: semi-colon 'til end of line */
+ if (src[0] == ';') {
+ src += strcspn(src, "\n");
+ skip_whitespace(src);
+ }
+}
+
static s_expression *
read_atom(void *ctx, const char *& src)
{
s_expression *expr = NULL;
- // Skip leading spaces.
- src += strspn(src, " \v\t\r\n");
+ skip_whitespace(src);
- size_t n = strcspn(src, "( \v\t\r\n)");
+ size_t n = strcspn(src, "( \v\t\r\n);");
if (n == 0)
return NULL; // no atom
@@ -80,8 +90,7 @@ s_expression::read_expression(void *ctx, const char *&src)
if (atom != NULL)
return atom;
- // Skip leading spaces.
- src += strspn(src, " \v\t\r\n");
+ skip_whitespace(src);
if (src[0] == '(') {
++src;
@@ -91,7 +100,7 @@ s_expression::read_expression(void *ctx, const char *&src)
while ((expr = read_expression(ctx, src)) != NULL) {
list->subexpressions.push_tail(expr);
}
- src += strspn(src, " \v\t\r\n");
+ skip_whitespace(src);
if (src[0] != ')') {
printf("Unclosed expression (check your parenthesis).\n");
return NULL;
More information about the mesa-commit
mailing list