]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[scan] Add parsing of line comments
authorCharlie Brej <cbrej@cs.man.ac.uk>
Mon, 22 Jun 2009 21:59:45 +0000 (22:59 +0100)
committerRay Strode <rstrode@redhat.com>
Fri, 24 Jul 2009 13:30:08 +0000 (09:30 -0400)
These are currently hard coded to '//' and '#'. The code is there to return
them to the caller but currently they are thrown away.
Should add a skip_comments option and allow customisable markers.

src/plugins/splash/script/ply-scan.c
src/plugins/splash/script/ply-scan.h
themes/script/script.script

index eb5e964333bcee20f033fb1c87802e1a53ac4239..348162f6d4ff34e18c582b58e4f8c7e2515e7a4b 100644 (file)
@@ -57,6 +57,7 @@ void ply_scan_token_clean(ply_scan_token_t* token)
         break;
     case PLY_SCAN_TOKEN_TYPE_IDENTIFIER:
     case PLY_SCAN_TOKEN_TYPE_STRING:
+    case PLY_SCAN_TOKEN_TYPE_COMMENT:
         free(token->data.string);
         break;
     }
@@ -100,7 +101,9 @@ unsigned char ply_scan_get_next_char(ply_scan_t* scan)
 
 void ply_scan_read_next_token(ply_scan_t* scan, ply_scan_token_t* token)
 {
- unsigned char curchar = ply_scan_get_current_char(scan);
+ unsigned char curchar = ply_scan_get_current_char(scan);       // FIXME Double check these unsigned chars are ok
+ unsigned char nextchar;
  token->whitespace = 0;
  while(true){
     if (curchar == ' ')  {curchar = ply_scan_get_next_char(scan); token->whitespace++; continue;}
@@ -191,10 +194,34 @@ void ply_scan_read_next_token(ply_scan_t* scan, ply_scan_token_t* token)
     return;
     }
  
+ nextchar = ply_scan_get_next_char(scan);
+    {
+    bool linecomment = false;
+    if (curchar == '#') linecomment = true;
+    if (curchar == '/' && nextchar == '/'){
+        linecomment = true;
+        nextchar = ply_scan_get_next_char(scan);
+        }
+    if (linecomment){
+        int index = 0;
+        token->data.string = malloc(sizeof(char));
+        token->data.string[0] = '\0';
+        curchar = nextchar;
+        for (curchar = nextchar; curchar != '\n' && curchar != '\0'; curchar = ply_scan_get_next_char(scan)){
+            token->data.string = realloc(token->data.string, (index+2)*sizeof(char));
+            token->data.string[index] = curchar;
+            token->data.string[index+1] = '\0';
+            index++;
+            }
+        token->type = PLY_SCAN_TOKEN_TYPE_COMMENT;
+        return;
+        }
+    }
  // all other
  token->type = PLY_SCAN_TOKEN_TYPE_SYMBOL;
  token->data.symbol = curchar;
- ply_scan_get_next_char(scan);
  return;
 }
 
@@ -214,7 +241,11 @@ static ply_scan_token_t* ply_scan_peek_token(ply_scan_t* scan, int n)
  if (scan->tokens[n]->type == PLY_SCAN_TOKEN_TYPE_EMPTY){
     if (n > 0 && scan->tokens[n-1]->type == PLY_SCAN_TOKEN_TYPE_EMPTY)
         ply_scan_peek_token(scan, n-1);
-    ply_scan_read_next_token(scan, scan->tokens[n]);
+    do {
+        ply_scan_token_clean(scan->tokens[n]);
+        ply_scan_read_next_token(scan, scan->tokens[n]);                        // FIXME if skipping comments, add whitespace to next token
+        }
+    while (scan->tokens[n]->type == PLY_SCAN_TOKEN_TYPE_COMMENT);               // FIXME optionally pass comments back
 //     printf("%d:", n);
 //     switch (scan->tokens[n]->type){
 //         case PLY_SCAN_TOKEN_TYPE_STRING:
index bf5bdb919f8e8129b567392cfda485034d684ec4..01bb449b2adf6a218862c91d8bd8f6bebb6b23df 100644 (file)
@@ -13,6 +13,7 @@ typedef enum
  PLY_SCAN_TOKEN_TYPE_IDENTIFIER,
  PLY_SCAN_TOKEN_TYPE_STRING,
  PLY_SCAN_TOKEN_TYPE_SYMBOL,
+ PLY_SCAN_TOKEN_TYPE_COMMENT,
 } ply_scan_token_type_t;
 
 typedef struct
index 3eef2f3570846a94a3473187042bcd6984c7f5fe..754140b004aa0600d77019852e630773846d7844 100644 (file)
@@ -45,4 +45,7 @@ fun refresh (){
     return;
     }
 
+// This is a comment
+# As is this (both are acceptable because people do forget which to use)
+
 PlymouthSetRefreshFunction(refresh);