Commit 7d0e4fb5 by Aaron Leung

Some parsing stuff. Currently broken.

parent 0a07ffd1
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
#define CONTEXT_HEADER #define CONTEXT_HEADER
/*
Probably gonna' need to stratify this a bit more. A context object will store
the symbol table and any other necessary project-wide info. Each sass_document
struct will store src strings, line counts, etc.
*/
typedef struct { typedef struct {
char *path; /* the full directory+filename of the source file */ char *path; /* the full directory+filename of the source file */
......
#include "parser.h"
#include <stdlib.h> #include <stdlib.h>
#include "parser.h"
#include "prefix.h"
DEFINE_SASS_ARRAY_OF(sass_node_ptr);
sass_token sass_make_token(int lexeme, char *beg, char *end) {
sass_token t;
t.lexeme = lexeme;
t.beg = beg;
t.end = end;
return t;
}
int sass_parse(sass_context *ctx) { int sass_parse(sass_context *ctx) {
sass_document *doc = (sass_document*)malloc(sizeof(sass_document)); sass_document *doc = (sass_document*)malloc(sizeof(sass_document));
doc->src = ctx->src; doc->src = ctx->src;
return 0; return 0;
}
sass_sass_node_ptr_array sass_parse(sass_context *ctx) {
/* not sure how big of an array to allocate by default */
sass_sass_node_ptr_array statements = sass_make_sass_node_ptr_array(16);
while (ctx->*p) sass_sass_node_ptr_array_push(statements, sass_parse_statement(ctx));
return statements;
}
static sass_node_ptr sass_parse_statement(sass_context *ctx) {
/* currently only handles rulesets; will expand to handle atkeywords */
return sass_parse_ruleset(ctx);
}
static sass_node_ptr sass_parse_ruleset(sass_context *ctx) {
sass_node_ptr selector = sass_parse_selector(ctx);
sass_node_ptr declarations = sass_parse_declarations(ctx);
return sass_make_node(RULESET, selector, declarations);
}
static sass_node_ptr sass_parse_selector(sass_context *ctx) {
/* will eventually need to be much more complicated */
char *lbrace = sass_prefix_find_first(ctx->pos, sass_prefix_is_lbrace);
sass_node_ptr node = sass_make_node(SELECTOR);
node->token = sass_make_token(SELECTOR, pos, lbrace);
ctx->pos = lbrace;
return node;
} }
\ No newline at end of file
...@@ -2,5 +2,35 @@ ...@@ -2,5 +2,35 @@
#ifndef CONTEXT_HEADER #ifndef CONTEXT_HEADER
#include "context.h" #include "context.h"
#endif #endif
#include "array.h"
enum {
IDENT,
ATKEYWORD,
STRING,
IDNAME,
CLASSNAME,
NUMBER,
PERCENTAGE,
DIMENSION,
URI,
SPACES,
COMMENT,
FUNCTION,
EXACTMATCH,
INCLUDES,
DASHMATCH,
PREFIXMATCH,
SUFFIXMATCH,
SUBSTRINGMATCH
};
typedef struct {
int lexeme;
char *beg;
char *end;
} Token;
#define sass_peek_token(src, lexeme) (sass_prefix_is_ ## lexeme(src))
int sass_parse(sass_context *ctx); int sass_parse(sass_context *ctx);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment