Skip to content

Commit

Permalink
More C++ stuff. Don't try to compile the Node stuff yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Leung committed Feb 28, 2012
1 parent 0287c9a commit 0418884
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 58 deletions.
Empty file added src/document.cpp
Empty file.
12 changes: 12 additions & 0 deletions src/document.hpp
@@ -0,0 +1,12 @@
#include <vector>
#include "node.hpp"

namespace Sass {
struct Document {
using std::vector;

char* source;
unsigned int position;
vector<Node> statements;
};
}
Empty file added src/node.cpp
Empty file.
6 changes: 6 additions & 0 deletions src/node.hpp
@@ -0,0 +1,6 @@
#include <vector>
#include "token.hpp"

namespace Sass {
struct Node {

112 changes: 110 additions & 2 deletions src/prelexer.cpp
@@ -1,3 +1,4 @@
#include <cctype>
#include "prelexer.hpp"

namespace Sass {
Expand All @@ -7,11 +8,118 @@ namespace Sass {
char *epsilon(char *src) {
return src;
}

// Matches the empty string.
char *empty(char *src) {
return *src ? 0 : src;
}


// Match a single character satisfying the ctype predicates.
char* space(char* src) { return std::isspace(*src) ? src+1 : 0; }
char* alpha(char* src) { return std::isalpha(*src) ? src+1 : 0; }
char* digit(char* src) { return std::isdigit(*src) ? src+1 : 0; }
char* xdigit(char* src) { return std::isxdigit(*src) ? src+1 : 0; }
char* alnum(char* src) { return std::isalnum(*src) ? src+1 : 0; }
char* punct(char* src) { return std::ispunct(*src) ? src+1 : 0; }
// Match multiple ctype characters.
char* spaces(char* src) { return one_plus<space>(src); }
char* alphas(char* src) { return one_plus<alpha>(src); }
char* digits(char* src) { return one_plus<digit>(src); }
char* xdigits(char* src) { return one_plus<xdigit>(src); }
char* alnums(char* src) { return one_plus<alnum>(src); }
char* puncts(char* src) { return one_plus<punct>(src); }

// Match a line comment.
extern const char slash_slash[] = "//";
char* line_comment(char* src) { return to_endl<slash_slash>(src); }
// Match a block comment.
extern const char slash_star[] = "/*";
extern const char star_slash[] = "*/";
char* block_comment(char* src) {
return delimited_by<slash_star, star_slash, false>(src);
}
// Match double- and single-quoted strings.
char* double_quoted_string(char* src) {
return delimited_by<'"', '"', true>(src);
}
char* single_quoted_string(char* src) {
return delimited_by<'\'', '\'', true>(src);
}
char* string_constant(char* src) {
return alternatives<double_quoted_string, single_quoted_string>(src);
}
// Match interpolants.
extern const char hash_lbrace[] = "#{";
extern const char rbrace[] = "}";
char* interpolant(char* src) {
return delimited_by<hash_lbrace, rbrace, false>(src);
}

// Match CSS identifiers.
char* identifier(char* src) {
return sequence< optional< exactly<'-'> >,
alternatives< alpha, exactly<'_'> >,
zero_plus< alternatives< alnum,
exactly<'-'>,
exactly<'_'> > > >(src);
}
// Match CSS '@' keywords.
char* at_keyword(char* src) {
return sequence<exactly<'@'>, identifier>(src);
}
char* name(char* src) {
return one_plus< alternatives< alnum,
exactly<'-'>,
exactly<'_'> > >(src);
}
// Match CSS id names.
char* id_name(char* src) {
return sequence<exactly<'#'>, name>(src);
}
// Match CSS class names.
char* class_name(char* src) {
return sequence<exactly<'.'>, identifier>(src);
}
// Match CSS numeric constants.
extern const char sign[] = "-+";
char* unsigned_number(char* src) {
return alternatives<sequence< zero_plus<digits>,
exactly<'.'>,
one_plus<digits> >,
digits>(src);
}
char* number(char* src) {
return sequence< optional< class_char<sign> >, unsigned_number>(src);
}
char* percentage(char* src) {
return sequence< number, exactly<'%'> >(src);
}
char* dimension(char* src) {
return sequence<number, identifier>(src);
}
// Match CSS uri specifiers.
extern const char url_call[] = "url(";
char* uri(char* src) {
return sequence< exactly<url_call>,
optional<spaces>,
string_constant,
optional<spaces>,
exactly<')'> >(src);
}
// Match CSS function call openers.
char* function(char* src) {
return sequence< identifier, exactly<'('> >(src);
}
// Match CSS attribute-matching operators.
extern const char tilde_equal[] = "~=";
extern const char pipe_equal[] = "|=";
extern const char caret_equal[] = "^=";
extern const char dollar_equal[] = "$=";
extern const char star_equal[] = "*=";
char* exact_match(char* src) { return exactly<'='>(src); }
char* class_match(char* src) { return exactly<tilde_equal>(src); }
char* dash_match(char* src) { return exactly<pipe_equal>(src); }
char* prefix_match(char* src) { return exactly<caret_equal>(src); }
char* suffix_match(char* src) { return exactly<dollar_equal>(src); }
char* substring_match(char* src) { return exactly<star_equal>(src); }
}
}

0 comments on commit 0418884

Please sign in to comment.