Change tagline, fix comments

This commit is contained in:
Alex Palaistras 2016-03-09 22:36:57 +00:00
parent 15d6669097
commit 19f2f5b514
7 changed files with 73 additions and 12 deletions

14
.editorconfig Normal file
View File

@ -0,0 +1,14 @@
# Code styles for Fawkss.
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View File

@ -88,20 +88,27 @@ test-after:
@printf ">> $(BOLD)Finished executing tests.$(RESET)\n"
$(TESTS):
# Generate temporary test files from concatenated original.
@awk "/--- TEST ---/ {f=1;next} /--- EXPECTED ---/ {exit} f" $@ >> $@.test.$(TMPPID)
@awk "/--- EXPECTED ---/ {f=1;next} /--- END ---/ {exit} f" $@ >> $@.expected.$(TMPPID)
# Calculate time and execute Fawkss with test file.
$(eval ts = $(shell date +"%s%3N"))
@$(FAWKSS) $@.test.$(TMPPID) > $@.actual.$(TMPPID)
@printf ">> $(BOLD)Testing file '$@'...$(RESET) "
$(eval te = $(shell date +"%s%3N"))
# Generate diff between expected and actual results and print back to user.
@result=$$($(DIFF) -ud $@.actual.$(TMPPID) $@.expected.$(TMPPID) | tail -n +3); \
if [ -z "$${result}" ]; then \
printf "$(GREEN)OK$(RESET)\n"; \
tt=`echo "$(ts) $(te)" | awk '{printf "(%.3fs)\n", (($$2-$$1)/1000)}'`; \
printf ">> $(BOLD)Testing file '$@'...$(RESET) "; \
if [ -z "$$result" ]; then \
printf "$(GREEN)OK$(RESET) $$tt\n"; \
else \
printf "$(RED)FAIL$(RESET)\n"; \
echo "$${result}"; \
echo "$$result"; \
fi \
# Clean up temporary files.
@rm -f $@.test.$(TMPPID) $@.expected.$(TMPPID) $@.actual.$(TMPPID)
## Show usage information for this Makefile.

View File

@ -1,4 +1,4 @@
# Fawkss — The simple CSS preprocessor [![MIT License][license-svg]][license-url]
# Fawkss — The [ig]noble CSS preprocessor [![MIT License][license-svg]][license-url]
Fawkss [fɔːks] is a simple CSS preprocessor built as a single AWK (nawk/gawk/mawk) script. Syntactically, it borrows as much as possible from the SASS language, for convenience and familiarity.
@ -8,10 +8,10 @@ This is more of a fun project than a production-ready piece of software, though
Currently, the following features are implemented:
* C99/C++-style comments (.i.e. `// This is a comment`)
* C99/C++-style comments (i.e. `// This is a comment`)
* Variables
A full test-suite is provided (depending only on Bash and AWK), which should serve as a good example of the existing feature-set.
A full test-suite is provided (depending only on `make` and `awk`), which should serve as a good example of the existing feature-set.
## Roadmap
@ -19,6 +19,10 @@ It is intended that the script never balloons to more than ~1000 lines of code.
That being said, I do not plan to implement any context-sensitive functionality (such as nesting etc.), which may be nigh-impossible in AWK anyways. Consider it a feature.
## Testing & Documentation
A `Makefile` is provided for running tests and producing documentation for Fawkss. Run `make help` in the project root for more information.
## Are you kidding me?
Nope. I wouldn't suggest you actually use this for anything, though.

16
fawkss
View File

@ -1,7 +1,7 @@
#!/usr/bin/awk -f
#
# Fawkss — The simple CSS preprocessor.
# =====================================
# Fawkss — The [ig]noble CSS preprocessor.
# ========================================
#
# Fawkss is a CSS preprocessor for people who dislike CSS preprocessors. It
# implements a subset of the SCSS syntax while remaining relatively simple.
@ -37,6 +37,12 @@ function trim(str, chars) {
return substr(str, RSTART, RLENGTH)
}
# > Function `file_exists` checks if file pointed to by `filename` exists, and
# > returns `1` if true, `0` if false.
function file_exists(filename) {
return (system("[ -e '" filename "' ]") == 0) ? 1 : 0;
}
# Initialization
# --------------
#
@ -76,7 +82,7 @@ $0 ~ rules["variable-define"] {
name = trim(substr(token[1], index(token[1], "$")))
value = trim(substr(token[2], 0, lastindex(token[2], ";") - 1))
# Assign variable to global variables table.
# Assign variable to the global variables table.
variables[name] = value
next
}
@ -94,7 +100,7 @@ $0 ~ rules["variable-define"] {
# > :root{background: white;} // Another inline comment.
# >
# > As opposed to regular CSS comments (i.e. `/* */`), inline comments are removed
# > from the processed result. Inline comments inside string are not removed.
# > from the processed result. Inline comments inside strings are not removed.
$0 ~ rules["comment"] {
# Remove any special cases from the line.
while (match($0, rules["comment-exception"])) {
@ -149,7 +155,7 @@ $0 ~ rules["variable-name"] {
# -------------
#
# This block contains line-printing rules, for results generated in the above
# blocks.
# blocks.
#
# > Match empty line. Consecutive empty lines do not print, and are instead
# > squashed down to a single line.

21
tests/03-includes.scss Normal file
View File

@ -0,0 +1,21 @@
//
// Simple include tests for Fawkss.
//
--- TEST ---
@include "includes/partial"
@include "includes/full.scss"
--- EXPECTED ---
.partial {
content: 'This is a partial';
}
.full {
content: 'This is a full include';
color: white;
}
--- END ---

View File

@ -0,0 +1,5 @@
$col-white: #fff;
.partial {
content: 'This is a partial';
}

4
tests/includes/full.scss Normal file
View File

@ -0,0 +1,4 @@
.full {
content: 'This is a full include';
color $col-white;
}