pax_global_header 0000666 0000000 0000000 00000000064 13557420656 0014527 g ustar 00root root 0000000 0000000 52 comment=e1c16e09b4a953757a15149deaaf28a3fd81dc97
libsass-3.6.3/ 0000775 0000000 0000000 00000000000 13557420656 0013200 5 ustar 00root root 0000000 0000000 libsass-3.6.3/.editorconfig 0000664 0000000 0000000 00000000442 13557420656 0015655 0 ustar 00root root 0000000 0000000 # This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
root = true
[*]
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2
[{Makefile,GNUmakefile.am}]
indent_style = tab
indent_size = 4
libsass-3.6.3/.gitattributes 0000664 0000000 0000000 00000000102 13557420656 0016064 0 ustar 00root root 0000000 0000000 # Auto detect text files and perform LF normalization
* text=auto
libsass-3.6.3/.github/ 0000775 0000000 0000000 00000000000 13557420656 0014540 5 ustar 00root root 0000000 0000000 libsass-3.6.3/.github/CONTRIBUTING.md 0000664 0000000 0000000 00000007202 13557420656 0016772 0 ustar 00root root 0000000 0000000 # Contributing to LibSass
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
The following is a set of guidelines for contributing to LibSass, which is hosted in the [Sass Organization](https://github.com/sass) on GitHub.
These are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request.
LibSass is a library that implements a [sass language][8] compiler. As such it does not directly interface with end users (frontend developers).
For direct contributions to the LibSass code base you will need to have at least a rough idea of C++, we will not lie about that.
But there are other ways to contribute to the progress of LibSass. All contributions are done via github pull requests.
You can also contribute to the LibSass [documentation][9] or provide additional [spec tests][10] (and we will gladly point you in the
direction for corners that lack test coverage). Foremost we rely on good and concise bug reports for issues the spec tests do not yet catch.
## Precheck: My Sass isn't compiling
- [ ] Check if you can reproduce the issue via [SourceMap Inspector][5] (updated regularly).
- [ ] Validate official ruby sass compiler via [SassMeister][6] produces your expected result.
- [ ] Search for similar issue in [LibSass][1] and [node-sass][2] (include closed tickets)
- [ ] Optionally test your code directly with [sass][7] or [sassc][3] ([installer][4])
## Precheck: My build/install fails
- [ ] Problems with building or installing libsass should be directed to implementors first!
- [ ] Except for issues directly verified via sassc or LibSass own build (make/autotools9
## Craft a meaningfull error report
- [ ] Include the version of libsass and the implementor (i.e. node-sass or sassc)
- [ ] Include information about your operating system and environment (i.e. io.js)
- [ ] Either create a self contained sample that shows your issue ...
- [ ] ... or provide it as a fetchable (github preferred) archive/repo
- [ ] ... and include a step by step list of command to get all dependencies
- [ ] Make it clear if you use indented or/and scss syntax
## My error is hiding in a big code base
1. we do not have time to support your code base!
2. to fix occurring issues we need precise bug reports
3. the more precise you are, the faster we can help you
4. lazy reports get overlooked even when exposing serious bugs
5. it's not hard to do, it only takes time
- [ ] Make sure you saved the current state (i.e. commit to git)
- [ ] Start by uncommenting blocks in the initial source file
- [ ] Check if the problem is still there after each edit
- [ ] Repeat until the problem goes away
- [ ] Inline imported files as you go along
- [ ] Finished once you cannot remove more
- [ ] The emphasis is on the word "repeat" ...
## What makes a code test case
Important is that someone else can get the test case up and running to reproduce it locally. For this
we urge you to verify that your sample yields the expected result by testing it via [SassMeister][6]
or directly via ruby sass or node-sass (or any other libsass implementor) before submitting your bug
report. Once you verified all of the above, you may use the template below to file your bug report.
[1]: https://github.com/sass/libsass/issues?utf8=%E2%9C%93&q=is%3Aissue
[2]: https://github.com/sass/node-sass/issues?utf8=%E2%9C%93&q=is%3Aissue
[3]: https://github.com/sass/sassc
[4]: http://libsass.ocbnet.ch/installer/
[5]: http://libsass.ocbnet.ch/srcmap/
[6]: http://www.sassmeister.com/
[7]: https://rubygems.org/gems/sass
[8]: https://sass-lang.com/
[9]: https://github.com/sass/libsass/tree/master/docs
[10]: https://github.com/sass/sass-spec
libsass-3.6.3/.github/ISSUE_TEMPLATE.md 0000664 0000000 0000000 00000002053 13557420656 0017245 0 ustar 00root root 0000000 0000000 [todo]: # (Title: Be as meaningful as possible)
[todo]: # (Title: Try to use 60 or less chars)
[todo]: # (This is only a template!)
[todo]: # (remove unneeded bits)
[todo]: # (use github preview!)
## input.scss
[todo]: # (always test and report with scss syntax)
[todo]: # (use sass only when results differ from scss)
```scss
test {
content: bar
}
```
## Actual results
[todo]: # (update version info!)
[libsass 3.X.y][1]
```css
test {
content: bar; }
```
## Expected result
[todo]: # (update version info!)
ruby sass 3.X.y
```css
test {
content: bar; }
```
[todo]: # (update version info!)
[todo]: # (example for node-sass!)
version info:
```cmd
$ node-sass --version
node-sass 3.X.y (Wrapper) [JavaScript]
libsass 3.X.y (Sass Compiler) [C/C++]
```
[todo]: # (Go to http://libsass.ocbnet.ch/srcmap)
[todo]: # (Enter your SCSS code and hit compile)
[todo]: # (Click `bookmark` and replace the url)
[todo]: # (link is used in actual results above)
[1]: http://libsass.ocbnet.ch/srcmap/#dGVzdCB7CiAgY29udGVudDogYmFyOyB9Cg==
libsass-3.6.3/.gitignore 0000664 0000000 0000000 00000002035 13557420656 0015170 0 ustar 00root root 0000000 0000000 # Miscellaneous stuff
/sassc
/sass-spec
/plugins/
VERSION
.DS_Store
.sass-cache
*.gem
*.gcno
.svn/*
.cproject
.project
.settings/
*.db
*.aps
# Configuration stuff
GNUmakefile.in
GNUmakefile
/aclocal.m4
/autom4te.cache/
/src/config.h
/config.h.in
/config.log
/config.status
/configure
/libtool
/m4/libtool.m4
/m4/ltoptions.m4
/m4/ltsugar.m4
/m4/ltversion.m4
/m4/lt~obsolete.m4
/script/ar-lib
/script/compile
/script/config.guess
/script/config.sub
/script/depcomp
/script/install-sh
/script/ltmain.sh
/script/missing
/script/test-driver
/src/stamp-h1
/src/Makefile.in
/src/Makefile
libsass/*
# Build stuff
*.o
*.lo
*.so
*.dll
*.a
*.suo
*.sdf
*.opendb
*.opensdf
a.out
libsass.js
tester
tester.exe
build/
config.h.in*
lib/pkgconfig/
bin/*
.deps/
.libs/
win/bin
*.user
win/*.db
# Final results
sassc++
libsass.la
src/support/libsass.pc
# Cloned testing dirs
sassc/
sass-spec/
installer/
# Visual Studio cache directory
.vs/
# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
libsass-3.6.3/.travis.yml 0000664 0000000 0000000 00000004041 13557420656 0015310 0 ustar 00root root 0000000 0000000 language: cpp
# ASan needs ptrace support which currently requires `sudo: required`.
# See https://github.com/travis-ci/travis-ci/issues/9033.
sudo: required
# don't create redundant code coverage reports
# - AUTOTOOLS=yes COVERAGE=yes BUILD=static
# - AUTOTOOLS=no COVERAGE=yes BUILD=shared
# - AUTOTOOLS=no COVERAGE=no BUILD=static
# further speed up day by day travis-ci builds
# re-enable this if you change the makefiles
# this will still catch all coding errors!
# - AUTOTOOLS=yes COVERAGE=no BUILD=static
# currently there are various issues when
# built with coverage, clang and autotools
# - AUTOTOOLS=yes COVERAGE=yes BUILD=shared
matrix:
include :
- os: linux
compiler: gcc
env: AUTOTOOLS=no COVERAGE=yes BUILD=static
- os: linux
compiler: g++-5
env: AUTOTOOLS=yes COVERAGE=no BUILD=shared
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
- os: linux
compiler: g++-8
env: AUTOTOOLS=yes COVERAGE=no BUILD=shared
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-8
- os: linux
compiler: clang
# This build runs with ASan and we set `detect_odr_violation=0`
# to work around https://bugs.llvm.org/show_bug.cgi?id=37545.
env: AUTOTOOLS=no COVERAGE=no BUILD=static ASAN_OPTIONS=detect_odr_violation=0
- os: linux
compiler: clang
env: AUTOTOOLS=yes COVERAGE=no BUILD=shared
- os: osx
compiler: clang
env: AUTOTOOLS=no COVERAGE=no BUILD=shared
- os: osx
compiler: clang
env: AUTOTOOLS=no COVERAGE=no BUILD=static
- os: osx
compiler: clang
env: AUTOTOOLS=yes COVERAGE=no BUILD=shared
script:
- ./script/ci-build-libsass
- ./script/ci-build-plugin math
- ./script/ci-build-plugin glob
- ./script/ci-build-plugin digest
- ./script/ci-build-plugin tests
before_install: ./script/ci-install-deps
install: ./script/ci-install-compiler
after_success: ./script/ci-report-coverage
libsass-3.6.3/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000001031 13557420656 0015772 0 ustar 00root root 0000000 0000000 Sass is more than a technology; Sass is driven by the community of individuals
that power its development and use every day. As a community, we want to embrace
the very differences that have made our collaboration so powerful, and work
together to provide the best environment for learning, growing, and sharing of
ideas. It is imperative that we keep Sass a fun, welcoming, challenging, and
fair place to play.
[The full community guidelines can be found on the Sass website.][link]
[link]: https://sass-lang.com/community-guidelines
libsass-3.6.3/COPYING 0000664 0000000 0000000 00000002334 13557420656 0014235 0 ustar 00root root 0000000 0000000
Copyright (C) 2012 by Hampton Catlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The following files in the spec were taken from the original Ruby Sass project which
is copyright Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein and under
the same license.
libsass-3.6.3/GNUmakefile.am 0000664 0000000 0000000 00000003402 13557420656 0015645 0 ustar 00root root 0000000 0000000 ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4 -I script
AM_COPT = -Wall -O2
AM_COVLDFLAGS =
if ENABLE_COVERAGE
AM_COPT = -Wall -O1 -fno-omit-frame-pointer --coverage
AM_COVLDFLAGS += -lgcov
endif
AM_CPPFLAGS = -I$(top_srcdir)/include
AM_CFLAGS = $(AM_COPT)
AM_CXXFLAGS = $(AM_COPT)
AM_LDFLAGS = $(AM_COPT) $(AM_COVLDFLAGS)
# only needed to support old source tree
# we have moved the files to src folder
AM_CPPFLAGS += -I$(top_srcdir)
RESOURCES =
AM_CXXFLAGS += -std=c++11
if COMPILER_IS_MINGW32
RESOURCES += res/libsass.rc
endif
TEST_EXTENSIONS = .rb
if ENABLE_TESTS
SASS_SASSC_PATH ?= $(top_srcdir)/sassc
SASS_SPEC_PATH ?= $(top_srcdir)/sass-spec
noinst_PROGRAMS = tester
tester_LDADD = src/libsass.la
tester_LDFLAGS = $(AM_LDFLAGS)
nodist_tester_SOURCES = $(SASS_SASSC_PATH)/sassc.c
SASS_SASSC_VERSION ?= `cd "$(SASS_SASSC_PATH)" && ./version.sh`
tester_CFLAGS = $(AM_CFLAGS) -DSASSC_VERSION="\"$(SASS_SASSC_VERSION)\""
tester_CXXFLAGS = $(AM_CXXFLAGS) -DSASSC_VERSION="\"$(SASS_SASSC_VERSION)\""
if ENABLE_COVERAGE
nodist_EXTRA_tester_SOURCES = non-existent-file-to-force-CXX-linking.cxx
endif
TESTS = $(SASS_SPEC_PATH)/sass-spec.rb
RB_LOG_COMPILER = ./script/tap-runner
AM_RB_LOG_FLAGS = $(RUBY)
SASS_TEST_FLAGS = --impl libsass
SASS_TEST_FLAGS += -r $(SASS_SPEC_PATH)
SASS_TEST_FLAGS += -c $(top_srcdir)/tester$(EXEEXT)
AM_TESTS_ENVIRONMENT = TEST_FLAGS='$(SASS_TEST_FLAGS)'
SASS_TESTER = $(RUBY) $(SASS_SPEC_PATH)/sass-spec.rb
test:
$(SASS_TESTER) $(SASS_TEST_FLAGS)
test_build:
$(SASS_TESTER) $(SASS_TEST_FLAGS)
test_full:
$(SASS_TESTER) --run-todo $(SASS_TEST_FLAGS)
test_probe:
$(SASS_TESTER) --probe-todo $(SASS_TEST_FLAGS)
test_interactive:
$(SASS_TESTER) --interactive $(SASS_TEST_FLAGS)
.PHONY: test test_build test_full test_probe
endif
SUBDIRS = src
libsass-3.6.3/INSTALL 0000664 0000000 0000000 00000000061 13557420656 0014226 0 ustar 00root root 0000000 0000000 // Autotools requires us to have this file. Boo.
libsass-3.6.3/LICENSE 0000664 0000000 0000000 00000002362 13557420656 0014210 0 ustar 00root root 0000000 0000000
Copyright (C) 2012-2016 by the Sass Open Source Foundation
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The following files in the spec were taken from the original Ruby Sass project which
is copyright Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein and under
the same license.
libsass-3.6.3/Makefile 0000664 0000000 0000000 00000020624 13557420656 0014644 0 ustar 00root root 0000000 0000000 OS ?= $(shell uname -s)
CC ?= cc
CXX ?= c++
RM ?= rm -f
CP ?= cp -a
MKDIR ?= mkdir
RMDIR ?= rmdir
WINDRES ?= windres
# Solaris/Illumos flavors
# ginstall from coreutils
ifeq ($(OS),SunOS)
INSTALL ?= ginstall
endif
INSTALL ?= install
CFLAGS ?= -Wall
CXXFLAGS ?= -Wall
LDFLAGS ?= -Wall
ifndef COVERAGE
CFLAGS += -O2
CXXFLAGS += -O2
LDFLAGS += -O2
else
CFLAGS += -O1 -fno-omit-frame-pointer
CXXFLAGS += -O1 -fno-omit-frame-pointer
LDFLAGS += -O1 -fno-omit-frame-pointer
endif
CAT ?= $(if $(filter $(OS),Windows_NT),type,cat)
ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
else
ifneq (,$(findstring Windows_NT,$(OS)))
UNAME := Windows
else
ifneq (,$(findstring mingw32,$(MAKE)))
UNAME := Windows
else
ifneq (,$(findstring MINGW32,$(shell uname -s)))
UNAME := Windows
else
UNAME := $(shell uname -s)
endif
endif
endif
endif
ifndef LIBSASS_VERSION
ifneq ($(wildcard ./.git/ ),)
LIBSASS_VERSION ?= $(shell git describe --abbrev=4 --dirty --always --tags)
endif
ifneq ($(wildcard VERSION),)
LIBSASS_VERSION ?= $(shell $(CAT) VERSION)
endif
endif
ifdef LIBSASS_VERSION
CFLAGS += -DLIBSASS_VERSION="\"$(LIBSASS_VERSION)\""
CXXFLAGS += -DLIBSASS_VERSION="\"$(LIBSASS_VERSION)\""
endif
CXXFLAGS += -std=c++11
LDFLAGS += -std=c++11
ifeq (Windows,$(UNAME))
ifneq ($(BUILD),shared)
STATIC_ALL ?= 1
endif
STATIC_LIBGCC ?= 1
STATIC_LIBSTDCPP ?= 1
else
STATIC_ALL ?= 0
STATIC_LIBGCC ?= 0
STATIC_LIBSTDCPP ?= 0
endif
ifndef SASS_LIBSASS_PATH
SASS_LIBSASS_PATH = $(CURDIR)
endif
ifdef SASS_LIBSASS_PATH
CFLAGS += -I $(SASS_LIBSASS_PATH)/include
CXXFLAGS += -I $(SASS_LIBSASS_PATH)/include
else
# this is needed for mingw
CFLAGS += -I include
CXXFLAGS += -I include
endif
CFLAGS += $(EXTRA_CFLAGS)
CXXFLAGS += $(EXTRA_CXXFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
LDLIBS = -lm
ifneq ($(BUILD),shared)
ifneq ($(STATIC_LIBSTDCPP),1)
LDLIBS += -lstdc++
endif
endif
# link statically into lib
# makes it a lot more portable
# increases size by about 50KB
ifeq ($(STATIC_ALL),1)
LDFLAGS += -static
endif
ifeq ($(STATIC_LIBGCC),1)
LDFLAGS += -static-libgcc
endif
ifeq ($(STATIC_LIBSTDCPP),1)
LDFLAGS += -static-libstdc++
endif
ifeq ($(UNAME),Darwin)
CFLAGS += -stdlib=libc++
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
endif
ifneq (Windows,$(UNAME))
ifneq (FreeBSD,$(UNAME))
ifneq (OpenBSD,$(UNAME))
LDFLAGS += -ldl
LDLIBS += -ldl
endif
endif
endif
ifneq ($(BUILD),shared)
BUILD := static
endif
ifeq ($(DEBUG),1)
BUILD := debug-$(BUILD)
endif
ifndef TRAVIS_BUILD_DIR
ifeq ($(OS),SunOS)
PREFIX ?= /opt/local
else
PREFIX ?= /usr/local
endif
else
PREFIX ?= $(TRAVIS_BUILD_DIR)
endif
SASS_SASSC_PATH ?= sassc
SASS_SPEC_PATH ?= sass-spec
SASS_SPEC_SPEC_DIR ?= spec
SASSC_BIN = $(SASS_SASSC_PATH)/bin/sassc
RUBY_BIN = ruby
RESOURCES =
STATICLIB = lib/libsass.a
SHAREDLIB = lib/libsass.so
LIB_STATIC = $(SASS_LIBSASS_PATH)/lib/libsass.a
LIB_SHARED = $(SASS_LIBSASS_PATH)/lib/libsass.so
ifeq ($(UNAME),Darwin)
SHAREDLIB = lib/libsass.dylib
LIB_SHARED = $(SASS_LIBSASS_PATH)/lib/libsass.dylib
endif
ifeq (Windows,$(UNAME))
SASSC_BIN = $(SASS_SASSC_PATH)/bin/sassc.exe
RESOURCES += res/resource.rc
SHAREDLIB = lib/libsass.dll
ifeq (shared,$(BUILD))
CFLAGS += -D ADD_EXPORTS
CXXFLAGS += -D ADD_EXPORTS
LIB_SHARED = $(SASS_LIBSASS_PATH)/lib/libsass.dll
endif
else
ifneq (Cygwin,$(UNAME))
CFLAGS += -fPIC
CXXFLAGS += -fPIC
LDFLAGS += -fPIC
endif
endif
include Makefile.conf
OBJECTS = $(addprefix src/,$(SOURCES:.cpp=.o))
COBJECTS = $(addprefix src/,$(CSOURCES:.c=.o))
RCOBJECTS = $(RESOURCES:.rc=.o)
DEBUG_LVL ?= NONE
CLEANUPS ?=
CLEANUPS += $(RCOBJECTS)
CLEANUPS += $(COBJECTS)
CLEANUPS += $(OBJECTS)
CLEANUPS += $(LIBSASS_LIB)
all: $(BUILD)
debug: $(BUILD)
debug-static: LDFLAGS := -g $(filter-out -O2,$(LDFLAGS))
debug-static: CFLAGS := -g -DDEBUG -DDEBUG_LVL="$(DEBUG_LVL)" $(filter-out -O2,$(CFLAGS))
debug-static: CXXFLAGS := -g -DDEBUG -DDEBUG_LVL="$(DEBUG_LVL)" $(filter-out -O2,$(CXXFLAGS))
debug-static: static
debug-shared: LDFLAGS := -g $(filter-out -O2,$(LDFLAGS))
debug-shared: CFLAGS := -g -DDEBUG -DDEBUG_LVL="$(DEBUG_LVL)" $(filter-out -O2,$(CFLAGS))
debug-shared: CXXFLAGS := -g -DDEBUG -DDEBUG_LVL="$(DEBUG_LVL)" $(filter-out -O2,$(CXXFLAGS))
debug-shared: shared
lib:
$(MKDIR) lib
lib/libsass.a: $(COBJECTS) $(OBJECTS) | lib
$(AR) rcvs $@ $(COBJECTS) $(OBJECTS)
lib/libsass.so: $(COBJECTS) $(OBJECTS) | lib
$(CXX) -shared $(LDFLAGS) -o $@ $(COBJECTS) $(OBJECTS) $(LDLIBS)
lib/libsass.dylib: $(COBJECTS) $(OBJECTS) | lib
$(CXX) -shared $(LDFLAGS) -o $@ $(COBJECTS) $(OBJECTS) $(LDLIBS) \
-install_name @rpath/libsass.dylib
lib/libsass.dll: $(COBJECTS) $(OBJECTS) $(RCOBJECTS) | lib
$(CXX) -shared $(LDFLAGS) -o $@ $(COBJECTS) $(OBJECTS) $(RCOBJECTS) $(LDLIBS) \
-s -Wl,--subsystem,windows,--out-implib,lib/libsass.a
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.rc
$(WINDRES) -i $< -o $@
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
%: %.o static
$(CXX) $(CXXFLAGS) -o $@ $+ $(LDFLAGS) $(LDLIBS)
install: install-$(BUILD)
static: $(STATICLIB)
shared: $(SHAREDLIB)
$(DESTDIR)$(PREFIX):
$(MKDIR) $(DESTDIR)$(PREFIX)
$(DESTDIR)$(PREFIX)/lib: | $(DESTDIR)$(PREFIX)
$(MKDIR) $(DESTDIR)$(PREFIX)/lib
$(DESTDIR)$(PREFIX)/include: | $(DESTDIR)$(PREFIX)
$(MKDIR) $(DESTDIR)$(PREFIX)/include
$(DESTDIR)$(PREFIX)/include/sass: | $(DESTDIR)$(PREFIX)/include
$(MKDIR) $(DESTDIR)$(PREFIX)/include/sass
$(DESTDIR)$(PREFIX)/include/%.h: include/%.h \
| $(DESTDIR)$(PREFIX)/include/sass
$(INSTALL) -v -m0644 "$<" "$@"
install-headers: $(DESTDIR)$(PREFIX)/include/sass.h \
$(DESTDIR)$(PREFIX)/include/sass2scss.h \
$(DESTDIR)$(PREFIX)/include/sass/base.h \
$(DESTDIR)$(PREFIX)/include/sass/version.h \
$(DESTDIR)$(PREFIX)/include/sass/values.h \
$(DESTDIR)$(PREFIX)/include/sass/context.h \
$(DESTDIR)$(PREFIX)/include/sass/functions.h
$(DESTDIR)$(PREFIX)/lib/%.a: lib/%.a \
| $(DESTDIR)$(PREFIX)/lib
@$(INSTALL) -v -m0755 "$<" "$@"
$(DESTDIR)$(PREFIX)/lib/%.so: lib/%.so \
| $(DESTDIR)$(PREFIX)/lib
@$(INSTALL) -v -m0755 "$<" "$@"
$(DESTDIR)$(PREFIX)/lib/%.dll: lib/%.dll \
| $(DESTDIR)$(PREFIX)/lib
@$(INSTALL) -v -m0755 "$<" "$@"
$(DESTDIR)$(PREFIX)/lib/%.dylib: lib/%.dylib \
| $(DESTDIR)$(PREFIX)/lib
@$(INSTALL) -v -m0755 "$<" "$@"
install-static: $(DESTDIR)$(PREFIX)/lib/libsass.a
install-shared: $(DESTDIR)$(PREFIX)/$(SHAREDLIB) \
install-headers
$(SASSC_BIN): $(BUILD)
$(MAKE) -C $(SASS_SASSC_PATH) build-$(BUILD)
sassc: $(SASSC_BIN)
$(SASSC_BIN) -v
version: $(SASSC_BIN)
$(SASSC_BIN) -v
test: test_build
test_build: $(SASSC_BIN)
$(RUBY_BIN) $(SASS_SPEC_PATH)/sass-spec.rb -c $(SASSC_BIN) --impl libsass \
--cmd-args "-I $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)" \
$(LOG_FLAGS) $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)
test_full: $(SASSC_BIN)
$(RUBY_BIN) $(SASS_SPEC_PATH)/sass-spec.rb -c $(SASSC_BIN) --impl libsass \
--cmd-args "-I $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)" \
--run-todo $(LOG_FLAGS) $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)
test_probe: $(SASSC_BIN)
$(RUBY_BIN) $(SASS_SPEC_PATH)/sass-spec.rb -c $(SASSC_BIN) --impl libsass \
--cmd-args "-I $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)" \
--probe-todo $(LOG_FLAGS) $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)
test_interactive: $(SASSC_BIN)
$(RUBY_BIN) $(SASS_SPEC_PATH)/sass-spec.rb -c $(SASSC_BIN) --impl libsass \
--cmd-args "-I $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)" \
--interactive $(LOG_FLAGS) $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)
clean-objects: | lib
-$(RM) lib/*.a lib/*.so lib/*.dll lib/*.dylib lib/*.la
-$(RMDIR) lib
clean: clean-objects
$(RM) $(CLEANUPS)
clean-all:
$(MAKE) -C $(SASS_SASSC_PATH) clean
lib-file: lib-file-$(BUILD)
lib-opts: lib-opts-$(BUILD)
lib-file-static:
@echo $(LIB_STATIC)
lib-file-shared:
@echo $(LIB_SHARED)
lib-opts-static:
@echo -L"$(SASS_LIBSASS_PATH)/lib"
lib-opts-shared:
@echo -L"$(SASS_LIBSASS_PATH)/lib -lsass"
.PHONY: all static shared sassc \
version install-headers \
clean clean-all clean-objects \
debug debug-static debug-shared \
install install-static install-shared \
lib-opts lib-opts-shared lib-opts-static \
lib-file lib-file-shared lib-file-static \
test test_build test_full test_probe
.DELETE_ON_ERROR:
libsass-3.6.3/Makefile.conf 0000664 0000000 0000000 00000002602 13557420656 0015564 0 ustar 00root root 0000000 0000000 # this is merely a common Makefile multiple implementers can use
# bigger files (in terms of compile time) tend to go to the top,
# so they don't end up as the last compile unit when compiling
# in parallel. But we also want to mix them a little too avoid
# heavy RAM usage peaks. Other than that the order is arbitrary.
SOURCES = \
ast.cpp \
ast_values.cpp \
ast_supports.cpp \
ast_sel_cmp.cpp \
ast_sel_unify.cpp \
ast_sel_super.cpp \
ast_sel_weave.cpp \
ast_selectors.cpp \
context.cpp \
constants.cpp \
fn_utils.cpp \
fn_miscs.cpp \
fn_maps.cpp \
fn_lists.cpp \
fn_colors.cpp \
fn_numbers.cpp \
fn_strings.cpp \
fn_selectors.cpp \
color_maps.cpp \
environment.cpp \
ast_fwd_decl.cpp \
bind.cpp \
file.cpp \
util.cpp \
util_string.cpp \
json.cpp \
units.cpp \
values.cpp \
plugins.cpp \
position.cpp \
lexer.cpp \
parser.cpp \
parser_selectors.cpp \
prelexer.cpp \
eval.cpp \
eval_selectors.cpp \
expand.cpp \
listize.cpp \
cssize.cpp \
extender.cpp \
extension.cpp \
stylesheet.cpp \
output.cpp \
inspect.cpp \
emitter.cpp \
check_nesting.cpp \
remove_placeholders.cpp \
sass.cpp \
sass_values.cpp \
sass_context.cpp \
sass_functions.cpp \
sass2scss.cpp \
backtrace.cpp \
operators.cpp \
ast2c.cpp \
c2ast.cpp \
to_value.cpp \
source_map.cpp \
error_handling.cpp \
memory/SharedPtr.cpp \
utf8_string.cpp \
base64vlq.cpp
CSOURCES = cencode.c
libsass-3.6.3/Readme.md 0000664 0000000 0000000 00000012334 13557420656 0014722 0 ustar 00root root 0000000 0000000 LibSass - Sass compiler written in C++
======================================
Currently maintained by Marcel Greter ([@mgreter]) and Michael Mifsud ([@xzyfer])
Originally created by Aaron Leung ([@akhleung]) and Hampton Catlin ([@hcatlin])
[](https://travis-ci.org/sass/libsass "Travis CI")
[](https://ci.appveyor.com/project/sass/libsass/branch/master "Appveyor CI")
[](https://coveralls.io/r/sass/libsass?branch=feature%2Ftest-travis-ci-3 "Code coverage of spec tests")
[](http://isitmaintained.com/project/sass/libsass "Percentage of issues still open")
[](http://isitmaintained.com/project/sass/libsass "Average time to resolve an issue")
[](https://www.bountysource.com/trackers/283068-libsass?utm_source=283068&utm_medium=shield&utm_campaign=TRACKER_BADGE "Bountysource")
[](https://libsass-slack.herokuapp.com/ "Slack communication channels")
[LibSass](https://github.com/sass/libsass "LibSass GitHub Project") is just a library!
If you want to use LibSass to compile Sass, you need an implementer. Some
implementations are only bindings into other programming languages. But most also
ship with a command line interface (CLI) you can use directly. There is also
[SassC](https://github.com/sass/sassc), which is the official lightweight
CLI tool built by the same people as LibSass.
### Excerpt of "sanctioned" implementations:
- https://github.com/sass/node-sass (Node.js)
- https://github.com/sass/perl-libsass (Perl)
- https://github.com/sass/libsass-python (Python)
- https://github.com/wellington/go-libsass (Go)
- https://github.com/sass/sassc-ruby (Ruby)
- https://github.com/sass/libsass-net (C#)
- https://github.com/medialize/sass.js (JS)
- https://github.com/bit3/jsass (Java)
This list does not say anything about the quality of either the listed or not listed [implementations](docs/implementations.md)!
The authors of the listed projects above are just known to work regularly together with LibSass developers.
About
-----
LibSass is a C++ port of the original Ruby Sass CSS compiler with a [C API](docs/api-doc.md).
We coded LibSass with portability and efficiency in mind. You can expect LibSass to be a lot
faster than Ruby Sass and on par or faster than the best alternative CSS compilers around.
Developing
----------
As noted above, the LibSass repository does not contain any binaries or other way to execute
LibSass. Therefore, you need an implementer to develop LibSass. Easiest is to start with
the official [SassC](http://github.com/sass/sassc) CLI wrapper. It is *guaranteed* to compile
with the latest code in LibSass master, since it is also used in the CI process. There is no
limitation here, as you may use any other LibSass implementer to test your LibSass branch!
Testing
-------
Since LibSass is a pure library, tests are run through the [Sass-Spec](https://github.com/sass/sass-spec)
project using the [SassC](http://github.com/sass/sassc) CLI wrapper. To run the tests against LibSass while
developing, you can run `./script/spec`. This will clone SassC and Sass-Spec under the project folder and
then run the Sass-Spec test suite. You may want to update the clones to ensure you have the latest version.
Note that the scripts in the `./script` folder are mainly intended for our CI needs.
Building
--------
To build LibSass you need GCC 4.7+ or Clang/LLVM. If your OS is older, you may need to upgrade
them first (or install clang as an alternative). On Windows, you need MinGW with GCC 4.7+ or VS 2013
Update 4+. It is also possible to build LibSass with Clang/LLVM on Windows with various build chains
and/or command line interpreters.
See the [build docs for further instructions](docs/build.md)!
Compatibility
-------------
For all intents and purposes LibSass is fully compatible with the Sass language spec. Any known
differences can be found as open issues.
About Sass
----------
Sass is a CSS pre-processor language to add on exciting, new, awesome features to CSS. Sass was
the first language of its kind and by far the most mature and up to date codebase.
Sass was originally conceived of by the co-creator of this library, Hampton Catlin ([@hcatlin]).
Most of the language has been the result of years of work by Natalie Weizenbaum ([@nex3]) and
Chris Eppstein ([@chriseppstein]).
For more information about Sass itself, please visit https://sass-lang.com
Initial development of LibSass by Aaron Leung and Hampton Catlin was supported by [Moovweb](http://www.moovweb.com).
Licensing
---------
Our [MIT license](LICENSE) is designed to be as simple and liberal as possible.
[@hcatlin]: https://github.com/hcatlin
[@akhleung]: https://github.com/akhleung
[@chriseppstein]: https://github.com/chriseppstein
[@nex3]: https://github.com/nex3
[@mgreter]: https://github.com/mgreter
[@xzyfer]: https://github.com/xzyfer
libsass-3.6.3/SECURITY.md 0000664 0000000 0000000 00000000562 13557420656 0014774 0 ustar 00root root 0000000 0000000 Serious about security
======================
The LibSass team recognizes the important contributions the security research
community can make. We therefore encourage reporting security issues with the
code contained in this repository.
If you believe you have discovered a security vulnerability, please report it at
https://hackerone.com/libsass instead of GitHub.
libsass-3.6.3/appveyor.yml 0000664 0000000 0000000 00000006253 13557420656 0015576 0 ustar 00root root 0000000 0000000 os: Visual Studio 2013
environment:
CTEST_OUTPUT_ON_FAILURE: 1
ruby_version: 24-x64
TargetPath: sassc/bin/sassc.exe
matrix:
- Compiler: msvc
Config: Release
Platform: Win32
- Compiler: msvc
Config: Debug
Platform: Win32
- Compiler: msvc
Config: Release
Platform: Win64
- Compiler: mingw
Build: static
- Compiler: mingw
Build: shared
cache:
- C:\Ruby%ruby_version%\lib\ruby\gems
- C:\mingw64
# Uncomment to debug hanging builds via RDP, password can be found/set under Environment-Variables in appveyor settings!
#
# init:
# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
#
# on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
install:
- git clone https://github.com/sass/sassc.git
- git clone https://github.com/sass/sass-spec.git
- set PATH=C:\Ruby%ruby_version%\bin;%PATH%
- ps: |
if(!(gem which minitest 2>$nul)) { gem install minitest --no-ri --no-rdoc }
if(!(gem which hrx 2>$nul)) { gem install hrx --no-ri --no-rdoc }
if ($env:Compiler -eq "mingw" -AND -Not (Test-Path "C:\mingw64")) {
# Install MinGW.
$file = "x86_64-4.9.2-release-win32-seh-rt_v4-rev3.7z"
wget https://bintray.com/artifact/download/drewwells/generic/$file -OutFile $file
&7z x -oC:\ $file > $null
}
- set PATH=C:\mingw64\bin;%PATH%
- set CC=gcc
build_script:
- ps: |
if ($env:Compiler -eq "mingw") {
mingw32-make -j4 sassc
} else {
msbuild /m:4 /p:"Configuration=$env:Config;Platform=$env:Platform" sassc\win\sassc.sln
}
# print the branding art
mv script/branding script/branding.ps1
script/branding.ps1
# print the version info
&$env:TargetPath -v
ruby -v
test_script:
- ps: |
$PRNR = $env:APPVEYOR_PULL_REQUEST_NUMBER
if ($PRNR) {
echo "Fetching info for PR $PRNR"
wget https://api.github.com/repos/sass/libsass/pulls/$PRNR -OutFile pr.json
$json = cat pr.json -Raw
$SPEC_PR = [regex]::match($json,'sass\/sass-spec(#|\/pull\/)([0-9]+)').Groups[2].Value
if ($SPEC_PR) {
echo "Checkout sass spec PR $SPEC_PR"
git -C sass-spec fetch -q -u origin pull/$SPEC_PR/head:ci-spec-pr-$SPEC_PR
git -C sass-spec checkout -q --force ci-spec-pr-$SPEC_PR
}
}
$env:TargetPath = Join-Path $pwd.Path $env:TargetPath
If (Test-Path "$env:TargetPath") {
ruby sass-spec/sass-spec.rb --probe-todo --impl libsass -c $env:TargetPath -s sass-spec/spec
if(-not($?)) {
echo "sass-spec tests failed"
exit 1
}
} else {
echo "spec runner not found (compile error?)"
exit 1
}
Write-Host "Explicitly testing the case when cwd has Unicode characters: " -nonewline
# See comments in gh-1774 for details.
cd test/e2e/unicode-pwd/Sáss-UŢF8/
&$env:TargetPath ./input.scss 2>&1>$null
if(-not($?)) {
echo "Failed!"
exit 1
} else {
echo "Success!"
}
libsass-3.6.3/configure.ac 0000664 0000000 0000000 00000010254 13557420656 0015470 0 ustar 00root root 0000000 0000000 # -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.61])
AC_INIT([libsass], m4_esyscmd_s([./version.sh]), [support@moovweb.com])
AC_CONFIG_SRCDIR([src/ast.hpp])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_FILES([include/sass/version.h])
AC_CONFIG_AUX_DIR([script])
# These are flags passed to automake
# Though they look like gcc flags!
AM_INIT_AUTOMAKE([foreign parallel-tests -Wall])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([no])])
# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_LANG_PUSH([C])
AC_LANG_PUSH([C++])
AC_GNU_SOURCE
# Check fails on Travis, but it works fine
# AX_CXX_COMPILE_STDCXX_11([ext],[optional])
AC_CHECK_TOOL([AR], [ar], [false])
AC_CHECK_TOOL([DLLTOOL], [dlltool], [false])
AC_CHECK_TOOL([DLLWRAP], [dllwrap], [false])
AC_CHECK_TOOL([WINDRES], [windres], [false])
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT([dlopen])
# Checks for header files.
AC_CHECK_HEADERS([unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([floor getcwd strtol])
# Checks for testing.
AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests], [enable testing the build]),
[enable_tests="$enableval"], [enable_tests=no])
AS_CASE([$host], [*-*-mingw*], [is_mingw32=yes], [is_mingw32=no])
AM_CONDITIONAL(COMPILER_IS_MINGW32, test "x$is_mingw32" = "xyes")
dnl The dlopen() function is in the C library for *BSD and in
dnl libdl on GLIBC-based systems
if test "x$is_mingw32" != "xyes"; then
AC_SEARCH_LIBS([dlopen], [dl dld], [], [
AC_MSG_ERROR([unable to find the dlopen() function])
])
fi
if test "x$enable_tests" = "xyes"; then
AC_PROG_CC
AC_PROG_AWK
# test need minitest gem
AC_PATH_PROG(RUBY, [ruby])
AC_PATH_PROG(TAPOUT, [tapout])
AC_REQUIRE_AUX_FILE([tap-driver])
AC_REQUIRE_AUX_FILE([tap-runner])
AC_ARG_WITH(sassc-dir,
AS_HELP_STRING([--with-sassc-dir=
], [specify directory of sassc sources for testing (default: sassc)]),
[sassc_dir="$withval"], [sassc_dir="sassc"])
AC_CHECK_FILE([$sassc_dir/sassc.c], [], [
AC_MSG_ERROR([Unable to find sassc directory.
You must clone the sassc repository in this directory or specify
the --with-sassc-dir= argument.
])
])
SASS_SASSC_PATH=$sassc_dir
AC_SUBST(SASS_SASSC_PATH)
AC_ARG_WITH(sass-spec-dir,
AS_HELP_STRING([--with-sass-spec-dir=], [specify directory of sass-spec for testing (default: sass-spec)]),
[sass_spec_dir="$withval"], [sass_spec_dir="sass-spec"])
AC_CHECK_FILE([$sass_spec_dir/sass-spec.rb], [], [
AC_MSG_ERROR([Unable to find sass-spec directory.
You must clone the sass-spec repository in this directory or specify
the --with-sass-spec-dir= argument.
])
])
# Automake doesn't like its tests in an absolute path, so we make it relative.
case $sass_spec_dir in
/*)
SASS_SPEC_PATH=`$RUBY -e "require 'pathname'; puts Pathname.new('$sass_spec_dir').relative_path_from(Pathname.new('$PWD')).to_s"`
;;
*)
SASS_SPEC_PATH="$sass_spec_dir"
;;
esac
AC_SUBST(SASS_SPEC_PATH)
else
# we do not really need these paths for non test build
# but automake may error if we do not define them here
SASS_SPEC_PATH=sass-spec
SASS_SASSC_PATH=sassc
AC_SUBST(SASS_SPEC_PATH)
AC_SUBST(SASS_SASSC_PATH)
fi
AM_CONDITIONAL(ENABLE_TESTS, test "x$enable_tests" = "xyes")
AC_ARG_ENABLE([coverage],
[AS_HELP_STRING([--enable-coverage],
[enable coverage report for test suite])],
[enable_cov=$enableval],
[enable_cov=no])
if test "x$enable_cov" = "xyes"; then
AC_CHECK_PROG(GCOV, gcov, gcov)
# Remove all optimization flags from C[XX]FLAGS
changequote({,})
CFLAGS=`echo "$CFLAGS -O1 -fno-omit-frame-pointer" | $SED -e 's/-O[0-9]*//g'`
CXXFLAGS=`echo "$CXXFLAGS -O1 -fno-omit-frame-pointer" | $SED -e 's/-O[0-9]*//g'`
changequote([,])
AC_SUBST(GCOV)
fi
AM_CONDITIONAL(ENABLE_COVERAGE, test "x$enable_cov" = "xyes")
AC_SUBST(PACKAGE_VERSION)
AC_MSG_NOTICE([Building libsass ($VERSION)])
AC_CONFIG_FILES([GNUmakefile src/GNUmakefile src/support/libsass.pc])
AC_OUTPUT
libsass-3.6.3/contrib/ 0000775 0000000 0000000 00000000000 13557420656 0014640 5 ustar 00root root 0000000 0000000 libsass-3.6.3/contrib/libsass.spec 0000664 0000000 0000000 00000002322 13557420656 0017153 0 ustar 00root root 0000000 0000000 Name: libsass
Version: %{version}
Release: 1%{?dist}
Summary: A C/C++ implementation of a Sass compiler
License: MIT
URL: http://libsass.org
Source0: %{name}-%{version}.tar.gz
BuildRequires: gcc-c++ >= 4.7
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: libtool
%description
LibSass is a C/C++ port of the Sass engine. The point is to be simple, fast, and easy to integrate.
%package devel
Summary: Development files for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
%description devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.
%prep
%setup -q
autoreconf --force --install
%build
%configure --disable-static \
--disable-tests \
--enable-shared
make %{?_smp_mflags}
%install
%make_install
find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%files
%doc Readme.md LICENSE
%{_libdir}/*.so.*
%files devel
%doc
%{_includedir}/*
%{_libdir}/*.so
%{_libdir}/pkgconfig/*.pc
%changelog
* Tue Feb 10 2015 Gawain Lynch - 3.1.0-1
- Initial SPEC file
libsass-3.6.3/contrib/plugin.cpp 0000664 0000000 0000000 00000004105 13557420656 0016642 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
// gcc: g++ -shared plugin.cpp -o plugin.so -fPIC -Llib -lsass
// mingw: g++ -shared plugin.cpp -o plugin.dll -Llib -lsass
extern "C" const char* ADDCALL libsass_get_version() {
return libsass_version();
}
union Sass_Value* custom_function(const union Sass_Value* s_args, Sass_Function_Entry cb, struct Sass_Compiler* comp)
{
// get context/option struct associated with this compiler
struct Sass_Context* ctx = sass_compiler_get_context(comp);
struct Sass_Options* opts = sass_compiler_get_options(comp);
// get the cookie from function descriptor
void* cookie = sass_function_get_cookie(cb);
// we actually abuse the void* to store an "int"
return sass_make_number((intptr_t)cookie, "px");
}
extern "C" Sass_Function_List ADDCALL libsass_load_functions()
{
// allocate a custom function caller
Sass_Function_Entry c_func =
sass_make_function("foo()", custom_function, (void*)42);
// create list of all custom functions
Sass_Function_List fn_list = sass_make_function_list(1);
// put the only function in this plugin to the list
sass_function_set_list_entry(fn_list, 0, c_func);
// return the list
return fn_list;
}
Sass_Import_List custom_importer(const char* cur_path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
{
// get the cookie from importer descriptor
void* cookie = sass_importer_get_cookie(cb);
// create a list to hold our import entries
Sass_Import_List incs = sass_make_import_list(1);
// create our only import entry (route path back)
incs[0] = sass_make_import_entry(cur_path, 0, 0);
// return imports
return incs;
}
extern "C" Sass_Importer_List ADDCALL libsass_load_importers()
{
// allocate a custom function caller
Sass_Importer_Entry c_imp =
sass_make_importer(custom_importer, - 99, (void*)42);
// create list of all custom functions
Sass_Importer_List imp_list = sass_make_importer_list(1);
// put the only function in this plugin to the list
sass_importer_set_list_entry(imp_list, 0, c_imp);
// return the list
return imp_list;
}
libsass-3.6.3/docs/ 0000775 0000000 0000000 00000000000 13557420656 0014130 5 ustar 00root root 0000000 0000000 libsass-3.6.3/docs/README.md 0000664 0000000 0000000 00000003074 13557420656 0015413 0 ustar 00root root 0000000 0000000 Welcome to the LibSass documentation!
## First Off
LibSass is just a library. To run the code locally (i.e. to compile your stylesheets), you need an implementer. SassC (get it?) is an implementer written in C. There are a number of other implementations of LibSass - for example Node. We encourage you to write your own port - the whole point of LibSass is that we want to bring Sass to many other languages, not just Ruby!
We're working hard on moving to full parity with Ruby Sass... learn more at the [The-LibSass-Compatibility-Plan](compatibility-plan.md)!
### Implementing LibSass
If you're interested in implementing LibSass in your own project see the [API Documentation](api-doc.md) which now includes implementing
your own [Sass functions](api-function.md). You may wish to [look at other implementations](implementations.md) for your language of choice.
Or make your own!
### Contributing to LibSass
| Issue Tracker | Issue Triage | Community Guidelines |
|-------------------|----------------------------------|-----------------------------|
| We're always needing help, so check out our issue tracker, help some people out, and read our article on [Contributing](contributing.md)! It's got all the details on what to do! | To help understand the process of triaging bugs, have a look at our [Issue-Triage](triage.md) document. | Oh, and don't forget we always follow [Sass Community Guidelines](https://sass-lang.com/community-guidelines). Be nice and everyone else will be nice too! |
Please refer to the steps on [Building LibSass](build.md)
libsass-3.6.3/docs/api-context-example.md 0000664 0000000 0000000 00000004705 13557420656 0020344 0 ustar 00root root 0000000 0000000 ## Example for `data_context`
```C:data.c
#include
#include "sass/context.h"
int main( int argc, const char* argv[] )
{
// LibSass will take control of data you pass in
// Therefore we need to make a copy of static data
char* text = sass_copy_c_string("a{b:c;}");
// Normally you'll load data into a buffer from i.e. the disk.
// Use `sass_alloc_memory` to get a buffer to pass to LibSass
// then fill it with data you load from disk or somewhere else.
// create the data context and get all related structs
struct Sass_Data_Context* data_ctx = sass_make_data_context(text);
struct Sass_Context* ctx = sass_data_context_get_context(data_ctx);
struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
// configure some options ...
sass_option_set_precision(ctx_opt, 10);
// context is set up, call the compile step now
int status = sass_compile_data_context(data_ctx);
// print the result or the error to the stdout
if (status == 0) puts(sass_context_get_output_string(ctx));
else puts(sass_context_get_error_message(ctx));
// release allocated memory
sass_delete_data_context(data_ctx);
// exit status
return status;
}
```
### Compile data.c
```bash
gcc -c data.c -o data.o
gcc -o sample data.o -lsass
echo "foo { margin: 21px * 2; }" > foo.scss
./sample foo.scss => "foo { margin: 42px }"
```
## Example for `file_context`
```C:file.c
#include
#include "sass/context.h"
int main( int argc, const char* argv[] )
{
// get the input file from first argument or use default
const char* input = argc > 1 ? argv[1] : "styles.scss";
// create the file context and get all related structs
struct Sass_File_Context* file_ctx = sass_make_file_context(input);
struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
// configure some options ...
sass_option_set_precision(ctx_opt, 10);
// context is set up, call the compile step now
int status = sass_compile_file_context(file_ctx);
// print the result or the error to the stdout
if (status == 0) puts(sass_context_get_output_string(ctx));
else puts(sass_context_get_error_message(ctx));
// release allocated memory
sass_delete_file_context(file_ctx);
// exit status
return status;
}
```
### Compile file.c
```bash
gcc -c file.c -o file.o
gcc -o sample file.o -lsass
echo "foo { margin: 21px * 2; }" > foo.scss
./sample foo.scss => "foo { margin: 42px }"
```
libsass-3.6.3/docs/api-context-internal.md 0000664 0000000 0000000 00000006662 13557420656 0020531 0 ustar 00root root 0000000 0000000 ```C
// Input behaviours
enum Sass_Input_Style {
SASS_CONTEXT_NULL,
SASS_CONTEXT_FILE,
SASS_CONTEXT_DATA,
SASS_CONTEXT_FOLDER
};
// sass config options structure
struct Sass_Inspect_Options {
// Output style for the generated css code
// A value from above SASS_STYLE_* constants
enum Sass_Output_Style output_style;
// Precision for fractional numbers
int precision;
};
// sass config options structure
struct Sass_Output_Options : Sass_Inspect_Options {
// String to be used for indentation
const char* indent;
// String to be used to for line feeds
const char* linefeed;
// Emit comments in the generated CSS indicating
// the corresponding source line.
bool source_comments;
};
// sass config options structure
struct Sass_Options : Sass_Output_Options {
// embed sourceMappingUrl as data uri
bool source_map_embed;
// embed include contents in maps
bool source_map_contents;
// create file urls for sources
bool source_map_file_urls;
// Disable sourceMappingUrl in css output
bool omit_source_map_url;
// Treat source_string as sass (as opposed to scss)
bool is_indented_syntax_src;
// The input path is used for source map
// generation. It can be used to define
// something with string compilation or to
// overload the input file path. It is
// set to "stdin" for data contexts and
// to the input file on file contexts.
char* input_path;
// The output path is used for source map
// generation. LibSass will not write to
// this file, it is just used to create
// information in source-maps etc.
char* output_path;
// Colon-separated list of paths
// Semicolon-separated on Windows
// Maybe use array interface instead?
char* include_path;
char* plugin_path;
// Include paths (linked string list)
struct string_list* include_paths;
// Plugin paths (linked string list)
struct string_list* plugin_paths;
// Path to source map file
// Enables source map generation
// Used to create sourceMappingUrl
char* source_map_file;
// Directly inserted in source maps
char* source_map_root;
// Custom functions that can be called from sccs code
Sass_Function_List c_functions;
// Callback to overload imports
Sass_Importer_List c_importers;
// List of custom headers
Sass_Importer_List c_headers;
};
// base for all contexts
struct Sass_Context : Sass_Options
{
// store context type info
enum Sass_Input_Style type;
// generated output data
char* output_string;
// generated source map json
char* source_map_string;
// error status
int error_status;
char* error_json;
char* error_text;
char* error_message;
// error position
char* error_file;
size_t error_line;
size_t error_column;
char* error_src;
// report imported files
char** included_files;
};
// struct for file compilation
struct Sass_File_Context : Sass_Context {
// no additional fields required
// input_path is already on options
};
// struct for data compilation
struct Sass_Data_Context : Sass_Context {
// provided source string
char* source_string;
char* srcmap_string;
};
// Compiler states
enum Sass_Compiler_State {
SASS_COMPILER_CREATED,
SASS_COMPILER_PARSED,
SASS_COMPILER_EXECUTED
};
// link c and cpp context
struct Sass_Compiler {
// progress status
Sass_Compiler_State state;
// original c context
Sass_Context* c_ctx;
// Sass::Context
Sass::Context* cpp_ctx;
// Sass::Block
Sass::Block_Obj root;
};
```
libsass-3.6.3/docs/api-context.md 0000664 0000000 0000000 00000025710 13557420656 0016712 0 ustar 00root root 0000000 0000000 Sass Contexts come in two flavors:
- `Sass_File_Context`
- `Sass_Data_Context`
### Basic Usage
```C
#include "sass/context.h"
```
***Sass_Options***
```C
// Precision for fractional numbers
int precision;
```
```C
// Output style for the generated css code
// A value from above SASS_STYLE_* constants
int output_style;
```
```C
// Emit comments in the generated CSS indicating
// the corresponding source line.
bool source_comments;
```
```C
// embed sourceMappingUrl as data uri
bool source_map_embed;
```
```C
// embed include contents in maps
bool source_map_contents;
```
```C
// create file urls for sources
bool source_map_file_urls;
```
```C
// Disable sourceMappingUrl in css output
bool omit_source_map_url;
```
```C
// Treat source_string as sass (as opposed to scss)
bool is_indented_syntax_src;
```
```C
// The input path is used for source map
// generating. It can be used to define
// something with string compilation or to
// overload the input file path. It is
// set to "stdin" for data contexts and
// to the input file on file contexts.
char* input_path;
```
```C
// The output path is used for source map
// generating. LibSass will not write to
// this file, it is just used to create
// information in source-maps etc.
char* output_path;
```
```C
// String to be used for indentation
const char* indent;
```
```C
// String to be used to for line feeds
const char* linefeed;
```
```C
// Colon-separated list of paths
// Semicolon-separated on Windows
char* include_path;
char* plugin_path;
```
```C
// Additional include paths
// Must be null delimited
char** include_paths;
char** plugin_paths;
```
```C
// Path to source map file
// Enables the source map generating
// Used to create sourceMappingUrl
char* source_map_file;
```
```C
// Directly inserted in source maps
char* source_map_root;
```
```C
// Custom functions that can be called from Sass code
Sass_C_Function_List c_functions;
```
```C
// Callback to overload imports
Sass_C_Import_Callback importer;
```
***Sass_Context***
```C
// store context type info
enum Sass_Input_Style type;
````
```C
// generated output data
char* output_string;
```
```C
// generated source map json
char* source_map_string;
```
```C
// error status
int error_status;
char* error_json;
char* error_text;
char* error_message;
// error position
char* error_file;
size_t error_line;
size_t error_column;
char* error_src;
```
```C
// report imported files
char** included_files;
```
***Sass_File_Context***
```C
// no additional fields required
// input_path is already on options
```
***Sass_Data_Context***
```C
// provided source string
char* source_string;
```
### Sass Context API
```C
// Forward declaration
struct Sass_Compiler;
// Forward declaration
struct Sass_Options;
struct Sass_Context; // : Sass_Options
struct Sass_File_Context; // : Sass_Context
struct Sass_Data_Context; // : Sass_Context
// Create and initialize an option struct
struct Sass_Options* sass_make_options (void);
// Create and initialize a specific context
struct Sass_File_Context* sass_make_file_context (const char* input_path);
struct Sass_Data_Context* sass_make_data_context (char* source_string);
// Call the compilation step for the specific context
int sass_compile_file_context (struct Sass_File_Context* ctx);
int sass_compile_data_context (struct Sass_Data_Context* ctx);
// Create a sass compiler instance for more control
struct Sass_Compiler* sass_make_file_compiler (struct Sass_File_Context* file_ctx);
struct Sass_Compiler* sass_make_data_compiler (struct Sass_Data_Context* data_ctx);
// Execute the different compilation steps individually
// Useful if you only want to query the included files
int sass_compiler_parse (struct Sass_Compiler* compiler);
int sass_compiler_execute (struct Sass_Compiler* compiler);
// Release all memory allocated with the compiler
// This does _not_ include any contexts or options
void sass_delete_compiler (struct Sass_Compiler* compiler);
void sass_delete_options(struct Sass_Options* options);
// Release all memory allocated and also ourself
void sass_delete_file_context (struct Sass_File_Context* ctx);
void sass_delete_data_context (struct Sass_Data_Context* ctx);
// Getters for Context from specific implementation
struct Sass_Context* sass_file_context_get_context (struct Sass_File_Context* file_ctx);
struct Sass_Context* sass_data_context_get_context (struct Sass_Data_Context* data_ctx);
// Getters for Context_Options from Sass_Context
struct Sass_Options* sass_context_get_options (struct Sass_Context* ctx);
struct Sass_Options* sass_file_context_get_options (struct Sass_File_Context* file_ctx);
struct Sass_Options* sass_data_context_get_options (struct Sass_Data_Context* data_ctx);
void sass_file_context_set_options (struct Sass_File_Context* file_ctx, struct Sass_Options* opt);
void sass_data_context_set_options (struct Sass_Data_Context* data_ctx, struct Sass_Options* opt);
// Getters for Sass_Context values
const char* sass_context_get_output_string (struct Sass_Context* ctx);
int sass_context_get_error_status (struct Sass_Context* ctx);
const char* sass_context_get_error_json (struct Sass_Context* ctx);
const char* sass_context_get_error_text (struct Sass_Context* ctx);
const char* sass_context_get_error_message (struct Sass_Context* ctx);
const char* sass_context_get_error_file (struct Sass_Context* ctx);
const char* sass_context_get_error_src (struct Sass_Context* ctx);
size_t sass_context_get_error_line (struct Sass_Context* ctx);
size_t sass_context_get_error_column (struct Sass_Context* ctx);
const char* sass_context_get_source_map_string (struct Sass_Context* ctx);
char** sass_context_get_included_files (struct Sass_Context* ctx);
// Getters for Sass_Compiler options (query import stack)
size_t sass_compiler_get_import_stack_size(struct Sass_Compiler* compiler);
Sass_Import_Entry sass_compiler_get_last_import(struct Sass_Compiler* compiler);
Sass_Import_Entry sass_compiler_get_import_entry(struct Sass_Compiler* compiler, size_t idx);
// Getters for Sass_Compiler options (query function stack)
size_t sass_compiler_get_callee_stack_size(struct Sass_Compiler* compiler);
Sass_Callee_Entry sass_compiler_get_last_callee(struct Sass_Compiler* compiler);
Sass_Callee_Entry sass_compiler_get_callee_entry(struct Sass_Compiler* compiler, size_t idx);
// Take ownership of memory (value on context is set to 0)
char* sass_context_take_error_json (struct Sass_Context* ctx);
char* sass_context_take_error_text (struct Sass_Context* ctx);
char* sass_context_take_error_message (struct Sass_Context* ctx);
char* sass_context_take_error_file (struct Sass_Context* ctx);
char* sass_context_take_error_src (struct Sass_Context* ctx);
char* sass_context_take_output_string (struct Sass_Context* ctx);
char* sass_context_take_source_map_string (struct Sass_Context* ctx);
```
### Sass Options API
```C
// Getters for Context_Option values
int sass_option_get_precision (struct Sass_Options* options);
enum Sass_Output_Style sass_option_get_output_style (struct Sass_Options* options);
bool sass_option_get_source_comments (struct Sass_Options* options);
bool sass_option_get_source_map_embed (struct Sass_Options* options);
bool sass_option_get_source_map_contents (struct Sass_Options* options);
bool sass_option_get_source_map_file_urls (struct Sass_Options* options);
bool sass_option_get_omit_source_map_url (struct Sass_Options* options);
bool sass_option_get_is_indented_syntax_src (struct Sass_Options* options);
const char* sass_option_get_indent (struct Sass_Options* options);
const char* sass_option_get_linefeed (struct Sass_Options* options);
const char* sass_option_get_input_path (struct Sass_Options* options);
const char* sass_option_get_output_path (struct Sass_Options* options);
const char* sass_option_get_source_map_file (struct Sass_Options* options);
const char* sass_option_get_source_map_root (struct Sass_Options* options);
Sass_C_Function_List sass_option_get_c_functions (struct Sass_Options* options);
Sass_C_Import_Callback sass_option_get_importer (struct Sass_Options* options);
// Getters for Context_Option include path array
size_t sass_option_get_include_path_size(struct Sass_Options* options);
const char* sass_option_get_include_path(struct Sass_Options* options, size_t i);
// Plugin paths to load dynamic libraries work the same
size_t sass_option_get_plugin_path_size(struct Sass_Options* options);
const char* sass_option_get_plugin_path(struct Sass_Options* options, size_t i);
// Setters for Context_Option values
void sass_option_set_precision (struct Sass_Options* options, int precision);
void sass_option_set_output_style (struct Sass_Options* options, enum Sass_Output_Style output_style);
void sass_option_set_source_comments (struct Sass_Options* options, bool source_comments);
void sass_option_set_source_map_embed (struct Sass_Options* options, bool source_map_embed);
void sass_option_set_source_map_contents (struct Sass_Options* options, bool source_map_contents);
void sass_option_set_source_map_file_urls (struct Sass_Options* options, bool source_map_file_urls);
void sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
void sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
void sass_option_set_indent (struct Sass_Options* options, const char* indent);
void sass_option_set_linefeed (struct Sass_Options* options, const char* linefeed);
void sass_option_set_input_path (struct Sass_Options* options, const char* input_path);
void sass_option_set_output_path (struct Sass_Options* options, const char* output_path);
void sass_option_set_plugin_path (struct Sass_Options* options, const char* plugin_path);
void sass_option_set_include_path (struct Sass_Options* options, const char* include_path);
void sass_option_set_source_map_file (struct Sass_Options* options, const char* source_map_file);
void sass_option_set_source_map_root (struct Sass_Options* options, const char* source_map_root);
void sass_option_set_c_functions (struct Sass_Options* options, Sass_C_Function_List c_functions);
void sass_option_set_importer (struct Sass_Options* options, Sass_C_Import_Callback importer);
// Push function for paths (no manipulation support for now)
void sass_option_push_plugin_path (struct Sass_Options* options, const char* path);
void sass_option_push_include_path (struct Sass_Options* options, const char* path);
// Resolve a file via the given include paths in the sass option struct
// find_file looks for the exact file name while find_include does a regular sass include
char* sass_find_file (const char* path, struct Sass_Options* opt);
char* sass_find_include (const char* path, struct Sass_Options* opt);
// Resolve a file relative to last import or include paths in the sass option struct
// find_file looks for the exact file name while find_include does a regular sass include
char* sass_compiler_find_file (const char* path, struct Sass_Compiler* compiler);
char* sass_compiler_find_include (const char* path, struct Sass_Compiler* compiler);
```
### More links
- [Sass Context Example](api-context-example.md)
- [Sass Context Internal](api-context-internal.md)
libsass-3.6.3/docs/api-doc.md 0000664 0000000 0000000 00000017755 13557420656 0016005 0 ustar 00root root 0000000 0000000 ## Introduction
LibSass wouldn't be much good without a way to interface with it. These
interface documentations describe the various functions and data structures
available to implementers. They are split up over three major components, which
have all their own source files (plus some common functionality).
- [Sass Context](api-context.md) - Trigger and handle the main Sass compilation
- [Sass Value](api-value.md) - Exchange values and its format with LibSass
- [Sass Function](api-function.md) - Get invoked by LibSass for function statments
- [Sass Importer](api-importer.md) - Get invoked by LibSass for @import statments
### Basic usage
First you will need to include the header file!
This will automatically load all other headers too!
```C
#include "sass/context.h"
```
## Basic C Example
```C
#include
#include "sass/context.h"
int main() {
puts(libsass_version());
return 0;
}
```
```bash
gcc -Wall version.c -lsass -o version && ./version
```
## More C Examples
- [Sample code for Sass Context](api-context-example.md)
- [Sample code for Sass Value](api-value-example.md)
- [Sample code for Sass Function](api-function-example.md)
- [Sample code for Sass Importer](api-importer-example.md)
## Compiling your code
The most important is your sass file (or string of sass code). With this, you
will want to start a LibSass compiler. Here is some pseudocode describing the
process. The compiler has two different modes: direct input as a string with
`Sass_Data_Context` or LibSass will do file reading for you by using
`Sass_File_Context`. See the code for a list of options available
[Sass_Options](https://github.com/sass/libsass/blob/36feef0/include/sass/interface.h#L18)
The general rule is if the API takes `const char*` it will make a copy,
but where the API is `char*` it will take over memory ownership, so make sure to pass
in memory that is allocated via `sass_copy_c_string` or `sass_alloc_memory`.
**Building a file compiler**
context = sass_make_file_context("file.scss")
options = sass_file_context_get_options(context)
sass_option_set_precision(options, 1)
sass_option_set_source_comments(options, true)
sass_file_context_set_options(context, options)
compiler = sass_make_file_compiler(sass_context)
sass_compiler_parse(compiler)
sass_compiler_execute(compiler)
output = sass_context_get_output_string(context)
// Retrieve errors during compilation
error_status = sass_context_get_error_status(context)
json_error = sass_context_get_error_json(context)
// Release memory dedicated to the C compiler
sass_delete_compiler(compiler)
**Building a data compiler**
// LibSass takes over memory owenership, make sure to allocate
// a buffer via `sass_alloc_memory` or `sass_copy_c_string`.
buffer = sass_copy_c_string("div { a { color: blue; } }")
context = sass_make_data_context(buffer)
options = sass_data_context_get_options(context)
sass_option_set_precision(options, 1)
sass_option_set_source_comments(options, true)
sass_data_context_set_options(context, options)
compiler = sass_make_data_compiler(context)
sass_compiler_parse(compiler)
sass_compiler_execute(compiler)
output = sass_context_get_output_string(context)
// div a { color: blue; }
// Retrieve errors during compilation
error_status = sass_context_get_error_status(context)
json_error = sass_context_get_error_json(context)
// Release memory dedicated to the C compiler
sass_delete_compiler(compiler)
## Sass Context Internals
Everything is stored in structs:
```C
struct Sass_Options;
struct Sass_Context : Sass_Options;
struct Sass_File_context : Sass_Context;
struct Sass_Data_context : Sass_Context;
```
This mirrors very well how `libsass` uses these structures.
- `Sass_Options` holds everything you feed in before the compilation. It also hosts
`input_path` and `output_path` options, because they are used to generate/calculate
relative links in source-maps. The `input_path` is shared with `Sass_File_Context`.
- `Sass_Context` holds all the data returned by the compilation step.
- `Sass_File_Context` is a specific implementation that requires no additional fields
- `Sass_Data_Context` is a specific implementation that adds the `input_source` field
Structs can be down-casted to access `context` or `options`!
## Memory handling and life-cycles
We keep memory around for as long as the main [context](api-context.md) object
is not destroyed (`sass_delete_context`). LibSass will create copies of most
inputs/options beside the main sass code. You need to allocate and fill that
buffer before passing it to LibSass. You may also overtake memory management
from libsass for certain return values (i.e. `sass_context_take_output_string`).
Make sure to free it via `sass_free_memory`.
```C
// to allocate buffer to be filled
void* sass_alloc_memory(size_t size);
// to allocate a buffer from existing string
char* sass_copy_c_string(const char* str);
// to free overtaken memory when done
void sass_free_memory(void* ptr);
```
## Miscellaneous API functions
```C
// Some convenient string helper function
char* sass_string_unquote (const char* str);
char* sass_string_quote (const char* str, const char quote_mark);
// Get compiled libsass version
const char* libsass_version(void);
// Implemented sass language version
// Hardcoded version 3.4 for time being
const char* libsass_language_version(void);
```
## Common Pitfalls
**input_path**
The `input_path` is part of `Sass_Options`, but it also is the main option for
`Sass_File_Context`. It is also used to generate relative file links in source-
maps. Therefore it is pretty useful to pass this information if you have a
`Sass_Data_Context` and know the original path.
**output_path**
Be aware that `libsass` does not write the output file itself. This option
merely exists to give `libsass` the proper information to generate links in
source-maps. The file has to be written to the disk by the
binding/implementation. If the `output_path` is omitted, `libsass` tries to
extrapolate one from the `input_path` by replacing (or adding) the file ending
with `.css`.
## Error Codes
The `error_code` is integer value which indicates the type of error that
occurred inside the LibSass process. Following is the list of error codes along
with the short description:
* 1: normal errors like parsing or `eval` errors
* 2: bad allocation error (memory error)
* 3: "untranslated" C++ exception (`throw std::exception`)
* 4: legacy string exceptions ( `throw const char*` or `std::string` )
* 5: Some other unknown exception
Although for the API consumer, error codes do not offer much value except
indicating whether *any* error occurred during the compilation, it helps
debugging the LibSass internal code paths.
## Real-World Implementations
The proof is in the pudding, so we have highlighted a few implementations that
should be on par with the latest LibSass interface version. Some of them may not
have all features implemented!
1. [Perl Example](https://github.com/sass/perl-libsass/blob/master/Sass.xs)
2. [Go Example](https://godoc.org/github.com/wellington/go-libsass#example-Compiler--Stdin)
3. [Node Example](https://github.com/sass/node-sass/blob/master/src/binding.cpp)
## ABI forward compatibility
We use a functional API to make dynamic linking more robust and future
compatible. The API is not yet 100% stable, so we do not yet guarantee
[ABI](https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html) forward
compatibility.
## Plugins (experimental)
LibSass can load plugins from directories. Just define `plugin_path` on context
options to load all plugins from the directories. To implement plugins, please
consult the following example implementations.
- https://github.com/mgreter/libsass-glob
- https://github.com/mgreter/libsass-math
- https://github.com/mgreter/libsass-digest
## Internal Structs
- [Sass Context Internals](api-context-internal.md)
- [Sass Value Internals](api-value-internal.md)
- [Sass Function Internals](api-function-internal.md)
- [Sass Importer Internals](api-importer-internal.md)
libsass-3.6.3/docs/api-function-example.md 0000664 0000000 0000000 00000004145 13557420656 0020503 0 ustar 00root root 0000000 0000000 ## Example main.c
```C
#include
#include
#include "sass/context.h"
union Sass_Value* call_fn_foo(const union Sass_Value* s_args, Sass_Function_Entry cb, struct Sass_Compiler* comp)
{
// get context/option struct associated with this compiler
struct Sass_Context* ctx = sass_compiler_get_context(comp);
struct Sass_Options* opts = sass_compiler_get_options(comp);
// get information about previous importer entry from the stack
Sass_Import_Entry import = sass_compiler_get_last_import(comp);
const char* prev_abs_path = sass_import_get_abs_path(import);
const char* prev_imp_path = sass_import_get_imp_path(import);
// get the cookie from function descriptor
void* cookie = sass_function_get_cookie(cb);
// we actually abuse the void* to store an "int"
return sass_make_number((intptr_t)cookie, "px");
}
int main( int argc, const char* argv[] )
{
// get the input file from first argument or use default
const char* input = argc > 1 ? argv[1] : "styles.scss";
// create the file context and get all related structs
struct Sass_File_Context* file_ctx = sass_make_file_context(input);
struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
// allocate a custom function caller
Sass_Function_Entry fn_foo =
sass_make_function("foo()", call_fn_foo, (void*)42);
// create list of all custom functions
Sass_Function_List fn_list = sass_make_function_list(1);
sass_function_set_list_entry(fn_list, 0, fn_foo);
sass_option_set_c_functions(ctx_opt, fn_list);
// context is set up, call the compile step now
int status = sass_compile_file_context(file_ctx);
// print the result or the error to the stdout
if (status == 0) puts(sass_context_get_output_string(ctx));
else puts(sass_context_get_error_message(ctx));
// release allocated memory
sass_delete_file_context(file_ctx);
// exit status
return status;
}
```
### Compile main.c
```bash
gcc -c main.c -o main.o
gcc -o sample main.o -lsass
echo "foo { margin: foo(); }" > foo.scss
./sample foo.scss => "foo { margin: 42px }"
```
libsass-3.6.3/docs/api-function-internal.md 0000664 0000000 0000000 00000000244 13557420656 0020660 0 ustar 00root root 0000000 0000000 ```C
// Struct to hold custom function callback
struct Sass_Function {
const char* signature;
Sass_Function_Fn function;
void* cookie;
};
```
libsass-3.6.3/docs/api-function.md 0000664 0000000 0000000 00000006617 13557420656 0017060 0 ustar 00root root 0000000 0000000 Sass functions are used to define new custom functions callable by Sass code. They are also used to overload debug or error statements. You can also define a fallback function, which is called for every unknown function found in the Sass code. Functions get passed zero or more `Sass_Values` (a `Sass_List` value) and they must also return a `Sass_Value`. Return a `Sass_Error` if you want to signal an error.
## Special signatures
- `*` - Fallback implementation
- `@warn` - Overload warn statements
- `@error` - Overload error statements
- `@debug` - Overload debug statements
Note: The fallback implementation will be given the name of the called function as the first argument, before all the original function arguments. These features are pretty new and should be considered experimental.
### Basic Usage
```C
#include "sass/functions.h"
```
## Sass Function API
```C
// Forward declaration
struct Sass_Compiler;
struct Sass_Function;
// Typedef helpers for custom functions lists
typedef struct Sass_Function (*Sass_Function_Entry);
typedef struct Sass_Function* (*Sass_Function_List);
// Typedef defining function signature and return type
typedef union Sass_Value* (*Sass_Function_Fn)
(const union Sass_Value*, Sass_Function_Entry cb, struct Sass_Compiler* compiler);
// Creators for sass function list and function descriptors
Sass_Function_List sass_make_function_list (size_t length);
Sass_Function_Entry sass_make_function (const char* signature, Sass_Function_Fn cb, void* cookie);
// In case you need to free them yourself
void sass_delete_function (Sass_Function_Entry entry);
void sass_delete_function_list (Sass_Function_List list);
// Setters and getters for callbacks on function lists
Sass_Function_Entry sass_function_get_list_entry(Sass_Function_List list, size_t pos);
void sass_function_set_list_entry(Sass_Function_List list, size_t pos, Sass_Function_Entry cb);
// Setters to insert an entry into the import list (you may also use [] access directly)
// Since we are dealing with pointers they should have a guaranteed and fixed size
void sass_import_set_list_entry (Sass_Import_List list, size_t idx, Sass_Import_Entry entry);
Sass_Import_Entry sass_import_get_list_entry (Sass_Import_List list, size_t idx);
// Getters for custom function descriptors
const char* sass_function_get_signature (Sass_Function_Entry cb);
Sass_Function_Fn sass_function_get_function (Sass_Function_Entry cb);
void* sass_function_get_cookie (Sass_Function_Entry cb);
// Getters for callee entry
const char* sass_callee_get_name (Sass_Callee_Entry);
const char* sass_callee_get_path (Sass_Callee_Entry);
size_t sass_callee_get_line (Sass_Callee_Entry);
size_t sass_callee_get_column (Sass_Callee_Entry);
enum Sass_Callee_Type sass_callee_get_type (Sass_Callee_Entry);
Sass_Env_Frame sass_callee_get_env (Sass_Callee_Entry);
// Getters and Setters for environments (lexical, local and global)
union Sass_Value* sass_env_get_lexical (Sass_Env_Frame, const char*);
void sass_env_set_lexical (Sass_Env_Frame, const char*, union Sass_Value*);
union Sass_Value* sass_env_get_local (Sass_Env_Frame, const char*);
void sass_env_set_local (Sass_Env_Frame, const char*, union Sass_Value*);
union Sass_Value* sass_env_get_global (Sass_Env_Frame, const char*);
void sass_env_set_global (Sass_Env_Frame, const char*, union Sass_Value*);
```
### More links
- [Sass Function Example](api-function-example.md)
- [Sass Function Internal](api-function-internal.md)
libsass-3.6.3/docs/api-importer-example.md 0000664 0000000 0000000 00000007105 13557420656 0020516 0 ustar 00root root 0000000 0000000 ## Example importer.c
```C
#include
#include
#include "sass/context.h"
Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
{
// get the cookie from importer descriptor
void* cookie = sass_importer_get_cookie(cb);
Sass_Import_List list = sass_make_import_list(2);
char* local = sass_copy_c_string("local { color: green; }");
char* remote = sass_copy_c_string("remote { color: red; }");
list[0] = sass_make_import_entry("/tmp/styles.scss", local, 0);
list[1] = sass_make_import_entry("http://www.example.com", remote, 0);
return list;
}
int main( int argc, const char* argv[] )
{
// get the input file from first argument or use default
const char* input = argc > 1 ? argv[1] : "styles.scss";
// create the file context and get all related structs
struct Sass_File_Context* file_ctx = sass_make_file_context(input);
struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
// allocate custom importer
Sass_Importer_Entry c_imp =
sass_make_importer(sass_importer, 0, 0);
// create list for all custom importers
Sass_Importer_List imp_list = sass_make_importer_list(1);
// put only the importer on to the list
sass_importer_set_list_entry(imp_list, 0, c_imp);
// register list on to the context options
sass_option_set_c_importers(ctx_opt, imp_list);
// context is set up, call the compile step now
int status = sass_compile_file_context(file_ctx);
// print the result or the error to the stdout
if (status == 0) puts(sass_context_get_output_string(ctx));
else puts(sass_context_get_error_message(ctx));
// release allocated memory
sass_delete_file_context(file_ctx);
// exit status
return status;
}
```
Compile importer.c
```bash
gcc -c importer.c -o importer.o
gcc -o importer importer.o -lsass
echo "@import 'foobar';" > importer.scss
./importer importer.scss
```
## Importer Behavior Examples
```C
Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
// let LibSass handle the import request
return NULL;
}
Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
// let LibSass handle the request
// swallows »@import "http://…"« pass-through
// (arguably a bug)
Sass_Import_List list = sass_make_import_list(1);
list[0] = sass_make_import_entry(path, 0, 0);
return list;
}
Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
// return an error to halt execution
Sass_Import_List list = sass_make_import_list(1);
const char* message = "some error message";
list[0] = sass_make_import_entry(path, 0, 0);
sass_import_set_error(list[0], sass_copy_c_string(message), 0, 0);
return list;
}
Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
// let LibSass load the file identifed by the importer
Sass_Import_List list = sass_make_import_list(1);
list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
return list;
}
Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
// completely hide the import
// (arguably a bug)
Sass_Import_List list = sass_make_import_list(0);
return list;
}
Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
// completely hide the import
// (arguably a bug)
Sass_Import_List list = sass_make_import_list(1);
list[0] = sass_make_import_entry(0, 0, 0);
return list;
}
```
libsass-3.6.3/docs/api-importer-internal.md 0000664 0000000 0000000 00000000645 13557420656 0020701 0 ustar 00root root 0000000 0000000 ```C
// External import entry
struct Sass_Import {
char* imp_path; // path as found in the import statement
char *abs_path; // path after importer has resolved it
char* source;
char* srcmap;
// error handling
char* error;
size_t line;
size_t column;
};
// Struct to hold importer callback
struct Sass_Importer {
Sass_Importer_Fn importer;
double priority;
void* cookie;
};
```
libsass-3.6.3/docs/api-importer.md 0000664 0000000 0000000 00000010407 13557420656 0017064 0 ustar 00root root 0000000 0000000 By using custom importers, Sass stylesheets can be implemented in any possible way, such as by being loaded via a remote server. Please note: this feature is experimental and is implemented differently than importers in Ruby Sass. Imports must be relative to the parent import context and therefore we need to pass this information to the importer callback. This is currently done by passing the complete import string/path of the previous import context.
## Return Imports
You actually have to return a list of imports, since some importers may want to import multiple files from one import statement (ie. a glob/star importer). The memory you pass with source and srcmap is taken over by LibSass and freed automatically when the import is done. You are also allowed to return `0` instead of a list, which will tell LibSass to handle the import by itself (as if no custom importer was in use).
```C
Sass_Import_Entry* rv = sass_make_import_list(1);
rv[0] = sass_make_import(rel, abs, source, srcmap);
```
Every import will then be included in LibSass. You are allowed to only return a file path without any loaded source. This way you can ie. implement rewrite rules for import paths and leave the loading part for LibSass.
Please note that LibSass doesn't use the srcmap parameter yet. It has been added to not deprecate the C-API once support has been implemented. It will be used to re-map the actual sourcemap with the provided ones.
### Basic Usage
```C
#include "sass/functions.h"
```
## Sass Importer API
```C
// Forward declaration
struct Sass_Import;
// Forward declaration
struct Sass_C_Import_Descriptor;
// Typedef defining the custom importer callback
typedef struct Sass_C_Import_Descriptor (*Sass_C_Import_Callback);
// Typedef defining the importer c function prototype
typedef Sass_Import_Entry* (*Sass_C_Import_Fn) (const char* url, const char* prev, void* cookie);
// Creators for custom importer callback (with some additional pointer)
// The pointer is mostly used to store the callback into the actual function
Sass_C_Import_Callback sass_make_importer (Sass_C_Import_Fn, void* cookie);
// Getters for import function descriptors
Sass_C_Import_Fn sass_import_get_function (Sass_C_Import_Callback fn);
void* sass_import_get_cookie (Sass_C_Import_Callback fn);
// Deallocator for associated memory
void sass_delete_importer (Sass_C_Import_Callback fn);
// Creator for sass custom importer return argument list
Sass_Import_Entry* sass_make_import_list (size_t length);
// Creator for a single import entry returned by the custom importer inside the list
Sass_Import_Entry sass_make_import_entry (const char* path, char* source, char* srcmap);
Sass_Import_Entry sass_make_import (const char* rel, const char* abs, char* source, char* srcmap);
// set error message to abort import and to print out a message (path from existing object is used in output)
Sass_Import_Entry sass_import_set_error(Sass_Import_Entry import, const char* message, size_t line, size_t col);
// Setters to insert an entry into the import list (you may also use [] access directly)
// Since we are dealing with pointers they should have a guaranteed and fixed size
void sass_import_set_list_entry (Sass_Import_Entry* list, size_t idx, Sass_Import_Entry entry);
Sass_Import_Entry sass_import_get_list_entry (Sass_Import_Entry* list, size_t idx);
// Getters for import entry
const char* sass_import_get_imp_path (Sass_Import_Entry);
const char* sass_import_get_abs_path (Sass_Import_Entry);
const char* sass_import_get_source (Sass_Import_Entry);
const char* sass_import_get_srcmap (Sass_Import_Entry);
// Explicit functions to take ownership of these items
// The property on our struct will be reset to NULL
char* sass_import_take_source (Sass_Import_Entry);
char* sass_import_take_srcmap (Sass_Import_Entry);
// Getters for import error entries
size_t sass_import_get_error_line (Sass_Import_Entry);
size_t sass_import_get_error_column (Sass_Import_Entry);
const char* sass_import_get_error_message (Sass_Import_Entry);
// Deallocator for associated memory (incl. entries)
void sass_delete_import_list (Sass_Import_Entry*);
// Just in case we have some stray import structs
void sass_delete_import (Sass_Import_Entry);
```
### More links
- [Sass Importer Example](api-importer-example.md)
- [Sass Importer Internal](api-importer-internal.md)
libsass-3.6.3/docs/api-value-example.md 0000664 0000000 0000000 00000002576 13557420656 0020000 0 ustar 00root root 0000000 0000000 ## Example operation.c
```C
#include
#include
#include "sass/values.h"
int main( int argc, const char* argv[] )
{
// create two new sass values to be added
union Sass_Value* string = sass_make_string("String");
union Sass_Value* number = sass_make_number(42, "nits");
// invoke the add operation which returns a new sass value
union Sass_Value* total = sass_value_op(ADD, string, number);
// no further use for the two operands
sass_delete_value(string);
sass_delete_value(number);
// this works since libsass will always return a
// string for add operations with a string as the
// left hand side. But you should never rely on it!
puts(sass_string_get_value(total));
// invoke stringification (uncompressed with precision of 5)
union Sass_Value* result = sass_value_stringify(total, false, 5);
// no further use for the sum
sass_delete_value(total);
// print the result - you may want to make
// sure result is indeed a string, although
// stringify guarantees to return a string
// if (sass_value_is_string(result)) {}
// really depends on your level of paranoia
puts(sass_string_get_value(result));
// finally free result
sass_delete_value(result);
// exit status
return 0;
}
```
## Compile operation.c
```bash
gcc -c operation.c -o operation.o
gcc -o operation operation.o -lsass
./operation # => String42nits
```
libsass-3.6.3/docs/api-value-internal.md 0000664 0000000 0000000 00000002371 13557420656 0020152 0 ustar 00root root 0000000 0000000 ```C
struct Sass_Unknown {
enum Sass_Tag tag;
};
struct Sass_Boolean {
enum Sass_Tag tag;
bool value;
};
struct Sass_Number {
enum Sass_Tag tag;
double value;
char* unit;
};
struct Sass_Color {
enum Sass_Tag tag;
double r;
double g;
double b;
double a;
};
struct Sass_String {
enum Sass_Tag tag;
char* value;
};
struct Sass_List {
enum Sass_Tag tag;
enum Sass_Separator separator;
size_t length;
// null terminated "array"
union Sass_Value** values;
};
struct Sass_Map {
enum Sass_Tag tag;
size_t length;
struct Sass_MapPair* pairs;
};
struct Sass_Null {
enum Sass_Tag tag;
};
struct Sass_Error {
enum Sass_Tag tag;
char* message;
};
struct Sass_Warning {
enum Sass_Tag tag;
char* message;
};
union Sass_Value {
struct Sass_Unknown unknown;
struct Sass_Boolean boolean;
struct Sass_Number number;
struct Sass_Color color;
struct Sass_String string;
struct Sass_List list;
struct Sass_Map map;
struct Sass_Null null;
struct Sass_Error error;
struct Sass_Warning warning;
};
struct Sass_MapPair {
union Sass_Value* key;
union Sass_Value* value;
};
```
libsass-3.6.3/docs/api-value.md 0000664 0000000 0000000 00000013770 13557420656 0016345 0 ustar 00root root 0000000 0000000 `Sass_Values` are used to pass values and their types between the implementer
and LibSass. Sass knows various different value types (including nested arrays
and hash-maps). If you implement a binding to another programming language, you
have to find a way to [marshal][1] (convert) `Sass_Values` between the target
language and C. `Sass_Values` are currently only used by custom functions, but
it should also be possible to use them without a compiler context.
[1]: https://en.wikipedia.org/wiki/Marshalling_%28computer_science%29
### Basic Usage
```C
#include "sass/values.h"
```
```C
// Type for Sass values
enum Sass_Tag {
SASS_BOOLEAN,
SASS_NUMBER,
SASS_COLOR,
SASS_STRING,
SASS_LIST,
SASS_MAP,
SASS_NULL,
SASS_ERROR,
SASS_WARNING
};
// Tags for denoting Sass list separators
enum Sass_Separator {
SASS_COMMA,
SASS_SPACE,
// only used internally to represent a hash map before evaluation
// otherwise we would be too early to check for duplicate keys
SASS_HASH
};
// Value Operators
enum Sass_OP {
AND, OR, // logical connectives
EQ, NEQ, GT, GTE, LT, LTE, // arithmetic relations
ADD, SUB, MUL, DIV, MOD, // arithmetic functions
NUM_OPS // so we know how big to make the op table
};
```
### Sass Value API
```C
// Forward declaration
union Sass_Value;
// Creator functions for all value types
union Sass_Value* sass_make_null (void);
union Sass_Value* sass_make_boolean (bool val);
union Sass_Value* sass_make_string (const char* val);
union Sass_Value* sass_make_qstring (const char* val);
union Sass_Value* sass_make_number (double val, const char* unit);
union Sass_Value* sass_make_color (double r, double g, double b, double a);
union Sass_Value* sass_make_list (size_t len, enum Sass_Separator sep, bool is_bracketed);
union Sass_Value* sass_make_map (size_t len);
union Sass_Value* sass_make_error (const char* msg);
union Sass_Value* sass_make_warning (const char* msg);
// Generic destructor function for all types
// Will release memory of all associated Sass_Values
// Means we will delete recursively for lists and maps
void sass_delete_value (union Sass_Value* val);
// Make a deep cloned copy of the given sass value
union Sass_Value* sass_clone_value (const union Sass_Value* val);
// Stringify a Sass_Values and also return the result as a Sass_Value (of type STRING)
union Sass_Value* sass_value_stringify (const union Sass_Value* a, bool compressed, int precision);
// Execute an operation for two Sass_Values and return the result as a Sass_Value too
union Sass_Value* sass_value_op (enum Sass_OP op, const union Sass_Value* a, const union Sass_Value* b);
// Return the sass tag for a generic sass value
// Check is needed before accessing specific values!
enum Sass_Tag sass_value_get_tag (const union Sass_Value* v);
// Check value to be of a specific type
// Can also be used before accessing properties!
bool sass_value_is_null (const union Sass_Value* v);
bool sass_value_is_number (const union Sass_Value* v);
bool sass_value_is_string (const union Sass_Value* v);
bool sass_value_is_boolean (const union Sass_Value* v);
bool sass_value_is_color (const union Sass_Value* v);
bool sass_value_is_list (const union Sass_Value* v);
bool sass_value_is_map (const union Sass_Value* v);
bool sass_value_is_error (const union Sass_Value* v);
bool sass_value_is_warning (const union Sass_Value* v);
// Getters and setters for Sass_Number
double sass_number_get_value (const union Sass_Value* v);
void sass_number_set_value (union Sass_Value* v, double value);
const char* sass_number_get_unit (const union Sass_Value* v);
void sass_number_set_unit (union Sass_Value* v, char* unit);
// Getters and setters for Sass_String
const char* sass_string_get_value (const union Sass_Value* v);
void sass_string_set_value (union Sass_Value* v, char* value);
bool sass_string_is_quoted(const union Sass_Value* v);
void sass_string_set_quoted(union Sass_Value* v, bool quoted);
// Getters and setters for Sass_Boolean
bool sass_boolean_get_value (const union Sass_Value* v);
void sass_boolean_set_value (union Sass_Value* v, bool value);
// Getters and setters for Sass_Color
double sass_color_get_r (const union Sass_Value* v);
void sass_color_set_r (union Sass_Value* v, double r);
double sass_color_get_g (const union Sass_Value* v);
void sass_color_set_g (union Sass_Value* v, double g);
double sass_color_get_b (const union Sass_Value* v);
void sass_color_set_b (union Sass_Value* v, double b);
double sass_color_get_a (const union Sass_Value* v);
void sass_color_set_a (union Sass_Value* v, double a);
// Getter for the number of items in list
size_t sass_list_get_length (const union Sass_Value* v);
// Getters and setters for Sass_List
enum Sass_Separator sass_list_get_separator (const union Sass_Value* v);
void sass_list_set_separator (union Sass_Value* v, enum Sass_Separator value);
bool sass_list_get_is_bracketed (const union Sass_Value* v);
void sass_list_set_is_bracketed (union Sass_Value* v, bool value);
// Getters and setters for Sass_List values
union Sass_Value* sass_list_get_value (const union Sass_Value* v, size_t i);
void sass_list_set_value (union Sass_Value* v, size_t i, union Sass_Value* value);
// Getter for the number of items in map
size_t sass_map_get_length (const union Sass_Value* v);
// Getters and setters for Sass_Map keys and values
union Sass_Value* sass_map_get_key (const union Sass_Value* v, size_t i);
void sass_map_set_key (union Sass_Value* v, size_t i, union Sass_Value*);
union Sass_Value* sass_map_get_value (const union Sass_Value* v, size_t i);
void sass_map_set_value (union Sass_Value* v, size_t i, union Sass_Value*);
// Getters and setters for Sass_Error
char* sass_error_get_message (const union Sass_Value* v);
void sass_error_set_message (union Sass_Value* v, char* msg);
// Getters and setters for Sass_Warning
char* sass_warning_get_message (const union Sass_Value* v);
void sass_warning_set_message (union Sass_Value* v, char* msg);
```
### More links
- [Sass Value Example](api-value-example.md)
- [Sass Value Internal](api-value-internal.md)
libsass-3.6.3/docs/build-on-darwin.md 0000664 0000000 0000000 00000001430 13557420656 0017443 0 ustar 00root root 0000000 0000000 To install LibSass, make sure the OS X build tools are installed:
xcode-select --install
## Homebrew
To install homebrew, see [http://brew.sh](http://brew.sh)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
You can install the latest version of LibSass quite easily with brew.
brew install --HEAD libsass
To update this, do:
brew reinstall --HEAD libsass
Brew will build static and shared libraries, and a `libsass.pc` file in `/usr/local/lib/pkgconfig`.
To use `libsass.pc`, make sure this path is in your `PKG_CONFIG_PATH`
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
## Manually
See the linux instructions [Building-with-autotools](build-with-autotools.md) or [Building-with-makefiles](build-with-makefiles.md)
libsass-3.6.3/docs/build-on-gentoo.md 0000664 0000000 0000000 00000002401 13557420656 0017451 0 ustar 00root root 0000000 0000000 Here are two ebuilds to compile LibSass and sassc on gentoo linux. If you do not know how to use these ebuilds, you should probably read the gentoo wiki page about [portage overlays](http://wiki.gentoo.org/wiki/Overlay).
## www-misc/libsass/libsass-9999.ebuild
```ebuild
EAPI=4
inherit eutils git-2 autotools
DESCRIPTION="A C/C++ implementation of a Sass compiler."
HOMEPAGE="http://libsass.org/"
EGIT_PROJECT='libsass'
EGIT_REPO_URI="https://github.com/sass/libsass.git"
LICENSE="MIT"
SLOT="0"
KEYWORDS=""
IUSE=""
DEPEND=""
RDEPEND="${DEPEND}"
DEPEND="${DEPEND}"
pkg_pretend() {
# older gcc is not supported
local major=$(gcc-major-version)
local minor=$(gcc-minor-version)
[[ "${MERGE_TYPE}" != "binary" && ( $major > 4 || ( $major == 4 && $minor < 5 ) ) ]] && \
die "Sorry, but gcc earlier than 4.5 will not work for LibSass."
}
src_prepare() {
eautoreconf
}
```
## www-misc/sassc/sassc-9999.ebuild
```ebuild
EAPI=4
inherit eutils git-2 autotools
DESCRIPTION="Command Line Tool for LibSass."
HOMEPAGE="http://libsass.org/"
EGIT_PROJECT='sassc'
EGIT_REPO_URI="https://github.com/sass/sassc.git"
LICENSE="MIT"
SLOT="0"
KEYWORDS=""
IUSE=""
DEPEND="www-misc/libsass"
RDEPEND="${DEPEND}"
DEPEND="${DEPEND}"
src_prepare() {
eautoreconf
}
```
libsass-3.6.3/docs/build-on-windows.md 0000664 0000000 0000000 00000011302 13557420656 0017650 0 ustar 00root root 0000000 0000000 We support builds via MingGW and via Visual Studio Community 2013.
Both should be considered experimental (MinGW was better tested)!
## Building via MingGW (makefiles)
First grab the latest [MinGW for windows][1] installer. Once it is installed, you can click on continue or open the Installation Manager via `bin\mingw-get.exe`.
You need to have the following components installed:

Next we need to install [git for windows][2]. You probably want to check the option to add it to the global path, but you do not need to install the unix tools.
If you want to run the spec test-suite you also need [ruby][3] and a few gems available. Grab the [latest installer][3] and make sure to add it the global path. Then install the missing gems:
```bash
gem install minitest
```
### Mount the mingw root directory
As mentioned in the [MinGW Getting Started](http://www.mingw.org/wiki/Getting_Started#toc5) guide, you should edit `C:\MinGW\msys\1.0\etc\fstab` to contain the following line:
```
C:\MinGW /mingw
```
### Starting a "MingGW" console
Create a batch file with this content:
```bat
@echo off
set PATH=C:\MinGW\bin;%PATH%
REM only needed if not already available
set PATH=%PROGRAMFILES%\git\bin;%PATH%
REM C:\MinGW\msys\1.0\msys.bat
cmd
```
Execute it and make sure these commands can be called: `git`, `mingw32-make`, `rm` and `gcc`! Once this is all set, you should be ready to compile `libsass`!
### Get the sources
```bash
# using git is preferred
git clone https://github.com/sass/libsass.git
# only needed for sassc and/or testsuite
git clone https://github.com/sass/sassc.git libsass/sassc
git clone https://github.com/sass/sass-spec.git libsass/sass-spec
```
### Decide for static or shared library
`libsass` can be built and linked as a `static` or as a `shared` library. The default is `static`. To change it you can set the `BUILD` environment variable:
```bat
set BUILD="shared"
```
### Compile the library
```bash
mingw32-make -C libsass
```
### Results can be found in
```bash
$ ls libsass/lib
libsass.a libsass.dll libsass.so
```
### Run the spec test-suite
```bash
mingw32-make -C libsass test_build
```
## Building via MingGW 64bit (makefiles)
Building libass to dll on window 64bit.
+ downloads [MinGW64 for windows7 64bit](http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.2/threads-win32/seh/x86_64-4.9.2-release-win32-seh-rt_v3-rev0.7z/download) , and unzip to "C:\mingw64".
+ Create a batch file with this content:
```bat
@echo off
set PATH=C:\mingw64\bin;%PATH%
set CC=gcc
REM only needed if not already available
set PATH=%PROGRAMFILES%\Git\bin;%PATH%
REM C:\MinGW\msys\1.0\msys.bat
cmd
```
+ By default , mingw64 dll will depends on "mingwm10.dll、 libgcc_s_dw2-1.dll" , we can modify Makefile to fix this:(add "-static")
``` bash
lib/libsass.dll: $(COBJECTS) $(OBJECTS) $(RCOBJECTS)
$(MKDIR) lib
$(CXX) -shared $(LDFLAGS) -o $@ $(COBJECTS) $(OBJECTS) $(RCOBJECTS) $(LDLIBS) -s -static -Wl,--subsystem,windows,--out-implib,lib/libsass.a
```
+ Compile the library
```bash
mingw32-make -C libsass
```
By the way , if you are using java jna , [JNAerator](http://jnaerator.googlecode.com/) is a good tool.
## Building via Visual Studio Community 2013
Open a Visual Studio 2013 command prompt:
- `VS2013 x86 Native Tools Command Prompt`
Note: When I installed the community edition, I only got the 2012 command prompts. I copied them from the Startmenu to the Desktop and adjusted the paths from `Visual Studio 11.0` to `Visual Studio 12.0`. Since `libsass` uses some `C++11` features, you need at least a MSVC 2013 compiler (v120).
### Get the source
```bash
# using git is preferred
git clone https://github.com/sass/libsass.git
git clone https://github.com/sass/sassc.git libsass/sassc
# only needed if you want to run the testsuite
git clone https://github.com/sass/sass-spec.git libsass/sass-spec
```
### Compile sassc
Sometimes `msbuild` seems not available from the command prompt. Just search for it and add it to the global path. It seems to be included in the .net folders too.
```bat
cd libsass
REM set PATH=%PATH%;%PROGRAMFILES%\MSBuild\12.0\Bin
msbuild /m:4 /p:Configuration=Release win\libsass.sln
REM running the spec test-suite manually (needs ruby and minitest gem)
ruby sass-spec\sass-spec.rb -c win\bin\sassc.exe -s --impl libsass sass-spec/spec
cd ..
```
[1]: http://sourceforge.net/projects/mingw/files/latest/download?source=files
[2]: https://msysgit.github.io/
[3]: http://rubyinstaller.org/
libsass-3.6.3/docs/build-shared-library.md 0000664 0000000 0000000 00000002612 13557420656 0020460 0 ustar 00root root 0000000 0000000 This page is mostly intended for people that want to build a system library that gets distributed via RPMs or other means. This is currently in a experimental phase, as we currently do not really guarantee any ABI forward compatibility. The C API was rewritten to make this possible in the future, but we want to wait some more time till we can call this final and stable.
Building via autotools
--
You want to build a system library only via autotools, since it will create the proper `libtool` files to make it loadable on multiple systems. We hope this works correctly, but nobody of the `libsass` core team has much knowledge in this area. Therefore we are open for comments or improvements by people that have more experience in that matter (like package maintainers from various linux distributions).
```bash
apt-get install autoconf libtool
git clone https://github.com/sass/libsass.git
cd libsass
autoreconf --force --install
./configure \
--disable-tests \
--disable-static \
--enable-shared \
--prefix=/usr
make -j5 install
cd ..
```
This should install these files
```bash
# $ ls -la /usr/lib/libsass.*
/usr/lib/libsass.la
/usr/lib/libsass.so -> libsass.so.0.0.9
/usr/lib/libsass.so.0 -> libsass.so.0.0.9
/usr/lib/libsass.so.0.0.9
# $ ls -la /usr/include/sass*
/usr/include/sass.h
/usr/include/sass2scss.h
/usr/include/sass/context.h
/usr/include/sass/functions.h
/usr/include/sass/values.h
```
libsass-3.6.3/docs/build-with-autotools.md 0000664 0000000 0000000 00000003757 13557420656 0020565 0 ustar 00root root 0000000 0000000 ### Get the sources
```bash
# using git is preferred
git clone https://github.com/sass/libsass.git
# only needed for sassc and/or testsuite
git clone https://github.com/sass/sassc.git libsass/sassc
git clone https://github.com/sass/sass-spec.git libsass/sass-spec
```
### Prerequisites
In order to run autotools you need a few tools installed on your system.
```bash
yum install automake libtool # RedHat Linux
emerge -a automake libtool # Gentoo Linux
pkgin install automake libtool # SmartOS
```
### Create configure script
```bash
cd libsass
autoreconf --force --install
cd ..
```
### Create custom makefiles
```bash
cd libsass
./configure \
--disable-tests \
--disable-shared \
--prefix=/usr
cd ..
```
### Build the library
```bash
make -C libsass -j5
```
### Install the library
The library will be installed to the location given as `prefix` to `configure`. This is standard behavior for autotools and not `libsass` specific.
```bash
make -C libsass -j5 install
```
### Configure options
The `configure` script is created by autotools. To get an overview of available options you can call `./configure --help`. When you execute this script, it will create specific makefiles, which you then use via the regular make command.
There are some `libsass` specific options:
```
Optional Features:
--enable-tests enable testing the build
--enable-coverage enable coverage report for test suite
--enable-shared build shared libraries [default=yes]
--enable-static build static libraries [default=yes]
Optional Packages:
--with-sassc-dir= specify directory of sassc sources for
testing (default: sassc)
--with-sass-spec-dir= specify directory of sass-spec for testing
(default: sass-spec)
```
### Build sassc and run spec test-suite
```bash
cd libsass
autoreconf --force --install
./configure \
--enable-tests \
--enable-shared \
--prefix=/usr
make -j5 test_build
cd ..
```
libsass-3.6.3/docs/build-with-makefiles.md 0000664 0000000 0000000 00000003100 13557420656 0020452 0 ustar 00root root 0000000 0000000 ### Get the sources
```bash
# using git is preferred
git clone https://github.com/sass/libsass.git
# only needed for sassc and/or testsuite
git clone https://github.com/sass/sassc.git libsass/sassc
git clone https://github.com/sass/sass-spec.git libsass/sass-spec
```
### Decide for static or shared library
`libsass` can be built and linked as a `static` or as a `shared` library. The default is `static`. To change it you can set the `BUILD` environment variable:
```bash
export BUILD="shared"
```
Alternatively you can also define it directly when calling make:
```bash
BUILD="shared" make ...
```
### Compile the library
```bash
make -C libsass -j5
```
### Results can be found in
```bash
$ ls libsass/lib
libsass.a libsass.so
```
### Install onto the system
We recommend to use [autotools to install](build-with-autotools.md) libsass onto the
system, since that brings all the benefits of using libtools as the main install method.
If you still want to install libsass via the makefile, you need to make sure that gnu
`install` utility (or compatible) is installed on your system.
```bash
yum install coreutils # RedHat Linux
emerge -a coreutils # Gentoo Linux
pkgin install coreutils # SmartOS
```
You can set the install location by setting `PREFIX`
```bash
PREFIX="/opt/local" make install
```
### Compling sassc
```bash
# Let build know library location
export SASS_LIBSASS_PATH="`pwd`/libsass"
# Invokes the sassc makefile
make -C libsass -j5 sassc
```
### Run the spec test-suite
```bash
# needs ruby available
# also gem install minitest
make -C libsass -j5 test_build
```
libsass-3.6.3/docs/build-with-mingw.md 0000664 0000000 0000000 00000006550 13557420656 0017647 0 ustar 00root root 0000000 0000000 ## Building LibSass with MingGW (makefiles)
First grab the latest [MinGW for windows][1] installer. Once it is installed, you can click on continue or open the Installation Manager via `bin\mingw-get.exe`.
You need to have the following components installed:

Next we need to install [git for windows][2]. You probably want to check the option to add it to the global path, but you do not need to install the unix tools.
If you want to run the spec test-suite you also need [ruby][3] and a few gems available. Grab the [latest installer][3] and make sure to add it the global path. Then install the missing gems:
```bash
gem install minitest
```
### Mount the mingw root directory
As mentioned in the [MinGW Getting Started](http://www.mingw.org/wiki/Getting_Started#toc5) guide, you should edit `C:\MinGW\msys\1.0\etc\fstab` to contain the following line:
```
C:\MinGW /mingw
```
### Starting a "MingGW" console
Create a batch file with this content:
```bat
@echo off
set PATH=C:\MinGW\bin;%PATH%
REM only needed if not already available
set PATH=%PROGRAMFILES%\git\bin;%PATH%
REM C:\MinGW\msys\1.0\msys.bat
cmd
```
Execute it and make sure these commands can be called: `git`, `mingw32-make`, `rm` and `gcc`! Once this is all set, you should be ready to compile `libsass`!
### Get the sources
```bash
# using git is preferred
git clone https://github.com/sass/libsass.git
# only needed for sassc and/or testsuite
git clone https://github.com/sass/sassc.git libsass/sassc
git clone https://github.com/sass/sass-spec.git libsass/sass-spec
```
### Decide for static or shared library
`libsass` can be built and linked as a `static` or as a `shared` library. The default is `static`. To change it you can set the `BUILD` environment variable:
```bat
set BUILD="shared"
```
### Compile the library
```bash
mingw32-make -C libsass
```
### Results can be found in
```bash
$ ls libsass/lib
libsass.a libsass.dll libsass.so
```
### Run the spec test-suite
```bash
mingw32-make -C libsass test_build
```
## Building via MingGW 64bit (makefiles)
Building libass to dll on window 64bit.
Download [MinGW64 for windows7 64bit](http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.2/threads-win32/seh/x86_64-4.9.2-release-win32-seh-rt_v3-rev0.7z/download) and unzip to "C:\mingw64".
Create a batch file with this content:
```bat
@echo off
set PATH=C:\mingw64\bin;%PATH%
set CC=gcc
REM only needed if not already available
set PATH=%PROGRAMFILES%\Git\bin;%PATH%
REM C:\MinGW\msys\1.0\msys.bat
cmd
```
By default, mingw64 dll will depends on "mingwm10.dll、 libgcc_s_dw2-1.dll", we can modify Makefile to fix this:(add "-static")
``` bash
lib/libsass.dll: $(COBJECTS) $(OBJECTS) $(RCOBJECTS)
$(MKDIR) lib
$(CXX) -shared $(LDFLAGS) -o $@ $(COBJECTS) $(OBJECTS) $(RCOBJECTS) $(LDLIBS) -s -static -Wl,--subsystem,windows,--out-implib,lib/libsass.a
```
Compile the library
```bash
mingw32-make -C libsass
```
By the way, if you are using java jna, [JNAerator](http://jnaerator.googlecode.com/) is a good tool.
[1]: http://sourceforge.net/projects/mingw/files/latest/download?source=files
[2]: https://msysgit.github.io/
[3]: http://rubyinstaller.org/
libsass-3.6.3/docs/build-with-visual-studio.md 0000664 0000000 0000000 00000005603 13557420656 0021334 0 ustar 00root root 0000000 0000000 ## Building LibSass with Visual Studio
### Requirements:
The minimum requirement to build LibSass with Visual Studio is "Visual Studio 2013 Express for Desktop".
Additionally, it is recommended to have `git` installed and available in `PATH`, so to deduce the `libsass` version information. For instance, if GitHub for Windows (https://windows.github.com/) is installed, the `PATH` will have an entry resembling: `X:\Users\\AppData\Local\GitHub\PortableGit_\cmd\` (where `X` is the drive letter of system drive). If `git` is not available, inquiring the LibSass version will result in `[NA]`.
### Build Steps:
#### From Visual Studio:
On opening the `win\libsass.sln` solution and build (Ctrl+Shift+B) to build `libsass.dll`.
To Build LibSass as a static Library, it is recommended to set an environment variable `LIBSASS_STATIC_LIB` before launching the project:
```cmd
cd path\to\libsass
SET LIBSASS_STATIC_LIB=1
::
:: or in PowerShell:
:: $env:LIBSASS_STATIC_LIB=1
::
win\libsass.sln
```
Visual Studio will form the filtered source tree as shown below:

`Header Files` contains the .h and .hpp files, while `Source Files` covers `.c` and `.cpp`. The other used headers/sources will appear under `External Dependencies`.
If there is a LibSass code file appearing under External Dependencies, it can be changed by altering the `win\libsass.vcxproj.filters` file or dragging in Solution Explorer.
#### From Command Prompt:
Notice that in the following commands:
* If the platform is 32-bit Windows, replace `ProgramFiles(x86)` with `ProgramFiles`.
* To build with Visual Studio 2015, replace `12.0` with `14.0` in the aforementioned command.
Open a command prompt:
To build dynamic/shared library (`libsass.dll`):
```cmd
:: debug build:
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild" win\libsass.sln
:: release build:
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild" win\libsass.sln ^
/p:Configuration=Release
```
To build static library (`libsass.lib`):
```cmd
:: debug build:
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild" win\libsass.sln ^
/p:LIBSASS_STATIC_LIB=1
:: release build:
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild" win\libsass.sln ^
/p:LIBSASS_STATIC_LIB=1 /p:Configuration=Release
```
#### From PowerShell:
To build dynamic/shared library (`libsass.dll`):
```powershell
# debug build:
&"${env:ProgramFiles(x86)}\MSBuild\12.0\Bin\MSBuild" win\libsass.sln
# release build:
&"${env:ProgramFiles(x86)}\MSBuild\12.0\Bin\MSBuild" win\libsass.sln `
/p:Configuration=Release
```
To build static library (`libsass.lib`):
```powershell
# build:
&"${env:ProgramFiles(x86)}\MSBuild\12.0\Bin\MSBuild" win\libsass.sln `
/p:LIBSASS_STATIC_LIB=1
# release build:
&"${env:ProgramFiles(x86)}\MSBuild\12.0\Bin\MSBuild" win\libsass.sln `
/p:LIBSASS_STATIC_LIB=1 /p:Configuration=Release
```
libsass-3.6.3/docs/build.md 0000664 0000000 0000000 00000011355 13557420656 0015556 0 ustar 00root root 0000000 0000000 `libsass` is only a library and does not do much on its own. You need an implementation that you can use from the [command line][6]. Or some [bindings|Implementations][9] to use it within your favorite programming language. You should be able to get [`sassc`][6] running by following the instructions in this guide.
Before starting, see [setup dev environment](setup-environment.md).
Building on different Operating Systems
--
We try to keep the code as OS independent and standard compliant as possible. Reading files from the file-system has some OS depending code, but will ultimately fall back to a posix compatible implementation. We do use some `C++11` features, but are so far only committed to use `unordered_map`. This means you will need a pretty recent compiler on most systems (gcc 4.5 seems to be the minimum).
### Building on Linux (and other *nix flavors)
Linux is the main target for `libsass` and we support two ways to build `libsass` here. The old plain makefiles should still work on most systems (including MinGW), while the autotools build is preferred if you want to create a [system library] (experimental).
- [Building with makefiles][1]
- [Building with autotools][2]
### Building on Windows (experimental)
Windows build support was added very recently and should be considered experimental. Credits go to @darrenkopp and @am11 for their work on getting `libsass` and `sassc` to compile with visual studio!
- [Building with MinGW][3]
- [Building with Visual Studio][11]
### Building on Max OS X (untested)
Works the same as on linux, but you can also install LibSass via `homebrew`.
- [Building on Mac OS X][10]
### Building a system library (experimental)
Since `libsass` is a library, it makes sense to install it as a shared library on your system. On linux this means creating a `.so` library via autotools. This should work pretty well already, but we are not yet committed to keep the ABI 100% stable. This should be the case once we increase the version number for the library to 1.0.0 or higher. On Windows you should be able get a `dll` by creating a shared build with MinGW. There is currently no target in the MSVC project files to do this.
- [Building shared system library][4]
Compiling with clang instead of gcc
--
To use clang you just need to set the appropriate environment variables:
```bash
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
```
Running the spec test-suite
--
We constantly and automatically test `libsass` against the official [spec test-suite][5]. To do this we need to have a test-runner (which is written in ruby) and a command-line tool ([`sassc`][6]) to run the tests. Therefore we need to additionally compile `sassc`. To do this, the build files of all three projects need to work together. This may not have the same quality for all build flavors. You definitely need to have ruby (2.1?) installed (version 1.9 seems to cause problems at least on windows). You also need some gems installed:
```bash
ruby -v
gem install minitest
# should be optional
gem install minitap
```
Including the LibSass version
--
There is a function in `libsass` to query the current version. This has to be defined at compile time. We use a C macro for this, which can be defined by calling `g++ -DLIBSASS_VERSION="\"x.y.z.\""`. The two quotes are necessary, since it needs to end up as a valid C string. Normally you do not need to do anything if you use the makefiles or autotools. They will try to fetch the version via git directly. If you only have the sources without the git repo, you can pass the version as an environment variable to `make` or `configure`:
```
export LIBSASS_VERSION="x.y.z."
```
Continuous Integration
--
We use two CI services to automatically test all commits against the latest [spec test-suite][5].
- [LibSass on Travis-CI (linux)][7]
[](https://travis-ci.org/sass/libsass)
- [LibSass on AppVeyor (windows)][8]
[](https://ci.appveyor.com/project/mgreter/libsass-513/branch/master)
Why not using CMake?
--
There were some efforts to get `libsass` to compile with CMake, which should make it easier to create build files for linux and windows. Unfortunately this was not completed. But we are certainly open for PRs!
Miscellaneous
--
- [Ebuilds for Gentoo Linux](build-on-gentoo.md)
[1]: build-with-makefiles.md
[2]: build-with-autotools.md
[3]: build-with-mingw.md
[4]: build-shared-library.md
[5]: https://github.com/sass/sass-spec
[6]: https://github.com/sass/sassc
[7]: https://github.com/sass/libsass/blob/master/.travis.yml
[8]: https://github.com/sass/libsass/blob/master/appveyor.yml
[9]: implementations.md
[10]: build-on-darwin.md
[11]: build-with-visual-studio.md
libsass-3.6.3/docs/compatibility-plan.md 0000664 0000000 0000000 00000005522 13557420656 0020257 0 ustar 00root root 0000000 0000000 This document is to serve as a living, changing plan for getting LibSass caught up with Ruby Sass.
_Note: an "s" preceding a version number is specifying a Ruby Sass version. Without an s, it's a version of LibSass._
# Goal
**Our goal is to reach full s3.4 compatibility as soon as possible. LibSass version 3.4 will behave just like Ruby Sass 3.4**
I highlight the goal, because there are some things that are *not* currently priorities. To be clear, they WILL be priorities, but they are not at the moment:
* Performance Improvements
* Extensibility
The overriding goal is correctness.
## Verifying Correctness
LibSass uses the spec for its testing. The spec was originally based off s3.2 tests. Many things have changed in Ruby Sass since then and some of the tests need to be updated and changed in order to get them to match both LibSass and Ruby Sass.
Until this project is complete, the spec will be primarily a place to test LibSass. By the time LibSass reaches 3.4, it is our goal that sass-spec will be fully usable as an official testing source for ALL implementations of Sass.
## Version Naming
Until LibSass reaches parity with Ruby Sass, we will be aggressively bumping versions, and LibSass 3.4 will be the peer to Ruby Sass 3.4 in every way.
# Release Plan
## 3.0
The goal of 3.0 is to introduce some of the most demanded features for LibSass. That is, we are focusing on issues and features that have kept adoption down. This is a mongrel release wrt which version of Sass it's targeting. It's often a mixture of 3.2 / 3.3 / 3.4 behaviours. This is not ideal, but it's favourable to not existing. Targeting 3.4 strictly during this release would mean we never actually release.
# 3.1
The goal of 3.1 is to update all the passing specs to agree with 3.4. This will not be a complete representation of s3.4 (aka, there will me missing features), but the goal is to change existing features and implemented features to match 3.4 behaviour.
By the end of this, the sass-spec must pass against 3.4.
Major issues:
* Variable Scoping
* Color Handling
* Precision
# 3.2
This version will focus on edge case fixes. There are a LOT of edge cases in the _todo_ tests and this is the release where we hunt those down like dogs (not that we want to hurt dogs, it's just a figure of speech in English).
# 3.3
Dress rehearsal. When we are 99% sure that we've fixed the main issues keeping us from saying we are compliant in s3.4 behaviour.
# 3.4
Compass Compatibility. We need to be able to work with Compass and all the other libraries out there. At this point, we are calling LibSass "mature"
# Beyond 3.4
Obviously, there is matching Sass 3.5 behaviour. But, beyond that, we'll want to focus on performance, stability, and error handling. These can always be improved upon and are the life's work of an open source project. We'll have to work closely with Sass in the future.
libsass-3.6.3/docs/contributing.md 0000664 0000000 0000000 00000002575 13557420656 0017172 0 ustar 00root root 0000000 0000000 First of all, welcome! Thanks for even reading this page. If you're here, you're probably wondering what you can do to help make the LibSass project even more awesome. And, even having that feeling means you are awesome!
## I'm a programmer
Awesome! We need your help. The best thing to do is go find issues that are tagged with both "bug" and "test written". We do spec driven development here and these issues have a test that's written already in the sass-spec project. Go find the test by going to sass-spec/spec/LibSass-todo-issues/issue_XXX/ where XXX is the issue number. Write the code, and compile, and then issue a pull request referencing the issue. We'll quickly verify it and get it merged in!
To get your dev environment setup, check out our article on [Setup-Dev-Environment](setup-environment.md).
## I'm not a backend programmer
COOL! We also need your help. Doing [Issue-Triage](triage.md) is a big deal and something we need constant help with. That means helping to verify issues, write tests for them, and make sure they are getting fixed. It's being part of the smiling face of the project.
Also, we need help with the Sass-Spec project itself. Just people to organize, refactor, and understand the tests in there.
## I don't know what a computer is?
Hmm.... well, it's the thing you are looking at right now. Ummm... check out training courses! Then, come back and join us!
libsass-3.6.3/docs/custom-functions-internal.md 0000664 0000000 0000000 00000010235 13557420656 0021605 0 ustar 00root root 0000000 0000000 # Developer Documentation
Custom functions are internally represented by `struct Sass_C_Function_Descriptor`.
## Sass_C_Function_Descriptor
```C
struct Sass_C_Function_Descriptor {
const char* signature;
Sass_C_Function function;
void* cookie;
};
```
- `signature`: The function declaration, like `foo($bar, $baz:1)`
- `function`: Reference to the C function callback
- `cookie`: any pointer you want to attach
### signature
The signature defines how the function can be invoked. It also declares which arguments are required and which are optional. Required arguments will be enforced by LibSass and a Sass error is thrown in the event a call as missing an argument. Optional arguments only need to be present when you want to overwrite the default value.
foo($bar, $baz: 2)
In this example, `$bar` is required and will error if not passed. `$baz` is optional and the default value of it is 2. A call like `foo(10)` is therefore equal to `foo(10, 2)`, while `foo()` will produce an error.
### function
The callback function needs to be of the following form:
```C
union Sass_Value* call_sass_function(
const union Sass_Value* s_args,
void* cookie
) {
return sass_clone_value(s_args);
}
```
### cookie
The cookie can hold any pointer you want. In the `perl-libsass` implementation it holds the structure with the reference of the actual registered callback into the perl interpreter. Before that call `perl-libsass` will convert all `Sass_Values` to corresponding perl data types (so they can be used natively inside the perl interpreter). The callback can also return a `Sass_Value`. In `perl-libsass` the actual function returns a perl value, which has to be converted before `libsass` can work with it again!
## Sass_Values
```C
// allocate memory (copies passed strings)
union Sass_Value* sass_make_null (void);
union Sass_Value* sass_make_boolean (bool val);
union Sass_Value* sass_make_string (const char* val);
union Sass_Value* sass_make_qstring (const char* val);
union Sass_Value* sass_make_number (double val, const char* unit);
union Sass_Value* sass_make_color (double r, double g, double b, double a);
union Sass_Value* sass_make_list (size_t len, enum Sass_Separator sep, bool is_bracketed);
union Sass_Value* sass_make_map (size_t len);
union Sass_Value* sass_make_error (const char* msg);
union Sass_Value* sass_make_warning (const char* msg);
// Make a deep cloned copy of the given sass value
union Sass_Value* sass_clone_value (const union Sass_Value* val);
// deallocate memory (incl. all copied memory)
void sass_delete_value (const union Sass_Value* val);
```
## Example main.c
```C
#include
#include
#include "sass/context.h"
union Sass_Value* call_fn_foo(const union Sass_Value* s_args, void* cookie)
{
// we actually abuse the void* to store an "int"
return sass_make_number((size_t)cookie, "px");
}
int main( int argc, const char* argv[] )
{
// get the input file from first argument or use default
const char* input = argc > 1 ? argv[1] : "styles.scss";
// create the file context and get all related structs
struct Sass_File_Context* file_ctx = sass_make_file_context(input);
struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
// allocate a custom function caller
Sass_C_Function_Callback fn_foo =
sass_make_function("foo()", call_fn_foo, (void*)42);
// create list of all custom functions
Sass_C_Function_List fn_list = sass_make_function_list(1);
sass_function_set_list_entry(fn_list, 0, fn_foo);
sass_option_set_c_functions(ctx_opt, fn_list);
// context is set up, call the compile step now
int status = sass_compile_file_context(file_ctx);
// print the result or the error to the stdout
if (status == 0) puts(sass_context_get_output_string(ctx));
else puts(sass_context_get_error_message(ctx));
// release allocated memory
sass_delete_file_context(file_ctx);
// exit status
return status;
}
```
## Compile main.c
```bash
gcc -c main.c -o main.o
gcc -o sample main.o -lsass
echo "foo { margin: foo(); }" > foo.scss
./sample foo.scss => "foo { margin: 42px }"
```
libsass-3.6.3/docs/dev-ast-memory.md 0000664 0000000 0000000 00000017116 13557420656 0017331 0 ustar 00root root 0000000 0000000 # LibSass smart pointer implementation
LibSass uses smart pointers very similar to `shared_ptr` known
by Boost or C++11. Implementation is a bit less modular since
it was not needed. Various compile time debug options are
available if you need to debug memory life-cycles.
## Memory Classes
### SharedObj
Base class for the actual node implementations. This ensures
that every object has a reference counter and other values.
```c++
class AST_Node : public SharedObj { ... };
```
### SharedPtr (base class for SharedImpl)
Base class that holds on to the pointer. The reference counter
is stored inside the pointer object directly (`SharedObj`).
### SharedImpl (inherits from SharedPtr)
This is the main base class for objects you use in your code. It
will make sure that the memory it points at will be deleted once
all copies to the same object/memory go out of scope.
```c++
Class* pointer = new Class(...);
SharedImpl obj(pointer);
```
To spare the developer of typing the templated class every time,
we created typedefs for each available AST Node specialization.
```c++
typedef SharedImpl Number_Obj;
Number_Obj number = SASS_MEMORY_NEW(...);
```
## Memory life-cycles
### Pointer pickups
I often use the terminology of "pickup". This means the moment when
a raw pointer not under any control is assigned to a reference counted
object (`XYZ_Obj = XYZ_Ptr`). From that point on memory will be
automatically released once the object goes out of scope (but only
if the reference counter reaches zero). Main point being, you don't
have to worry about memory management yourself.
### Object detach
Sometimes we can't return reference counted objects directly (see
invalid covariant return types problems below). But we often still
need to use reference objects inside a function to avoid leaks when
something throws. For this you can use `detach`, which basically
detaches the pointer memory from the reference counted object. So
when the reference counted object goes out of scope, it will not
free the attached memory. You are now again in charge of freeing
the memory (just assign it to a reference counted object again).
## Circular references
Reference counted memory implementations are prone to circular references.
This can be addressed by using a multi generation garbage collector. But
for our use-case that seems overkill. There is no way so far for users
(sass code) to create circular references. Therefore we can code around
this possible issue. But developers should be aware of this limitation.
There are AFAIR two places where circular references could happen. One is
the `sources` member on every `Selector`. The other one can happen in the
extend code (Node handling). The easy way to avoid this is to only assign
complete object clones to these members. If you know the objects lifetime
is longer than the reference you create, you can also just store the raw
pointer. Once needed this could be solved with weak pointers.
## Addressing the invalid covariant return types problems
If you are not familiar with the mentioned problem, you may want
to read up on covariant return types and virtual functions, i.e.
- http://stackoverflow.com/questions/6924754/return-type-covariance-with-smart-pointers
- http://stackoverflow.com/questions/196733/how-can-i-use-covariant-return-types-with-smart-pointers
- http://stackoverflow.com/questions/2687790/how-to-accomplish-covariant-return-types-when-returning-a-shared-ptr
We hit this issue at least with the CRTP visitor pattern (eval, expand,
listize and so forth). This means we cannot return reference counted
objects directly. We are forced to return raw pointers or we would need
to have a lot of explicit and expensive upcasts by callers/consumers.
### Simple functions that allocate new AST Nodes
In the parser step we often create new objects and can just return a
unique pointer (meaning ownership clearly shifts back to the caller).
The caller/consumer is responsible that the memory is freed.
```c++
typedef Number* Number_Ptr;
int parse_integer() {
... // do the parsing
return 42;
}
Number_Ptr parse_number() {
Number_Ptr p_nr = SASS_MEMORY_NEW(...);
p_nr->value(parse_integer());
return p_nr;
}
Number_Obj nr = parse_number();
```
The above would be the encouraged pattern for such simple cases.
### Allocate new AST Nodes in functions that can throw
There is a major caveat with the previous example, considering this
more real-life implementation that throws an error. The throw may
happen deep down in another function. Holding raw pointers that
we need to free would leak in this case.
```c++
int parse_integer() {
... // do the parsing
if (error) throw(error);
return 42;
}
```
With this `parse_integer` function the previous example would leak memory.
I guess it is pretty obvious, as the allocated memory will not be freed,
as it was never assigned to a SharedObj value. Therefore the above code
would better be written as:
```c++
typedef Number* Number_Ptr;
int parse_integer() {
... // do the parsing
if (error) throw(error);
return 42;
}
// this leaks due to pointer return
// should return Number_Obj instead
// though not possible for virtuals!
Number_Ptr parse_number() {
Number_Obj nr = SASS_MEMORY_NEW(...);
nr->value(parse_integer()); // throws
return &nr; // Ptr from Obj
}
Number_Obj nr = parse_number();
// will now be freed automatically
```
The example above unfortunately will not work as is, since we return a
`Number_Ptr` from that function. Therefore the object allocated inside
the function is already gone when it is picked up again by the caller.
The easy fix for the given simplified use case would be to change the
return type of `parse_number` to `Number_Obj`. Indeed we do it exactly
this way in the parser. But as stated above, this will not work for
virtual functions due to invalid covariant return types!
### Return managed objects from virtual functions
The easy fix would be to just create a new copy on the heap and return
that. But this seems like a very inelegant solution to this problem. I
mean why can't we just tell the object to treat it like a newly allocated
object? And indeed we can. I've added a `detach` method that will tell
the object to survive deallocation until the next pickup. This means
that it will leak if it is not picked up by consumer.
```c++
typedef Number* Number_Ptr;
int parse_integer() {
... // do the parsing
if (error) throw(error);
return 42;
}
Number_Ptr parse_number() {
Number_Obj nr = SASS_MEMORY_NEW(...);
nr->value(parse_integer()); // throws
return nr.detach();
}
Number_Obj nr = parse_number();
// will now be freed automatically
```
## Compile time debug options
To enable memory debugging you need to define `DEBUG_SHARED_PTR`.
This can i.e. be done in `include/sass/base.h`
```c++
define DEBUG_SHARED_PTR
```
This will print lost memory on exit to stderr. You can also use
`setDbg(true)` on sepecific variables to emit reference counter
increase, decrease and other events.
## Why reinvent the wheel when there is `shared_ptr` from C++11
First, implementing a smart pointer class is not really that hard. It
was indeed also a learning experience for myself. But there are more
profound advantages:
- Better GCC 4.4 compatibility (which most code still has OOTB)
- Not thread safe (give us some free performance on some compiler)
- Being able to track memory allocations for debugging purposes
- Adding additional features if needed (as seen in `detach`)
- Optional: optimized weak pointer implementation possible
### Thread Safety
As said above, this is not thread safe currently. But we don't need
this ATM anyway. And I guess we probably never will share AST Nodes
across different threads. libsass-3.6.3/docs/dev-profiling.md 0000664 0000000 0000000 00000003275 13557420656 0017226 0 ustar 00root root 0000000 0000000 # Profiling LibSass
## Linux perf and pprof
On Linux, you can record the profile with `perf` and inspect it with `pprof`.
### Install required tools
Pre-requisites:
1. Linux `perf`, commonly found in the `linux-tools-generic` package.
2. [go], for installing `pprof`.
3. [bazel], for installing `perf_to_profile`.
[go]: https://golang.org
[bazel]: https://bazel.build
First, install `pprof` with:
```bash
go get -u github.com/google/pprof
```
Then, build and install `perf_to_profile`:
```bash
git clone https://github.com/google/perf_data_converter
cd perf_data_converter
bazel build -c opt src:perf_to_profile
sudo cp bazel-bin/src/perf_to_profile /usr/local/bin/
```
Finally, in your libsass repository, clone and build `sassc`:
```bash
git clone https://github.com/sass/sassc.git
make sassc
```
### Record perf data
```bash
sudo perf record sassc/bin/sassc input.scss > /dev/null && sudo chown $USER:$USER perf.data
```
This will create a `perf.data` file that you can vizualize with `pprof`.
### Inspect perf data
A web server with various visualization options:
```bash
pprof -http=localhost:3232 sassc/bin/sassc perf.data
```
Simple text output:
```bash
pprof -text sassc/bin/sassc perf.data
```
Example output:
```
flat flat% sum% cum cum%
24651348 6.97% 6.97% 24651348 6.97% [[kernel.kallsyms]]
20746241 5.87% 12.84% 20746241 5.87% Sass::SharedPtr::decRefCount
18401663 5.20% 18.04% 20420896 5.78% __libc_malloc
15205959 4.30% 22.34% 15205959 4.30% [libc-2.27.so]
12974307 3.67% 26.01% 14070189 3.98% _int_malloc
10958857 3.10% 29.11% 10958857 3.10% Sass::SharedPtr::incRefCount
9837672 2.78% 31.89% 18433250 5.21% cfree
```
libsass-3.6.3/docs/implementations.md 0000664 0000000 0000000 00000003753 13557420656 0017672 0 ustar 00root root 0000000 0000000 There are several implementations of `libsass` for a variety of languages. Here are just a few of them. Note, some implementations may or may not be up to date. We have not verified whether they work.
### C
* [sassc](https://github.com/hcatlin/sassc)
### Crystal
* [sass.cr](https://github.com/straight-shoota/sass.cr)
### Elixir
* [sass.ex](https://github.com/scottdavis/sass.ex)
### Go
* [go-libsass](https://github.com/wellington/go-libsass)
* [go_sass](https://github.com/suapapa/go_sass)
* [go-sass](https://github.com/SamWhited/go-sass)
### Haskell
* [hLibsass](https://github.com/jakubfijalkowski/hlibsass)
* [hSass](https://github.com/jakubfijalkowski/hsass)
### Java
* [libsass-maven-plugin](https://github.com/warmuuh/libsass-maven-plugin)
* [jsass](https://github.com/bit3/jsass)
### JavaScript
* [sass.js](https://github.com/medialize/sass.js)
### Lua
* [lua-sass](https://github.com/craigbarnes/lua-sass)
### .NET
* [libsass-net](https://github.com/darrenkopp/libsass-net)
* [NSass](https://github.com/TBAPI-0KA/NSass)
* [Sass.Net](https://github.com/andyalm/Sass.Net)
* [SharpScss](https://github.com/xoofx/SharpScss)
* [LibSassHost](https://github.com/Taritsyn/LibSassHost)
### Nim
* [sass](https://github.com/dom96/sass)
* [nim-sass](https://github.com/zacharycarter/nim-sass)
### node.js
* [node-sass](https://github.com/sass/node-sass)
### Perl
* [CSS::Sass](https://github.com/caldwell/CSS-Sass)
* [Text::Sass::XS](https://github.com/ysasaki/Text-Sass-XS)
### PHP
* [sassphp](https://github.com/sensational/sassphp)
* [php-sass](https://github.com/lesstif/php-sass)
### Python
* [libsass-python](https://github.com/dahlia/libsass-python)
* [SassPython](https://github.com/marianoguerra/SassPython)
* [pylibsass](https://github.com/rsenk330/pylibsass)
* [python-scss](https://github.com/pistolero/python-scss)
### Ruby
* [sassruby](https://github.com/hcatlin/sassruby)
### Scala
* [Sass-Scala](https://github.com/kkung/Sass-Scala)
### Tcl
* [tclsass](https://github.com/flightaware/tclsass)
libsass-3.6.3/docs/plugins.md 0000664 0000000 0000000 00000003573 13557420656 0016143 0 ustar 00root root 0000000 0000000 Plugins are shared object files (.so on *nix and .dll on win) that can be loaded by LibSass on runtime. Currently we only provide a way to load internal/custom functions from plugins. In the future we probably will also add a way to provide custom importers via plugins (needs more refactoring to [support multiple importers with some kind of priority system](https://github.com/sass/libsass/issues/962)).
## plugin.cpp
```C++
#include
#include
#include
#include "sass_values.h"
union Sass_Value* ADDCALL call_fn_foo(const union Sass_Value* s_args, void* cookie)
{
// we actually abuse the void* to store an "int"
return sass_make_number((intptr_t)cookie, "px");
}
extern "C" const char* ADDCALL libsass_get_version() {
return libsass_version();
}
extern "C" Sass_C_Function_List ADDCALL libsass_load_functions()
{
// allocate a custom function caller
Sass_C_Function_Callback fn_foo =
sass_make_function("foo()", call_fn_foo, (void*)42);
// create list of all custom functions
Sass_C_Function_List fn_list = sass_make_function_list(1);
// put the only function in this plugin to the list
sass_function_set_list_entry(fn_list, 0, fn_foo);
// return the list
return fn_list;
}
```
To compile the plugin you need to have LibSass already built as a shared library (to link against it). The commands below expect the shared library in the `lib` sub-directory (`-Llib`). The plugin and the main LibSass process should "consume" the same shared LibSass library on runtime. It will propably also work if they use different LibSass versions. In this case we check if the major versions are compatible (i.e. 3.1.3 and 3.1.1 would be considered compatible).
## Compile with gcc on linux
```bash
g++ -O2 -shared plugin.cpp -o plugin.so -fPIC -Llib -lsass
```
## Compile with mingw on windows
```bash
g++ -O2 -shared plugin.cpp -o plugin.dll -Llib -lsass
```
libsass-3.6.3/docs/setup-environment.md 0000664 0000000 0000000 00000004753 13557420656 0020165 0 ustar 00root root 0000000 0000000 ## Requirements
In order to install and setup your local development environment, there are some prerequisites:
* git
* gcc/clang/llvm (Linux: build tools, Mac OS X: XCode w/ Command Line Tools)
* ruby w/ bundler
OS X:
First you'll need to install XCode which you can now get from the AppStore installed on your mac. After you download that and run it, then run this on the command line:
````
xcode-select --install
````
## Cloning the Projects
First, clone the project and then add a line to your `~/.bash_profile` that will let other programs know where the LibSass dev files are.
````
git clone git@github.com:sass/libsass.git
cd libsass
echo "export SASS_LIBSASS_PATH=$(pwd)" >> ~/.bash_profile
````
Then, if you run the "bootstrap" script, it should clone all the other required projects.
````
./script/bootstrap
````
You should now have a `sass-spec` and `sassc` folder within the libsass folder. Both of these are clones of their respective git projects. If you want to do a pull request, remember to work in those folders. For instance, if you want to add a test (see other documentation for how to do that), make sure to commit it to your *fork* of the sass-spec github project. Also, whenever you are running tests, make sure to `pull` from the origin! We want to make sure we are testing against the newest libsass, sassc, and sass-spec!
Now, try and see if you can build the project. We do that with the `make` command.
````
make
````
At this point, if you get an error, something is most likely wrong with your compiler installation. Yikes. It's hard to cover how to fix this in an article. Feel free to open an issue and we'll try and help! But, remember, before you do that, googling the error message is your friend! Many problems are solved quickly that way.
## Running The Spec Against LibSass
Then, to run the spec against LibSass, just run:
````
./script/spec
````
If you get an error about `SASS_LIBSASS_PATH`, you may still need to set a variable pointing to the libsass folder, like this:
````
export SASS_LIBSASS_PATH=/Users/you/path/libsass
````
...where the latter part is to the `libsass` directory you've cloned. You can get this path by typing `pwd` in the Terminal
## Running the Spec Against Ruby Sass
Go into the sass-spec folder that should have been cloned earlier with the "bootstrap" command. Run the following.
````
bundle install
./sass-spec.rb
````
Voila! Now you are testing against Sass too!
## Profiling
Is libsass being slow? See the [Profiling guide](dev-profiling.md).
libsass-3.6.3/docs/source-map-internals.md 0000664 0000000 0000000 00000004426 13557420656 0020530 0 ustar 00root root 0000000 0000000 This document is mainly intended for developers!
# Documenting some of the source map internals
Since source maps are somewhat a black box to all LibSass maintainers, [I](@mgreter) will try to document my findings with source maps in LibSass, as I come across them. This document will also brievely explain how LibSass parses the source and how it outputs the result.
The main storage for SourceMap mappings is the `mappings` vector:
```
# in source_map.hpp
vector mappings
# in mappings.hpp
struct Mapping ...
Position original_position;
Position generated_position;
```
## Every parsed token has its source associated
LibSass uses a lexical parser. Whenever LibSass finds a token of interest, it creates a specific `AST_Node`, which will hold a reference to the input source with line/column information. `AST_Node` is the base class for all parsed items. They are declared in `ast.hpp` and are used in `parser.hpp`. Here a simple example:
```
if (lex< custom_property_name >()) {
Sass::String* prop = new (ctx.mem) String_Constant(path, source_position, lexed);
return new (ctx.mem) Declaration(path, prop->position(), prop, ...);
}
```
## How is the `source_position` calculated
This is automatically done with `lex` in `parser.hpp`. Whenever something is lexed, the `source_position` is updated. But be aware that `source_position` points to the beginning of the parsed text. If you need a mapping for the position where the parsing ended, you need to add another call to `lex` (to match nothing)!
```
lex< exactly < empty_str > >();
end = new (ctx.mem) String_Constant(path, source_position, lexed);
```
## How are mappings for the output created
So far we have collected all needed data for all tokens in the input stream. We can now use this information to create mappings when we put things into the output stream. Mappings are created via the `add_mappings` method:
```
# in source_map.hpp
void add_mapping(AST_Node* node);
```
This method is called in two places:
- `Inspect::append_to_buffer`
- `Output_[Nested|Compressed]::append_to_buffer`
Mappings can only be created for things that have been parsed into a `AST_Node`. Otherwise we do not have the information to create the mappings, which is the reason why LibSass currently only maps the most important tokens in source maps.
libsass-3.6.3/docs/trace.md 0000664 0000000 0000000 00000001574 13557420656 0015557 0 ustar 00root root 0000000 0000000 ## This is proposed interface in https://github.com/sass/libsass/pull/1288
Additional debugging macros with low overhead are available, `TRACE()` and `TRACEINST()`.
Both macros simulate a string stream, so they can be used like this:
TRACE() << "Reached.";
produces:
[LibSass] parse_value parser.cpp:1384 Reached.
`TRACE()`
logs function name, source filename, source file name to the standard error and the attached
stream to the standard error.
`TRACEINST(obj)`
logs object instance address, function name, source filename, source file name to the standard error and the attached stream to the standard error, for example:
TRACEINST(this) << "String_Constant created " << this;
produces:
[LibSass] 0x8031ba980:String_Constant ./ast.hpp:1371 String_Constant created (0,"auto")
The macros generate output only of `LibSass_TRACE` is set in the environment.
libsass-3.6.3/docs/triage.md 0000664 0000000 0000000 00000003355 13557420656 0015733 0 ustar 00root root 0000000 0000000 This is an article about how to help with LibSass issues. Issue triage is a fancy word for explaining how we deal with incoming issues and make sure that the right problems get worked on. The lifecycle of an issue goes like this:
1. Issue is reported by a user.
2. If the issue seems like a bug, then the "bug" tag is added.
3. If the reporting user didn't also create a spec test over at sass/sass-spec, the "needs test" tag is added.
4. Verify that Ruby Sass *does not* have the same bug. LibSass strives to be an exact replica of how Ruby Sass works. If it's an issue that neither project has solved, please close the ticket with the "not in sass" label.
5. The smallest possible breaking test is created in sass-spec. Cut away any extra information or non-breaking code until the core issue is made clear.
6. Again, verify that the expected output matches the latest Ruby Sass release. Do this by using your own tool OR by running ./sass-spec.rb in the spec folder and making sure that your test passes!
7. Create the test cases in sass-spec with the name spec/LibSass-todo-issues/issue_XXX/input.scss and expected_output.css where the XXX is the issue number here.
8. Commit that test to sass-spec, making sure to reference the issue in the comment message like "Test to demonstrate sass/LibSass#XXX".
9. Once the spec test exists, remove the "needs test" tag and replace it with "test written".
10. A C++ developer will then work on the issue and issue a pull request to fix the issue.
11. A core member verifies that the fix does actually fix the spec tests.
12. The fix is merged into the project.
13. The spec is moved from the LibSass-todo-issues folder into LibSass-closed-issues
14. The issue is closed
15. Have a soda pop or enjoyable beverage of your choice
libsass-3.6.3/docs/unicode.md 0000664 0000000 0000000 00000011653 13557420656 0016106 0 ustar 00root root 0000000 0000000 LibSass currently expects all input to be utf8 encoded (and outputs only utf8), if you actually have any unicode characters at all. We do not support conversion between encodings, even if you declare it with a `@charset` rule. The text below was originally posted as an [issue](https://github.com/sass/libsass/issues/381) on the LibSass tracker. Since then the status is outdated as LibSass now expects your
input to be utf8/ascii compatible, as it has been proven that reading ANSI (e.g. single byte encodings) as utf8 can lead to unexpected
behavior, which can in the worst case lead to buffer overruns/segfaults. Therefore LibSass now checks your input to be valid utf8 encoded!
### [Declaring character encodings in CSS](http://www.w3.org/International/questions/qa-css-charset.en)
This [explains](http://www.w3.org/International/questions/qa-css-charset.en) how the character encoding of a css file is determined. Since we are only dealing with local files, we never have a HTTP header. So the precedence should be 'charset' rule, byte-order mark (BOM) or auto-detection (finally falling back to system default/UTF-8). This may not sound too hard to implement, but what about import rules? The CSS specs do not forbid the mixing of different encodings! I [solved that](https://github.com/mgreter/webmerge/) by converting all files to UTF-8 internally. On writing there is an option to tell the tool what encoding it should be (UTF-8 by default). One can also define if it should write a BOM or not and if it should add the charset declaration.
Since my [tool]((https://github.com/mgreter/webmerge/)) is written in perl, I have a lot of utilities at hand to deal with different unicode charsets. I'm pretty sure that most OSS uses [ICU](http://site.icu-project.org/) or [libiconv](https://www.gnu.org/software/libiconv/) to convert between different encodings. But I have now idea how easy/hard this would be to integrate platform independent (it seems doable). ANSII (single byte encoding) to utf8 is basically just a conversion table (for every supported code-page).
### Current status on LibSass unicode support
LibSass should/is fully UTF (and therefore plain ASCII) compatible.
~~Currently LibSass seems to handle the common UTF-8 case pretty well. I believe it should correctly support all ASCII compatible encodings (like UTF-8 or Latin-1). If all includes use the same encoding, the output should be correct (in the same encoding). It should also handle unicode chars in [selectors, variable names and other identifiers](https://github.com/hcatlin/libsass/issues/244#issuecomment-34681227). This is true for all ASCII compatible encodings. So the main incompatible encodings (I'm aware of) are UTF-16/UTF-32 (which could be converted to UTF-8 with libiconv).~~
LibSass 3.5 will enforce that your input is either plain ASCII (chars below 127) or utf8. It does not handle anything else, but therefore ensures that the output is in a valid form. Before version 3.5 you were able to mix different code-pages, which yielded unexpected behavior.
### Current encoding auto detection
LibSass currently reads all kind of BOMs and will error out if it finds something it doesn't know how to handle! It seems that it throws away the optional UTF-8 BOM (if any is found). IMO it would be nice if users could configure that (also if a charset rule should be added to the output). But it does not really take any `@charset` into account, it always assumes your input is utf8 and ignores any given `@charset`!
### What is currently not supported
- Using non ASCII compatible encodings (like UTF-16, Latin-1 etc.)
- Using non ASCII characters in different encodings in different includes
### What is missing to support the above cases
- A way to convert between encodings (like libiconv/ICU)
- Sniffing the charset inside the file (source is available)
- Handling the conversion on import (and export)
- Optional: Make output encoding configurable
- Optional: Add optional/mandatory BOM (configurable)
### Low priority feature
I guess the current implementation should handle more than 99% of all real world use cases.
A) Unicode characters are still seldom seen (as they can be written escaped)
~~B) It will still work if it's UTF-8 or in any of the most common known western ISO codepages.
Although I'm not sure how this applies to asian and other "exotic" codepages!~~
I guess the biggest Problem is to have libiconv/ICU (or some other) library as a dependency. Since it contains a lot of rules for the conversions, I see it as the only way to handle this correctly. Once that is sorted out it should be pretty much straight forward to implement the missing pieces (in parser.cpp - Parser::parse should return encoding and add Parser::sniff_charset, then convert the source byte stream to UTF-8).
I hope the statements above all hold true. Unicode is really not the easiest topic to wrap your head around. But since I did all the above recently in Perl, I wanted to document it here. Feel free to extend or criticize.
libsass-3.6.3/include/ 0000775 0000000 0000000 00000000000 13557420656 0014623 5 ustar 00root root 0000000 0000000 libsass-3.6.3/include/sass.h 0000664 0000000 0000000 00000000352 13557420656 0015745 0 ustar 00root root 0000000 0000000 #ifndef SASS_H
#define SASS_H
// #define DEBUG 1
// include API headers
#include
#include
#include
#include
#include
#include
#endif
libsass-3.6.3/include/sass/ 0000775 0000000 0000000 00000000000 13557420656 0015574 5 ustar 00root root 0000000 0000000 libsass-3.6.3/include/sass/base.h 0000664 0000000 0000000 00000004501 13557420656 0016657 0 ustar 00root root 0000000 0000000 #ifndef SASS_BASE_H
#define SASS_BASE_H
// #define DEBUG
// #define DEBUG_SHARED_PTR
#ifdef _MSC_VER
#pragma warning(disable : 4503)
#ifndef _SCL_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef _CRT_NONSTDC_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#endif
#endif
// Work around lack of `noexcept` keyword support in VS2013
#if defined(_MSC_VER) && (_MSC_VER <= 1800) && !defined(_ALLOW_KEYWORD_MACROS)
#define _ALLOW_KEYWORD_MACROS 1
#define noexcept throw( )
#endif
#include
#include
#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__ ((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED(func) func
#endif
#ifdef _WIN32
/* You should define ADD_EXPORTS *only* when building the DLL. */
#ifdef ADD_EXPORTS
#define ADDAPI __declspec(dllexport)
#define ADDCALL __cdecl
#else
#define ADDAPI
#define ADDCALL
#endif
#else /* _WIN32 not defined. */
/* Define with no value on non-Windows OSes. */
#define ADDAPI
#define ADDCALL
#endif
/* Make sure functions are exported with C linkage under C++ compilers. */
#ifdef __cplusplus
extern "C" {
#endif
// Different render styles
enum Sass_Output_Style {
SASS_STYLE_NESTED,
SASS_STYLE_EXPANDED,
SASS_STYLE_COMPACT,
SASS_STYLE_COMPRESSED,
// only used internaly
SASS_STYLE_INSPECT,
SASS_STYLE_TO_SASS,
SASS_STYLE_TO_CSS
};
// to allocate buffer to be filled
ADDAPI void* ADDCALL sass_alloc_memory(size_t size);
// to allocate a buffer from existing string
ADDAPI char* ADDCALL sass_copy_c_string(const char* str);
// to free overtaken memory when done
ADDAPI void ADDCALL sass_free_memory(void* ptr);
// Some convenient string helper function
ADDAPI char* ADDCALL sass_string_quote (const char* str, const char quote_mark);
ADDAPI char* ADDCALL sass_string_unquote (const char* str);
// Implemented sass language version
// Hardcoded version 3.4 for time being
ADDAPI const char* ADDCALL libsass_version(void);
// Get compiled libsass language
ADDAPI const char* ADDCALL libsass_language_version(void);
#ifdef __cplusplus
} // __cplusplus defined.
#endif
#endif
libsass-3.6.3/include/sass/context.h 0000664 0000000 0000000 00000024410 13557420656 0017432 0 ustar 00root root 0000000 0000000 #ifndef SASS_C_CONTEXT_H
#define SASS_C_CONTEXT_H
#include
#include
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
// Forward declaration
struct Sass_Compiler;
// Forward declaration
struct Sass_Options; // base struct
struct Sass_Context; // : Sass_Options
struct Sass_File_Context; // : Sass_Context
struct Sass_Data_Context; // : Sass_Context
// Compiler states
enum Sass_Compiler_State {
SASS_COMPILER_CREATED,
SASS_COMPILER_PARSED,
SASS_COMPILER_EXECUTED
};
// Create and initialize an option struct
ADDAPI struct Sass_Options* ADDCALL sass_make_options (void);
// Create and initialize a specific context
ADDAPI struct Sass_File_Context* ADDCALL sass_make_file_context (const char* input_path);
ADDAPI struct Sass_Data_Context* ADDCALL sass_make_data_context (char* source_string);
// Call the compilation step for the specific context
ADDAPI int ADDCALL sass_compile_file_context (struct Sass_File_Context* ctx);
ADDAPI int ADDCALL sass_compile_data_context (struct Sass_Data_Context* ctx);
// Create a sass compiler instance for more control
ADDAPI struct Sass_Compiler* ADDCALL sass_make_file_compiler (struct Sass_File_Context* file_ctx);
ADDAPI struct Sass_Compiler* ADDCALL sass_make_data_compiler (struct Sass_Data_Context* data_ctx);
// Execute the different compilation steps individually
// Useful if you only want to query the included files
ADDAPI int ADDCALL sass_compiler_parse(struct Sass_Compiler* compiler);
ADDAPI int ADDCALL sass_compiler_execute(struct Sass_Compiler* compiler);
// Release all memory allocated with the compiler
// This does _not_ include any contexts or options
ADDAPI void ADDCALL sass_delete_compiler(struct Sass_Compiler* compiler);
ADDAPI void ADDCALL sass_delete_options(struct Sass_Options* options);
// Release all memory allocated and also ourself
ADDAPI void ADDCALL sass_delete_file_context (struct Sass_File_Context* ctx);
ADDAPI void ADDCALL sass_delete_data_context (struct Sass_Data_Context* ctx);
// Getters for context from specific implementation
ADDAPI struct Sass_Context* ADDCALL sass_file_context_get_context (struct Sass_File_Context* file_ctx);
ADDAPI struct Sass_Context* ADDCALL sass_data_context_get_context (struct Sass_Data_Context* data_ctx);
// Getters for Context_Options from Sass_Context
ADDAPI struct Sass_Options* ADDCALL sass_context_get_options (struct Sass_Context* ctx);
ADDAPI struct Sass_Options* ADDCALL sass_file_context_get_options (struct Sass_File_Context* file_ctx);
ADDAPI struct Sass_Options* ADDCALL sass_data_context_get_options (struct Sass_Data_Context* data_ctx);
ADDAPI void ADDCALL sass_file_context_set_options (struct Sass_File_Context* file_ctx, struct Sass_Options* opt);
ADDAPI void ADDCALL sass_data_context_set_options (struct Sass_Data_Context* data_ctx, struct Sass_Options* opt);
// Getters for Context_Option values
ADDAPI int ADDCALL sass_option_get_precision (struct Sass_Options* options);
ADDAPI enum Sass_Output_Style ADDCALL sass_option_get_output_style (struct Sass_Options* options);
ADDAPI bool ADDCALL sass_option_get_source_comments (struct Sass_Options* options);
ADDAPI bool ADDCALL sass_option_get_source_map_embed (struct Sass_Options* options);
ADDAPI bool ADDCALL sass_option_get_source_map_contents (struct Sass_Options* options);
ADDAPI bool ADDCALL sass_option_get_source_map_file_urls (struct Sass_Options* options);
ADDAPI bool ADDCALL sass_option_get_omit_source_map_url (struct Sass_Options* options);
ADDAPI bool ADDCALL sass_option_get_is_indented_syntax_src (struct Sass_Options* options);
ADDAPI const char* ADDCALL sass_option_get_indent (struct Sass_Options* options);
ADDAPI const char* ADDCALL sass_option_get_linefeed (struct Sass_Options* options);
ADDAPI const char* ADDCALL sass_option_get_input_path (struct Sass_Options* options);
ADDAPI const char* ADDCALL sass_option_get_output_path (struct Sass_Options* options);
ADDAPI const char* ADDCALL sass_option_get_source_map_file (struct Sass_Options* options);
ADDAPI const char* ADDCALL sass_option_get_source_map_root (struct Sass_Options* options);
ADDAPI Sass_Importer_List ADDCALL sass_option_get_c_headers (struct Sass_Options* options);
ADDAPI Sass_Importer_List ADDCALL sass_option_get_c_importers (struct Sass_Options* options);
ADDAPI Sass_Function_List ADDCALL sass_option_get_c_functions (struct Sass_Options* options);
// Setters for Context_Option values
ADDAPI void ADDCALL sass_option_set_precision (struct Sass_Options* options, int precision);
ADDAPI void ADDCALL sass_option_set_output_style (struct Sass_Options* options, enum Sass_Output_Style output_style);
ADDAPI void ADDCALL sass_option_set_source_comments (struct Sass_Options* options, bool source_comments);
ADDAPI void ADDCALL sass_option_set_source_map_embed (struct Sass_Options* options, bool source_map_embed);
ADDAPI void ADDCALL sass_option_set_source_map_contents (struct Sass_Options* options, bool source_map_contents);
ADDAPI void ADDCALL sass_option_set_source_map_file_urls (struct Sass_Options* options, bool source_map_file_urls);
ADDAPI void ADDCALL sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
ADDAPI void ADDCALL sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
ADDAPI void ADDCALL sass_option_set_indent (struct Sass_Options* options, const char* indent);
ADDAPI void ADDCALL sass_option_set_linefeed (struct Sass_Options* options, const char* linefeed);
ADDAPI void ADDCALL sass_option_set_input_path (struct Sass_Options* options, const char* input_path);
ADDAPI void ADDCALL sass_option_set_output_path (struct Sass_Options* options, const char* output_path);
ADDAPI void ADDCALL sass_option_set_plugin_path (struct Sass_Options* options, const char* plugin_path);
ADDAPI void ADDCALL sass_option_set_include_path (struct Sass_Options* options, const char* include_path);
ADDAPI void ADDCALL sass_option_set_source_map_file (struct Sass_Options* options, const char* source_map_file);
ADDAPI void ADDCALL sass_option_set_source_map_root (struct Sass_Options* options, const char* source_map_root);
ADDAPI void ADDCALL sass_option_set_c_headers (struct Sass_Options* options, Sass_Importer_List c_headers);
ADDAPI void ADDCALL sass_option_set_c_importers (struct Sass_Options* options, Sass_Importer_List c_importers);
ADDAPI void ADDCALL sass_option_set_c_functions (struct Sass_Options* options, Sass_Function_List c_functions);
// Getters for Sass_Context values
ADDAPI const char* ADDCALL sass_context_get_output_string (struct Sass_Context* ctx);
ADDAPI int ADDCALL sass_context_get_error_status (struct Sass_Context* ctx);
ADDAPI const char* ADDCALL sass_context_get_error_json (struct Sass_Context* ctx);
ADDAPI const char* ADDCALL sass_context_get_error_text (struct Sass_Context* ctx);
ADDAPI const char* ADDCALL sass_context_get_error_message (struct Sass_Context* ctx);
ADDAPI const char* ADDCALL sass_context_get_error_file (struct Sass_Context* ctx);
ADDAPI const char* ADDCALL sass_context_get_error_src (struct Sass_Context* ctx);
ADDAPI size_t ADDCALL sass_context_get_error_line (struct Sass_Context* ctx);
ADDAPI size_t ADDCALL sass_context_get_error_column (struct Sass_Context* ctx);
ADDAPI const char* ADDCALL sass_context_get_source_map_string (struct Sass_Context* ctx);
ADDAPI char** ADDCALL sass_context_get_included_files (struct Sass_Context* ctx);
// Getters for options include path array
ADDAPI size_t ADDCALL sass_option_get_include_path_size(struct Sass_Options* options);
ADDAPI const char* ADDCALL sass_option_get_include_path(struct Sass_Options* options, size_t i);
// Calculate the size of the stored null terminated array
ADDAPI size_t ADDCALL sass_context_get_included_files_size (struct Sass_Context* ctx);
// Take ownership of memory (value on context is set to 0)
ADDAPI char* ADDCALL sass_context_take_error_json (struct Sass_Context* ctx);
ADDAPI char* ADDCALL sass_context_take_error_text (struct Sass_Context* ctx);
ADDAPI char* ADDCALL sass_context_take_error_message (struct Sass_Context* ctx);
ADDAPI char* ADDCALL sass_context_take_error_file (struct Sass_Context* ctx);
ADDAPI char* ADDCALL sass_context_take_error_src (struct Sass_Context* ctx);
ADDAPI char* ADDCALL sass_context_take_output_string (struct Sass_Context* ctx);
ADDAPI char* ADDCALL sass_context_take_source_map_string (struct Sass_Context* ctx);
ADDAPI char** ADDCALL sass_context_take_included_files (struct Sass_Context* ctx);
// Getters for Sass_Compiler options
ADDAPI enum Sass_Compiler_State ADDCALL sass_compiler_get_state(struct Sass_Compiler* compiler);
ADDAPI struct Sass_Context* ADDCALL sass_compiler_get_context(struct Sass_Compiler* compiler);
ADDAPI struct Sass_Options* ADDCALL sass_compiler_get_options(struct Sass_Compiler* compiler);
ADDAPI size_t ADDCALL sass_compiler_get_import_stack_size(struct Sass_Compiler* compiler);
ADDAPI Sass_Import_Entry ADDCALL sass_compiler_get_last_import(struct Sass_Compiler* compiler);
ADDAPI Sass_Import_Entry ADDCALL sass_compiler_get_import_entry(struct Sass_Compiler* compiler, size_t idx);
ADDAPI size_t ADDCALL sass_compiler_get_callee_stack_size(struct Sass_Compiler* compiler);
ADDAPI Sass_Callee_Entry ADDCALL sass_compiler_get_last_callee(struct Sass_Compiler* compiler);
ADDAPI Sass_Callee_Entry ADDCALL sass_compiler_get_callee_entry(struct Sass_Compiler* compiler, size_t idx);
// Push function for paths (no manipulation support for now)
ADDAPI void ADDCALL sass_option_push_plugin_path (struct Sass_Options* options, const char* path);
ADDAPI void ADDCALL sass_option_push_include_path (struct Sass_Options* options, const char* path);
// Resolve a file via the given include paths in the sass option struct
// find_file looks for the exact file name while find_include does a regular sass include
ADDAPI char* ADDCALL sass_find_file (const char* path, struct Sass_Options* opt);
ADDAPI char* ADDCALL sass_find_include (const char* path, struct Sass_Options* opt);
// Resolve a file relative to last import or include paths in the sass option struct
// find_file looks for the exact file name while find_include does a regular sass include
ADDAPI char* ADDCALL sass_compiler_find_file (const char* path, struct Sass_Compiler* compiler);
ADDAPI char* ADDCALL sass_compiler_find_include (const char* path, struct Sass_Compiler* compiler);
#ifdef __cplusplus
} // __cplusplus defined.
#endif
#endif
libsass-3.6.3/include/sass/functions.h 0000664 0000000 0000000 00000014750 13557420656 0017764 0 ustar 00root root 0000000 0000000 #ifndef SASS_C_FUNCTIONS_H
#define SASS_C_FUNCTIONS_H
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
// Forward declaration
struct Sass_Env;
struct Sass_Callee;
struct Sass_Import;
struct Sass_Options;
struct Sass_Compiler;
struct Sass_Importer;
struct Sass_Function;
// Typedef helpers for callee lists
typedef struct Sass_Env (*Sass_Env_Frame);
// Typedef helpers for callee lists
typedef struct Sass_Callee (*Sass_Callee_Entry);
// Typedef helpers for import lists
typedef struct Sass_Import (*Sass_Import_Entry);
typedef struct Sass_Import* (*Sass_Import_List);
// Typedef helpers for custom importer lists
typedef struct Sass_Importer (*Sass_Importer_Entry);
typedef struct Sass_Importer* (*Sass_Importer_List);
// Typedef defining importer signature and return type
typedef Sass_Import_List (*Sass_Importer_Fn)
(const char* url, Sass_Importer_Entry cb, struct Sass_Compiler* compiler);
// Typedef helpers for custom functions lists
typedef struct Sass_Function (*Sass_Function_Entry);
typedef struct Sass_Function* (*Sass_Function_List);
// Typedef defining function signature and return type
typedef union Sass_Value* (*Sass_Function_Fn)
(const union Sass_Value*, Sass_Function_Entry cb, struct Sass_Compiler* compiler);
// Type of function calls
enum Sass_Callee_Type {
SASS_CALLEE_MIXIN,
SASS_CALLEE_FUNCTION,
SASS_CALLEE_C_FUNCTION,
};
// Creator for sass custom importer return argument list
ADDAPI Sass_Importer_List ADDCALL sass_make_importer_list (size_t length);
ADDAPI Sass_Importer_Entry ADDCALL sass_importer_get_list_entry (Sass_Importer_List list, size_t idx);
ADDAPI void ADDCALL sass_importer_set_list_entry (Sass_Importer_List list, size_t idx, Sass_Importer_Entry entry);
ADDAPI void ADDCALL sass_delete_importer_list (Sass_Importer_List list);
// Creators for custom importer callback (with some additional pointer)
// The pointer is mostly used to store the callback into the actual binding
ADDAPI Sass_Importer_Entry ADDCALL sass_make_importer (Sass_Importer_Fn importer, double priority, void* cookie);
// Getters for import function descriptors
ADDAPI Sass_Importer_Fn ADDCALL sass_importer_get_function (Sass_Importer_Entry cb);
ADDAPI double ADDCALL sass_importer_get_priority (Sass_Importer_Entry cb);
ADDAPI void* ADDCALL sass_importer_get_cookie (Sass_Importer_Entry cb);
// Deallocator for associated memory
ADDAPI void ADDCALL sass_delete_importer (Sass_Importer_Entry cb);
// Creator for sass custom importer return argument list
ADDAPI Sass_Import_List ADDCALL sass_make_import_list (size_t length);
// Creator for a single import entry returned by the custom importer inside the list
ADDAPI Sass_Import_Entry ADDCALL sass_make_import_entry (const char* path, char* source, char* srcmap);
ADDAPI Sass_Import_Entry ADDCALL sass_make_import (const char* imp_path, const char* abs_base, char* source, char* srcmap);
// set error message to abort import and to print out a message (path from existing object is used in output)
ADDAPI Sass_Import_Entry ADDCALL sass_import_set_error(Sass_Import_Entry import, const char* message, size_t line, size_t col);
// Setters to insert an entry into the import list (you may also use [] access directly)
// Since we are dealing with pointers they should have a guaranteed and fixed size
ADDAPI void ADDCALL sass_import_set_list_entry (Sass_Import_List list, size_t idx, Sass_Import_Entry entry);
ADDAPI Sass_Import_Entry ADDCALL sass_import_get_list_entry (Sass_Import_List list, size_t idx);
// Getters for callee entry
ADDAPI const char* ADDCALL sass_callee_get_name (Sass_Callee_Entry);
ADDAPI const char* ADDCALL sass_callee_get_path (Sass_Callee_Entry);
ADDAPI size_t ADDCALL sass_callee_get_line (Sass_Callee_Entry);
ADDAPI size_t ADDCALL sass_callee_get_column (Sass_Callee_Entry);
ADDAPI enum Sass_Callee_Type ADDCALL sass_callee_get_type (Sass_Callee_Entry);
ADDAPI Sass_Env_Frame ADDCALL sass_callee_get_env (Sass_Callee_Entry);
// Getters and Setters for environments (lexical, local and global)
ADDAPI union Sass_Value* ADDCALL sass_env_get_lexical (Sass_Env_Frame, const char*);
ADDAPI void ADDCALL sass_env_set_lexical (Sass_Env_Frame, const char*, union Sass_Value*);
ADDAPI union Sass_Value* ADDCALL sass_env_get_local (Sass_Env_Frame, const char*);
ADDAPI void ADDCALL sass_env_set_local (Sass_Env_Frame, const char*, union Sass_Value*);
ADDAPI union Sass_Value* ADDCALL sass_env_get_global (Sass_Env_Frame, const char*);
ADDAPI void ADDCALL sass_env_set_global (Sass_Env_Frame, const char*, union Sass_Value*);
// Getters for import entry
ADDAPI const char* ADDCALL sass_import_get_imp_path (Sass_Import_Entry);
ADDAPI const char* ADDCALL sass_import_get_abs_path (Sass_Import_Entry);
ADDAPI const char* ADDCALL sass_import_get_source (Sass_Import_Entry);
ADDAPI const char* ADDCALL sass_import_get_srcmap (Sass_Import_Entry);
// Explicit functions to take ownership of these items
// The property on our struct will be reset to NULL
ADDAPI char* ADDCALL sass_import_take_source (Sass_Import_Entry);
ADDAPI char* ADDCALL sass_import_take_srcmap (Sass_Import_Entry);
// Getters from import error entry
ADDAPI size_t ADDCALL sass_import_get_error_line (Sass_Import_Entry);
ADDAPI size_t ADDCALL sass_import_get_error_column (Sass_Import_Entry);
ADDAPI const char* ADDCALL sass_import_get_error_message (Sass_Import_Entry);
// Deallocator for associated memory (incl. entries)
ADDAPI void ADDCALL sass_delete_import_list (Sass_Import_List);
// Just in case we have some stray import structs
ADDAPI void ADDCALL sass_delete_import (Sass_Import_Entry);
// Creators for sass function list and function descriptors
ADDAPI Sass_Function_List ADDCALL sass_make_function_list (size_t length);
ADDAPI Sass_Function_Entry ADDCALL sass_make_function (const char* signature, Sass_Function_Fn cb, void* cookie);
ADDAPI void ADDCALL sass_delete_function (Sass_Function_Entry entry);
ADDAPI void ADDCALL sass_delete_function_list (Sass_Function_List list);
// Setters and getters for callbacks on function lists
ADDAPI Sass_Function_Entry ADDCALL sass_function_get_list_entry(Sass_Function_List list, size_t pos);
ADDAPI void ADDCALL sass_function_set_list_entry(Sass_Function_List list, size_t pos, Sass_Function_Entry cb);
// Getters for custom function descriptors
ADDAPI const char* ADDCALL sass_function_get_signature (Sass_Function_Entry cb);
ADDAPI Sass_Function_Fn ADDCALL sass_function_get_function (Sass_Function_Entry cb);
ADDAPI void* ADDCALL sass_function_get_cookie (Sass_Function_Entry cb);
#ifdef __cplusplus
} // __cplusplus defined.
#endif
#endif
libsass-3.6.3/include/sass/values.h 0000664 0000000 0000000 00000014531 13557420656 0017250 0 ustar 00root root 0000000 0000000 #ifndef SASS_C_VALUES_H
#define SASS_C_VALUES_H
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
// Forward declaration
union Sass_Value;
// Type for Sass values
enum Sass_Tag {
SASS_BOOLEAN,
SASS_NUMBER,
SASS_COLOR,
SASS_STRING,
SASS_LIST,
SASS_MAP,
SASS_NULL,
SASS_ERROR,
SASS_WARNING
};
// Tags for denoting Sass list separators
enum Sass_Separator {
SASS_COMMA,
SASS_SPACE,
// only used internally to represent a hash map before evaluation
// otherwise we would be too early to check for duplicate keys
SASS_HASH
};
// Value Operators
enum Sass_OP {
AND, OR, // logical connectives
EQ, NEQ, GT, GTE, LT, LTE, // arithmetic relations
ADD, SUB, MUL, DIV, MOD, // arithmetic functions
NUM_OPS // so we know how big to make the op table
};
// Creator functions for all value types
ADDAPI union Sass_Value* ADDCALL sass_make_null (void);
ADDAPI union Sass_Value* ADDCALL sass_make_boolean (bool val);
ADDAPI union Sass_Value* ADDCALL sass_make_string (const char* val);
ADDAPI union Sass_Value* ADDCALL sass_make_qstring (const char* val);
ADDAPI union Sass_Value* ADDCALL sass_make_number (double val, const char* unit);
ADDAPI union Sass_Value* ADDCALL sass_make_color (double r, double g, double b, double a);
ADDAPI union Sass_Value* ADDCALL sass_make_list (size_t len, enum Sass_Separator sep, bool is_bracketed);
ADDAPI union Sass_Value* ADDCALL sass_make_map (size_t len);
ADDAPI union Sass_Value* ADDCALL sass_make_error (const char* msg);
ADDAPI union Sass_Value* ADDCALL sass_make_warning (const char* msg);
// Generic destructor function for all types
// Will release memory of all associated Sass_Values
// Means we will delete recursively for lists and maps
ADDAPI void ADDCALL sass_delete_value (union Sass_Value* val);
// Make a deep cloned copy of the given sass value
ADDAPI union Sass_Value* ADDCALL sass_clone_value (const union Sass_Value* val);
// Execute an operation for two Sass_Values and return the result as a Sass_Value too
ADDAPI union Sass_Value* ADDCALL sass_value_op (enum Sass_OP op, const union Sass_Value* a, const union Sass_Value* b);
// Stringify a Sass_Values and also return the result as a Sass_Value (of type STRING)
ADDAPI union Sass_Value* ADDCALL sass_value_stringify (const union Sass_Value* a, bool compressed, int precision);
// Return the sass tag for a generic sass value
// Check is needed before accessing specific values!
ADDAPI enum Sass_Tag ADDCALL sass_value_get_tag (const union Sass_Value* v);
// Check value to be of a specific type
// Can also be used before accessing properties!
ADDAPI bool ADDCALL sass_value_is_null (const union Sass_Value* v);
ADDAPI bool ADDCALL sass_value_is_number (const union Sass_Value* v);
ADDAPI bool ADDCALL sass_value_is_string (const union Sass_Value* v);
ADDAPI bool ADDCALL sass_value_is_boolean (const union Sass_Value* v);
ADDAPI bool ADDCALL sass_value_is_color (const union Sass_Value* v);
ADDAPI bool ADDCALL sass_value_is_list (const union Sass_Value* v);
ADDAPI bool ADDCALL sass_value_is_map (const union Sass_Value* v);
ADDAPI bool ADDCALL sass_value_is_error (const union Sass_Value* v);
ADDAPI bool ADDCALL sass_value_is_warning (const union Sass_Value* v);
// Getters and setters for Sass_Number
ADDAPI double ADDCALL sass_number_get_value (const union Sass_Value* v);
ADDAPI void ADDCALL sass_number_set_value (union Sass_Value* v, double value);
ADDAPI const char* ADDCALL sass_number_get_unit (const union Sass_Value* v);
ADDAPI void ADDCALL sass_number_set_unit (union Sass_Value* v, char* unit);
// Getters and setters for Sass_String
ADDAPI const char* ADDCALL sass_string_get_value (const union Sass_Value* v);
ADDAPI void ADDCALL sass_string_set_value (union Sass_Value* v, char* value);
ADDAPI bool ADDCALL sass_string_is_quoted(const union Sass_Value* v);
ADDAPI void ADDCALL sass_string_set_quoted(union Sass_Value* v, bool quoted);
// Getters and setters for Sass_Boolean
ADDAPI bool ADDCALL sass_boolean_get_value (const union Sass_Value* v);
ADDAPI void ADDCALL sass_boolean_set_value (union Sass_Value* v, bool value);
// Getters and setters for Sass_Color
ADDAPI double ADDCALL sass_color_get_r (const union Sass_Value* v);
ADDAPI void ADDCALL sass_color_set_r (union Sass_Value* v, double r);
ADDAPI double ADDCALL sass_color_get_g (const union Sass_Value* v);
ADDAPI void ADDCALL sass_color_set_g (union Sass_Value* v, double g);
ADDAPI double ADDCALL sass_color_get_b (const union Sass_Value* v);
ADDAPI void ADDCALL sass_color_set_b (union Sass_Value* v, double b);
ADDAPI double ADDCALL sass_color_get_a (const union Sass_Value* v);
ADDAPI void ADDCALL sass_color_set_a (union Sass_Value* v, double a);
// Getter for the number of items in list
ADDAPI size_t ADDCALL sass_list_get_length (const union Sass_Value* v);
// Getters and setters for Sass_List
ADDAPI enum Sass_Separator ADDCALL sass_list_get_separator (const union Sass_Value* v);
ADDAPI void ADDCALL sass_list_set_separator (union Sass_Value* v, enum Sass_Separator value);
ADDAPI bool ADDCALL sass_list_get_is_bracketed (const union Sass_Value* v);
ADDAPI void ADDCALL sass_list_set_is_bracketed (union Sass_Value* v, bool value);
// Getters and setters for Sass_List values
ADDAPI union Sass_Value* ADDCALL sass_list_get_value (const union Sass_Value* v, size_t i);
ADDAPI void ADDCALL sass_list_set_value (union Sass_Value* v, size_t i, union Sass_Value* value);
// Getter for the number of items in map
ADDAPI size_t ADDCALL sass_map_get_length (const union Sass_Value* v);
// Getters and setters for Sass_Map keys and values
ADDAPI union Sass_Value* ADDCALL sass_map_get_key (const union Sass_Value* v, size_t i);
ADDAPI void ADDCALL sass_map_set_key (union Sass_Value* v, size_t i, union Sass_Value*);
ADDAPI union Sass_Value* ADDCALL sass_map_get_value (const union Sass_Value* v, size_t i);
ADDAPI void ADDCALL sass_map_set_value (union Sass_Value* v, size_t i, union Sass_Value*);
// Getters and setters for Sass_Error
ADDAPI char* ADDCALL sass_error_get_message (const union Sass_Value* v);
ADDAPI void ADDCALL sass_error_set_message (union Sass_Value* v, char* msg);
// Getters and setters for Sass_Warning
ADDAPI char* ADDCALL sass_warning_get_message (const union Sass_Value* v);
ADDAPI void ADDCALL sass_warning_set_message (union Sass_Value* v, char* msg);
#ifdef __cplusplus
} // __cplusplus defined.
#endif
#endif
libsass-3.6.3/include/sass/version.h 0000664 0000000 0000000 00000000305 13557420656 0017430 0 ustar 00root root 0000000 0000000 #ifndef SASS_VERSION_H
#define SASS_VERSION_H
#ifndef LIBSASS_VERSION
#define LIBSASS_VERSION "[NA]"
#endif
#ifndef LIBSASS_LANGUAGE_VERSION
#define LIBSASS_LANGUAGE_VERSION "3.5"
#endif
#endif
libsass-3.6.3/include/sass/version.h.in 0000664 0000000 0000000 00000000322 13557420656 0020034 0 ustar 00root root 0000000 0000000 #ifndef SASS_VERSION_H
#define SASS_VERSION_H
#ifndef LIBSASS_VERSION
#define LIBSASS_VERSION "@PACKAGE_VERSION@"
#endif
#ifndef LIBSASS_LANGUAGE_VERSION
#define LIBSASS_LANGUAGE_VERSION "3.5"
#endif
#endif
libsass-3.6.3/include/sass2scss.h 0000664 0000000 0000000 00000004726 13557420656 0016734 0 ustar 00root root 0000000 0000000 /**
* sass2scss
* Licensed under the MIT License
* Copyright (c) Marcel Greter
*/
#ifndef SASS2SCSS_H
#define SASS2SCSS_H
#ifdef _WIN32
/* You should define ADD_EXPORTS *only* when building the DLL. */
#ifdef ADD_EXPORTS
#define ADDAPI __declspec(dllexport)
#define ADDCALL __cdecl
#else
#define ADDAPI
#define ADDCALL
#endif
#else /* _WIN32 not defined. */
/* Define with no value on non-Windows OSes. */
#define ADDAPI
#define ADDCALL
#endif
#ifdef __cplusplus
#include
#include
#include
#include
#include
#ifndef SASS2SCSS_VERSION
// Hardcode once the file is copied from
// https://github.com/mgreter/sass2scss
#define SASS2SCSS_VERSION "1.1.1"
#endif
// add namespace for c++
namespace Sass
{
// pretty print options
const int SASS2SCSS_PRETTIFY_0 = 0;
const int SASS2SCSS_PRETTIFY_1 = 1;
const int SASS2SCSS_PRETTIFY_2 = 2;
const int SASS2SCSS_PRETTIFY_3 = 3;
// remove one-line comment
const int SASS2SCSS_KEEP_COMMENT = 32;
// remove multi-line comments
const int SASS2SCSS_STRIP_COMMENT = 64;
// convert one-line to multi-line
const int SASS2SCSS_CONVERT_COMMENT = 128;
// String for finding something interesting
const std::string SASS2SCSS_FIND_WHITESPACE = " \t\n\v\f\r";
// converter struct
// holding all states
struct converter
{
// bit options
int options;
// is selector
bool selector;
// concat lists
bool comma;
// has property
bool property;
// has semicolon
bool semicolon;
// comment context
std::string comment;
// flag end of file
bool end_of_file;
// whitespace buffer
std::string whitespace;
// context/block stack
std::stack indents;
};
// function only available in c++ code
char* sass2scss (const std::string& sass, const int options);
}
// EO namespace
// declare for c
extern "C" {
#endif
// prettyfy print options
#define SASS2SCSS_PRETTIFY_0 0
#define SASS2SCSS_PRETTIFY_1 1
#define SASS2SCSS_PRETTIFY_2 2
#define SASS2SCSS_PRETTIFY_3 3
// keep one-line comments
#define SASS2SCSS_KEEP_COMMENT 32
// remove multi-line comments
#define SASS2SCSS_STRIP_COMMENT 64
// convert one-line to multi-line
#define SASS2SCSS_CONVERT_COMMENT 128
// available to c and c++ code
ADDAPI char* ADDCALL sass2scss (const char* sass, const int options);
// Get compiled sass2scss version
ADDAPI const char* ADDCALL sass2scss_version(void);
#ifdef __cplusplus
} // __cplusplus defined.
#endif
#endif libsass-3.6.3/m4/ 0000775 0000000 0000000 00000000000 13557420656 0013520 5 ustar 00root root 0000000 0000000 libsass-3.6.3/m4/.gitkeep 0000664 0000000 0000000 00000000000 13557420656 0015137 0 ustar 00root root 0000000 0000000 libsass-3.6.3/m4/m4-ax_cxx_compile_stdcxx_11.m4 0000664 0000000 0000000 00000013000 13557420656 0021172 0 ustar 00root root 0000000 0000000 # ============================================================================
# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
# ============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++11
# standard; if necessary, add switches to CXXFLAGS to enable support.
#
# The first argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
# -std=c++11). If neither is specified, you get whatever works, with
# preference for an extended mode.
#
# The second argument, if specified 'mandatory' or if left unspecified,
# indicates that baseline C++11 support is required and that the macro
# should error out if no mode with that support is found. If specified
# 'optional', then configuration proceeds regardless, after defining
# HAVE_CXX11 if and only if a supporting mode is found.
#
# LICENSE
#
# Copyright (c) 2008 Benjamin Kosnik
# Copyright (c) 2012 Zack Weinberg
# Copyright (c) 2013 Roy Stogner
# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 11
m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
template
struct check
{
static_assert(sizeof(int) <= sizeof(T), "not big enough");
};
struct Base {
virtual void f() {}
};
struct Child : public Base {
virtual void f() override {}
};
typedef check> right_angle_brackets;
int a;
decltype(a) b;
typedef check check_type;
check_type c;
check_type&& cr = static_cast(c);
auto d = a;
auto l = [](){};
// Prevent Clang error: unused variable 'l' [-Werror,-Wunused-variable]
struct use_l { use_l() { l(); } };
// http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
// Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function because of this
namespace test_template_alias_sfinae {
struct foo {};
template
using member = typename T::member_type;
template
void func(...) {}
template
void func(member*) {}
void test();
void test() {
func(0);
}
}
]])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
m4_if([$1], [], [],
[$1], [ext], [],
[$1], [noext], [],
[m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
[$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
[$2], [optional], [ax_cxx_compile_cxx11_required=false],
[m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
AC_LANG_PUSH([C++])dnl
ac_success=no
AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
ax_cv_cxx_compile_cxx11,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[ax_cv_cxx_compile_cxx11=yes],
[ax_cv_cxx_compile_cxx11=no])])
if test x$ax_cv_cxx_compile_cxx11 = xyes; then
ac_success=yes
fi
m4_if([$1], [noext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=gnu++11 -std=gnu++0x; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
m4_if([$1], [ext], [], [dnl
if test x$ac_success = xno; then
dnl HP's aCC needs +std=c++11 according to:
dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
for switch in -std=c++11 -std=c++0x +std=c++11; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
AC_LANG_POP([C++])
if test x$ax_cxx_compile_cxx11_required = xtrue; then
if test x$ac_success = xno; then
AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
fi
else
if test x$ac_success = xno; then
HAVE_CXX11=0
AC_MSG_NOTICE([No compiler with C++11 support was found])
else
HAVE_CXX11=1
AC_DEFINE(HAVE_CXX11,1,
[define if the compiler supports basic C++11 syntax])
fi
AC_SUBST(HAVE_CXX11)
fi
])
libsass-3.6.3/res/ 0000775 0000000 0000000 00000000000 13557420656 0013771 5 ustar 00root root 0000000 0000000 libsass-3.6.3/res/resource.rc 0000664 0000000 0000000 00000001631 13557420656 0016147 0 ustar 00root root 0000000 0000000 #include
// DLL version information.
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG | VS_FF_PRERELEASE
#else
FILEFLAGS 0
#endif
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", "Sass Open Source Foundation"
VALUE "FileDescription", "A C/C++ implementation of a Sass compiler"
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "libsass"
VALUE "LegalCopyright", "\251 2017 libsass.org"
VALUE "OriginalFilename", "libsass.dll"
VALUE "ProductName", "LibSass Library"
VALUE "ProductVersion", "1.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END
libsass-3.6.3/script/ 0000775 0000000 0000000 00000000000 13557420656 0014504 5 ustar 00root root 0000000 0000000 libsass-3.6.3/script/bootstrap 0000775 0000000 0000000 00000000453 13557420656 0016451 0 ustar 00root root 0000000 0000000 #!/bin/bash
script/branding
: ${SASS_SPEC_PATH:="sass-spec"}
: ${SASS_SASSC_PATH:="sassc" }
if [ ! -d $SASS_SPEC_PATH ]; then
git clone https://github.com/sass/sass-spec.git $SASS_SPEC_PATH
fi
if [ ! -d $SASS_SASSC_PATH ]; then
git clone https://github.com/sass/sassc.git $SASS_SASSC_PATH
fi
libsass-3.6.3/script/branding 0000775 0000000 0000000 00000000537 13557420656 0016223 0 ustar 00root root 0000000 0000000 #! /bin/bash
echo " "
echo " _ ___ ____ ____ _ ____ ____ "
echo "| | |_ _| __ ) ___| / \ / ___/ ___| "
echo "| | | || _ \___ \ / _ \ \___ \___ \ "
echo "| |___ | || |_) |__) / ___ \ ___) |__) |"
echo "|_____|___|____/____/_/ \_\____/____/ "
echo " "
libsass-3.6.3/script/ci-build-libsass 0000775 0000000 0000000 00000007670 13557420656 0017572 0 ustar 00root root 0000000 0000000 #!/bin/bash
set -e
script/bootstrap
# export this path right here (was in script/spec before)
export SASS_LIBSASS_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )"
# use some defaults if not running under travis ci
if [ "x$CONTINUOUS_INTEGRATION" == "x" ]; then export CONTINUOUS_INTEGRATION=true; fi
if [ "x$TRAVIS_BUILD_DIR" == "x" ]; then export TRAVIS_BUILD_DIR=$(pwd); fi
if [ "x$SASS_SASSC_PATH" == "x" ]; then export SASS_SASSC_PATH=$(pwd)/sassc; fi
if [ "x$SASS_SPEC_PATH" == "x" ]; then export SASS_SPEC_PATH=$(pwd)/sass-spec; fi
# try to get the os name from uname (and filter via perl - probably not the most portable way?)
if [ "x$TRAVIS_OS_NAME" == "x" ]; then export TRAVIS_OS_NAME=`uname -s | perl -ne 'print lc \$1 if\(/^([a-zA-Z]+)/'\)`; fi
if [ "x$COVERAGE" == "xyes" ]; then
COVERAGE_OPT="--enable-coverage"
export EXTRA_CFLAGS="-fprofile-arcs -ftest-coverage"
export EXTRA_CXXFLAGS="-fprofile-arcs -ftest-coverage"
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
# osx doesn't seem to know gcov lib?
export EXTRA_LDFLAGS="--coverage"
else
export EXTRA_LDFLAGS="-lgcov --coverage"
fi
else
COVERAGE_OPT="--disable-coverage"
fi
if [ "x$BUILD" == "xstatic" ]; then
SHARED_OPT="--disable-shared --enable-static"
MAKE_TARGET="static"
else
# Makefile of sassc wants to link to static
SHARED_OPT="--enable-shared --enable-static"
MAKE_TARGET="shared"
fi
if [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
MAKE_OPTS="$MAKE_OPTS -j1 V=1"
else
MAKE_OPTS="$MAKE_OPTS -j5 V=1"
fi
if [ "x$PREFIX" == "x" ]; then
if [ "x$TRAVIS_BUILD_DIR" == "x" ]; then
PREFIX=$SASS_LIBSASS_PATH/build
else
PREFIX=$TRAVIS_BUILD_DIR/build
fi
fi
# enable address sanitation
# https://en.wikipedia.org/wiki/AddressSanitizer
if [ "x$CC" == "xclang" ]; then
if [ "x$COVERAGE" != "xyes" ]; then
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
export EXTRA_CFLAGS="$EXTRA_CFLAGS -fsanitize=address"
export EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -fsanitize=address"
export EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fsanitize=address"
fi
fi
fi
echo SASS_LIBSASS_PATH: $SASS_LIBSASS_PATH
echo TRAVIS_BUILD_DIR: $TRAVIS_BUILD_DIR
echo SASS_SASSC_PATH: $SASS_SASSC_PATH
echo SASS_SPEC_PATH: $SASS_SPEC_PATH
echo INSTALL_LOCATION: $PREFIX
if [ "x$AUTOTOOLS" == "xyes" ]; then
echo -en 'travis_fold:start:configure\r'
autoreconf --force --install
./configure --enable-tests $COVERAGE_OPT \
--disable-silent-rules \
--with-sassc-dir=$SASS_SASSC_PATH \
--with-sass-spec-dir=$SASS_SPEC_PATH \
--prefix=$PREFIX \
${SHARED_OPT}
echo -en 'travis_fold:end:configure\r'
make $MAKE_OPTS clean
else
make $MAKE_OPTS clean
# Run C++ unit tests
make -C test clean
make -C test test
fi
# install to prefix directory
PREFIX="$PREFIX" make $MAKE_OPTS install
ls -la $PREFIX/*
echo successfully compiled libsass
echo AUTOTOOLS=$AUTOTOOLS COVERAGE=$COVERAGE BUILD=$BUILD
if [ "$CONTINUOUS_INTEGRATION" == "true" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ "x$TRAVIS_PULL_REQUEST" != "x" ] &&
([ "$TRAVIS_OS_NAME" == "linux" ] || [ "$TRAVIS_OS_NAME" == "osx" ] || [ "$TRAVIS_OS_NAME" == "cygwin" ]);
then
echo "Fetching PR $TRAVIS_PULL_REQUEST"
JSON=$(curl -L -sS https://api.github.com/repos/sass/libsass/pulls/$TRAVIS_PULL_REQUEST)
if [[ $JSON =~ "API rate limit exceeded" ]];
then
echo "Travis rate limit on github exceeded"
echo "Retrying via 'special purpose proxy'"
JSON=$(curl -L -sS https://github-api-reverse-proxy.herokuapp.com/repos/sass/libsass/pulls/$TRAVIS_PULL_REQUEST)
fi
RE_SPEC_PR="sass\/sass-spec(#|\/pull\/)([0-9]+)"
if [[ $JSON =~ $RE_SPEC_PR ]];
then
SPEC_PR="${BASH_REMATCH[2]}"
echo "Fetching Sass Spec PR $SPEC_PR"
git -C sass-spec fetch -u origin pull/$SPEC_PR/head:ci-spec-pr-$SPEC_PR
git -C sass-spec checkout --force ci-spec-pr-$SPEC_PR
make $MAKE_OPTS test_probe
else
make $MAKE_OPTS test_probe
fi
else
make $MAKE_OPTS test_probe
fi
libsass-3.6.3/script/ci-build-plugin 0000775 0000000 0000000 00000004043 13557420656 0017417 0 ustar 00root root 0000000 0000000 #!/bin/bash
PLUGIN=$1
RUBY_BIN=ruby
SASS_SPEC_PATH=sass-spec
SASSC_BIN=sassc/bin/sassc
SASS_SPEC_SPEC_DIR=plugins/libsass-${PLUGIN}/test
if [ -e ./tester ] ; then
SASSC_BIN=./tester
fi
if [ -d ./build/lib ] ; then
cp -a build/lib lib
fi
if [ "x$1" == "x" ] ; then
echo "No plugin name given"
exit 1
fi
if [ "x$COVERAGE" == "0" ] ; then
unset COVERAGE
fi
export EXTRA_CFLAGS=""
export EXTRA_CXXFLAGS=""
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
# osx doesn't seem to know gcov lib?
export EXTRA_LDFLAGS="--coverage"
else
export EXTRA_LDFLAGS="-lgcov --coverage"
fi
mkdir -p plugins
if [ ! -d plugins/libsass-${PLUGIN} ] ; then
git clone https://github.com/mgreter/libsass-${PLUGIN} plugins/libsass-${PLUGIN}
fi
if [ ! -d plugins/libsass-${PLUGIN}/build ] ; then
mkdir plugins/libsass-${PLUGIN}/build
fi
RETVAL=$?; if [ "$RETVAL" != "0" ]; then exit $RETVAL; fi
cd plugins/libsass-${PLUGIN}/build
cmake -G "Unix Makefiles" -D LIBSASS_DIR="../../.." ..
RETVAL=$?; if [ "$RETVAL" != "0" ]; then exit $RETVAL; fi
make VERBOSE=1 -j2
RETVAL=$?; if [ "$RETVAL" != "0" ]; then exit $RETVAL; fi
cd ../../..
# glob only works on paths relative to imports
if [ "x$PLUGIN" == "xglob" ]; then
${SASSC_BIN} --precision 5 --plugin-path plugins/libsass-${PLUGIN}/build ${SASS_SPEC_SPEC_DIR}/basic/input.scss > ${SASS_SPEC_SPEC_DIR}/basic/result.css
${SASSC_BIN} --precision 5 --plugin-path plugins/libsass-${PLUGIN}/build ${SASS_SPEC_SPEC_DIR}/basic/input.scss --sourcemap > /dev/null
else
cat ${SASS_SPEC_SPEC_DIR}/basic/input.scss | ${SASSC_BIN} --precision 5 --plugin-path plugins/libsass-${PLUGIN}/build -I ${SASS_SPEC_SPEC_DIR}/basic > ${SASS_SPEC_SPEC_DIR}/basic/result.css
cat ${SASS_SPEC_SPEC_DIR}/basic/input.scss | ${SASSC_BIN} --precision 5 --plugin-path plugins/libsass-${PLUGIN}/build -I ${SASS_SPEC_SPEC_DIR}/basic --sourcemap > /dev/null
fi
RETVAL=$?; if [ "$RETVAL" != "0" ]; then exit $RETVAL; fi
diff ${SASS_SPEC_SPEC_DIR}/basic/expected_output.css ${SASS_SPEC_SPEC_DIR}/basic/result.css
RETVAL=$?; if [ "$RETVAL" != "0" ]; then exit $RETVAL; fi
libsass-3.6.3/script/ci-install-compiler 0000775 0000000 0000000 00000000160 13557420656 0020276 0 ustar 00root root 0000000 0000000 #!/bin/bash
gem install minitest
gem install minitap
gem install hrx
pip2 install --user 'requests[security]'
libsass-3.6.3/script/ci-install-deps 0000775 0000000 0000000 00000000634 13557420656 0017425 0 ustar 00root root 0000000 0000000 #!/bin/bash
if [ "x$COVERAGE" == "xyes" ]; then
pip2 install --user gcovr
pip2 install --user cpp-coveralls
else
echo "no dependencies to install"
fi
if [ "x$AUTOTOOLS" == "xyes" ]; then
AUTOTOOLS=yes
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
sudo add-apt-repository -y ppa:rbose-debianizer/automake &> /dev/null
sudo apt-get -qq update
sudo apt-get -qq install automake
fi
fi
exit 0
libsass-3.6.3/script/ci-report-coverage 0000775 0000000 0000000 00000002671 13557420656 0020135 0 ustar 00root root 0000000 0000000 #!/bin/bash
if [ "x$COVERAGE" = "xyes" ]; then
# find / -name "gcovr"
# find / -name "coveralls"
# this is only needed for mac os x builds!
PATH=$PATH:/Users/travis/Library/Python/2.7/bin/
# exclude some directories from profiling (.libs is from autotools)
export EXCLUDE_COVERAGE="--exclude plugins
--exclude sassc/sassc.c
--exclude src/sass-spec
--exclude src/.libs
--exclude src/debug.hpp
--exclude src/json.cpp
--exclude src/json.hpp
--exclude src/cencode.c
--exclude src/b64
--exclude src/utf8
--exclude src/utf8_string.hpp
--exclude src/utf8.h
--exclude src/utf8_string.cpp
--exclude src/sass2scss.h
--exclude src/sass2scss.cpp
--exclude src/test
--exclude src/posix
--exclude src/debugger.hpp"
# debug used gcov version
# option not available on mac
if [ "$TRAVIS_OS_NAME" != "osx" ]; then
gcov -v
fi
# create summarized report
gcovr -r .
# submit report to coveralls.io
coveralls $EXCLUDE_COVERAGE --gcov-options '\-lp'
else
echo "skip coverage reporting"
fi
libsass-3.6.3/script/spec 0000775 0000000 0000000 00000000072 13557420656 0015363 0 ustar 00root root 0000000 0000000 #!/bin/bash
script/bootstrap
make $MAKE_OPTS test_build
libsass-3.6.3/script/tap-driver 0000775 0000000 0000000 00000046101 13557420656 0016511 0 ustar 00root root 0000000 0000000 #!/usr/bin/env sh
# Copyright (C) 2011-2013 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to or send patches to
# .
scriptversion=2011-12-27.17; # UTC
# Make unconditional expansion of undefined variables an error. This
# helps a lot in preventing typo-related bugs.
set -u
me=tap-driver.sh
fatal ()
{
echo "$me: fatal: $*" >&2
exit 1
}
usage_error ()
{
echo "$me: $*" >&2
print_usage >&2
exit 2
}
print_usage ()
{
cat <
#
trap : 1 3 2 13 15
if test $merge -gt 0; then
exec 2>&1
else
exec 2>&3
fi
"$@"
echo $?
) | LC_ALL=C ${AM_TAP_AWK-awk} \
-v me="$me" \
-v test_script_name="$test_name" \
-v log_file="$log_file" \
-v trs_file="$trs_file" \
-v expect_failure="$expect_failure" \
-v merge="$merge" \
-v ignore_exit="$ignore_exit" \
-v comments="$comments" \
-v diag_string="$diag_string" \
'
# FIXME: the usages of "cat >&3" below could be optimized when using
# FIXME: GNU awk, and/on on systems that supports /dev/fd/.
# Implementation note: in what follows, `result_obj` will be an
# associative array that (partly) simulates a TAP result object
# from the `TAP::Parser` perl module.
## ----------- ##
## FUNCTIONS ##
## ----------- ##
function fatal(msg)
{
print me ": " msg | "cat >&2"
exit 1
}
function abort(where)
{
fatal("internal error " where)
}
# Convert a boolean to a "yes"/"no" string.
function yn(bool)
{
return bool ? "yes" : "no";
}
function add_test_result(result)
{
if (!test_results_index)
test_results_index = 0
test_results_list[test_results_index] = result
test_results_index += 1
test_results_seen[result] = 1;
}
# Whether the test script should be re-run by "make recheck".
function must_recheck()
{
for (k in test_results_seen)
if (k != "XFAIL" && k != "PASS" && k != "SKIP")
return 1
return 0
}
# Whether the content of the log file associated to this test should
# be copied into the "global" test-suite.log.
function copy_in_global_log()
{
for (k in test_results_seen)
if (k != "PASS")
return 1
return 0
}
# FIXME: this can certainly be improved ...
function get_global_test_result()
{
if ("ERROR" in test_results_seen)
return "ERROR"
if ("FAIL" in test_results_seen || "XPASS" in test_results_seen)
return "FAIL"
all_skipped = 1
for (k in test_results_seen)
if (k != "SKIP")
all_skipped = 0
if (all_skipped)
return "SKIP"
return "PASS";
}
function stringify_result_obj(result_obj)
{
if (result_obj["is_unplanned"] || result_obj["number"] != testno)
return "ERROR"
if (plan_seen == LATE_PLAN)
return "ERROR"
if (result_obj["directive"] == "TODO")
return result_obj["is_ok"] ? "XPASS" : "XFAIL"
if (result_obj["directive"] == "SKIP")
return result_obj["is_ok"] ? "SKIP" : COOKED_FAIL;
if (length(result_obj["directive"]))
abort("in function stringify_result_obj()")
return result_obj["is_ok"] ? COOKED_PASS : COOKED_FAIL
}
function decorate_result(result)
{
color_name = color_for_result[result]
if (color_name)
return color_map[color_name] "" result "" color_map["std"]
# If we are not using colorized output, or if we do not know how
# to colorize the given result, we should return it unchanged.
return result
}
function report(result, details)
{
if (result ~ /^(X?(PASS|FAIL)|SKIP|ERROR)/)
{
msg = ": " test_script_name
add_test_result(result)
}
else if (result == "#")
{
msg = " " test_script_name ":"
}
else
{
abort("in function report()")
}
if (length(details))
msg = msg " " details
# Output on console might be colorized.
print decorate_result(result) msg
# Log the result in the log file too, to help debugging (this is
# especially true when said result is a TAP error or "Bail out!").
print result msg | "cat >&3";
}
function testsuite_error(error_message)
{
report("ERROR", "- " error_message)
}
function handle_tap_result()
{
details = result_obj["number"];
if (length(result_obj["description"]))
details = details " " result_obj["description"]
if (plan_seen == LATE_PLAN)
{
details = details " # AFTER LATE PLAN";
}
else if (result_obj["is_unplanned"])
{
details = details " # UNPLANNED";
}
else if (result_obj["number"] != testno)
{
details = sprintf("%s # OUT-OF-ORDER (expecting %d)",
details, testno);
}
else if (result_obj["directive"])
{
details = details " # " result_obj["directive"];
if (length(result_obj["explanation"]))
details = details " " result_obj["explanation"]
}
report(stringify_result_obj(result_obj), details)
}
# `skip_reason` should be empty whenever planned > 0.
function handle_tap_plan(planned, skip_reason)
{
planned += 0 # Avoid getting confused if, say, `planned` is "00"
if (length(skip_reason) && planned > 0)
abort("in function handle_tap_plan()")
if (plan_seen)
{
# Error, only one plan per stream is acceptable.
testsuite_error("multiple test plans")
return;
}
planned_tests = planned
# The TAP plan can come before or after *all* the TAP results; we speak
# respectively of an "early" or a "late" plan. If we see the plan line
# after at least one TAP result has been seen, assume we have a late
# plan; in this case, any further test result seen after the plan will
# be flagged as an error.
plan_seen = (testno >= 1 ? LATE_PLAN : EARLY_PLAN)
# If testno > 0, we have an error ("too many tests run") that will be
# automatically dealt with later, so do not worry about it here. If
# $plan_seen is true, we have an error due to a repeated plan, and that
# has already been dealt with above. Otherwise, we have a valid "plan
# with SKIP" specification, and should report it as a particular kind
# of SKIP result.
if (planned == 0 && testno == 0)
{
if (length(skip_reason))
skip_reason = "- " skip_reason;
report("SKIP", skip_reason);
}
}
function extract_tap_comment(line)
{
if (index(line, diag_string) == 1)
{
# Strip leading `diag_string` from `line`.
line = substr(line, length(diag_string) + 1)
# And strip any leading and trailing whitespace left.
sub("^[ \t]*", "", line)
sub("[ \t]*$", "", line)
# Return what is left (if any).
return line;
}
return "";
}
# When this function is called, we know that line is a TAP result line,
# so that it matches the (perl) RE "^(not )?ok\b".
function setup_result_obj(line)
{
# Get the result, and remove it from the line.
result_obj["is_ok"] = (substr(line, 1, 2) == "ok" ? 1 : 0)
sub("^(not )?ok[ \t]*", "", line)
# If the result has an explicit number, get it and strip it; otherwise,
# automatically assing the next progresive number to it.
if (line ~ /^[0-9]+$/ || line ~ /^[0-9]+[^a-zA-Z0-9_]/)
{
match(line, "^[0-9]+")
# The final `+ 0` is to normalize numbers with leading zeros.
result_obj["number"] = substr(line, 1, RLENGTH) + 0
line = substr(line, RLENGTH + 1)
}
else
{
result_obj["number"] = testno
}
if (plan_seen == LATE_PLAN)
# No further test results are acceptable after a "late" TAP plan
# has been seen.
result_obj["is_unplanned"] = 1
else if (plan_seen && testno > planned_tests)
result_obj["is_unplanned"] = 1
else
result_obj["is_unplanned"] = 0
# Strip trailing and leading whitespace.
sub("^[ \t]*", "", line)
sub("[ \t]*$", "", line)
# This will have to be corrected if we have a "TODO"/"SKIP" directive.
result_obj["description"] = line
result_obj["directive"] = ""
result_obj["explanation"] = ""
if (index(line, "#") == 0)
return # No possible directive, nothing more to do.
# Directives are case-insensitive.
rx = "[ \t]*#[ \t]*([tT][oO][dD][oO]|[sS][kK][iI][pP])[ \t]*"
# See whether we have the directive, and if yes, where.
pos = match(line, rx "$")
if (!pos)
pos = match(line, rx "[^a-zA-Z0-9_]")
# If there was no TAP directive, we have nothing more to do.
if (!pos)
return
# Let`s now see if the TAP directive has been escaped. For example:
# escaped: ok \# SKIP
# not escaped: ok \\# SKIP
# escaped: ok \\\\\# SKIP
# not escaped: ok \ # SKIP
if (substr(line, pos, 1) == "#")
{
bslash_count = 0
for (i = pos; i > 1 && substr(line, i - 1, 1) == "\\"; i--)
bslash_count += 1
if (bslash_count % 2)
return # Directive was escaped.
}
# Strip the directive and its explanation (if any) from the test
# description.
result_obj["description"] = substr(line, 1, pos - 1)
# Now remove the test description from the line, that has been dealt
# with already.
line = substr(line, pos)
# Strip the directive, and save its value (normalized to upper case).
sub("^[ \t]*#[ \t]*", "", line)
result_obj["directive"] = toupper(substr(line, 1, 4))
line = substr(line, 5)
# Now get the explanation for the directive (if any), with leading
# and trailing whitespace removed.
sub("^[ \t]*", "", line)
sub("[ \t]*$", "", line)
result_obj["explanation"] = line
}
function get_test_exit_message(status)
{
if (status == 0)
return ""
if (status !~ /^[1-9][0-9]*$/)
abort("getting exit status")
if (status < 127)
exit_details = ""
else if (status == 127)
exit_details = " (command not found?)"
else if (status >= 128 && status <= 255)
exit_details = sprintf(" (terminated by signal %d?)", status - 128)
else if (status > 256 && status <= 384)
# We used to report an "abnormal termination" here, but some Korn
# shells, when a child process die due to signal number n, can leave
# in $? an exit status of 256+n instead of the more standard 128+n.
# Apparently, both behaviours are allowed by POSIX (2008), so be
# prepared to handle them both. See also Austing Group report ID
# 0000051
exit_details = sprintf(" (terminated by signal %d?)", status - 256)
else
# Never seen in practice.
exit_details = " (abnormal termination)"
return sprintf("exited with status %d%s", status, exit_details)
}
function write_test_results()
{
print ":global-test-result: " get_global_test_result() > trs_file
print ":recheck: " yn(must_recheck()) > trs_file
print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file
for (i = 0; i < test_results_index; i += 1)
print ":test-result: " test_results_list[i] > trs_file
close(trs_file);
}
BEGIN {
## ------- ##
## SETUP ##
## ------- ##
'"$init_colors"'
# Properly initialized once the TAP plan is seen.
planned_tests = 0
COOKED_PASS = expect_failure ? "XPASS": "PASS";
COOKED_FAIL = expect_failure ? "XFAIL": "FAIL";
# Enumeration-like constants to remember which kind of plan (if any)
# has been seen. It is important that NO_PLAN evaluates "false" as
# a boolean.
NO_PLAN = 0
EARLY_PLAN = 1
LATE_PLAN = 2
testno = 0 # Number of test results seen so far.
bailed_out = 0 # Whether a "Bail out!" directive has been seen.
# Whether the TAP plan has been seen or not, and if yes, which kind
# it is ("early" is seen before any test result, "late" otherwise).
plan_seen = NO_PLAN
## --------- ##
## PARSING ##
## --------- ##
is_first_read = 1
while (1)
{
# Involutions required so that we are able to read the exit status
# from the last input line.
st = getline
if (st < 0) # I/O error.
fatal("I/O error while reading from input stream")
else if (st == 0) # End-of-input
{
if (is_first_read)
abort("in input loop: only one input line")
break
}
if (is_first_read)
{
is_first_read = 0
nextline = $0
continue
}
else
{
curline = nextline
nextline = $0
$0 = curline
}
# Copy any input line verbatim into the log file.
print | "cat >&3"
# Parsing of TAP input should stop after a "Bail out!" directive.
if (bailed_out)
continue
# TAP test result.
if ($0 ~ /^(not )?ok$/ || $0 ~ /^(not )?ok[^a-zA-Z0-9_]/)
{
testno += 1
setup_result_obj($0)
handle_tap_result()
}
# TAP plan (normal or "SKIP" without explanation).
else if ($0 ~ /^1\.\.[0-9]+[ \t]*$/)
{
# The next two lines will put the number of planned tests in $0.
sub("^1\\.\\.", "")
sub("[^0-9]*$", "")
handle_tap_plan($0, "")
continue
}
# TAP "SKIP" plan, with an explanation.
else if ($0 ~ /^1\.\.0+[ \t]*#/)
{
# The next lines will put the skip explanation in $0, stripping
# any leading and trailing whitespace. This is a little more
# tricky in truth, since we want to also strip a potential leading
# "SKIP" string from the message.
sub("^[^#]*#[ \t]*(SKIP[: \t][ \t]*)?", "")
sub("[ \t]*$", "");
handle_tap_plan(0, $0)
}
# "Bail out!" magic.
# Older versions of prove and TAP::Harness (e.g., 3.17) did not
# recognize a "Bail out!" directive when preceded by leading
# whitespace, but more modern versions (e.g., 3.23) do. So we
# emulate the latter, "more modern" behaviour.
else if ($0 ~ /^[ \t]*Bail out!/)
{
bailed_out = 1
# Get the bailout message (if any), with leading and trailing
# whitespace stripped. The message remains stored in `$0`.
sub("^[ \t]*Bail out![ \t]*", "");
sub("[ \t]*$", "");
# Format the error message for the
bailout_message = "Bail out!"
if (length($0))
bailout_message = bailout_message " " $0
testsuite_error(bailout_message)
}
# Maybe we have too look for dianogtic comments too.
else if (comments != 0)
{
comment = extract_tap_comment($0);
if (length(comment))
report("#", comment);
}
}
## -------- ##
## FINISH ##
## -------- ##
# A "Bail out!" directive should cause us to ignore any following TAP
# error, as well as a non-zero exit status from the TAP producer.
if (!bailed_out)
{
if (!plan_seen)
{
testsuite_error("missing test plan")
}
else if (planned_tests != testno)
{
bad_amount = testno > planned_tests ? "many" : "few"
testsuite_error(sprintf("too %s tests run (expected %d, got %d)",
bad_amount, planned_tests, testno))
}
if (!ignore_exit)
{
# Fetch exit status from the last line.
exit_message = get_test_exit_message(nextline)
if (exit_message)
testsuite_error(exit_message)
}
}
write_test_results()
exit 0
} # End of "BEGIN" block.
'
# TODO: document that we consume the file descriptor 3 :-(
} 3>"$log_file"
test $? -eq 0 || fatal "I/O or internal error"
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:
libsass-3.6.3/script/tap-runner 0000775 0000000 0000000 00000000053 13557420656 0016523 0 ustar 00root root 0000000 0000000 $@ $TEST_FLAGS --tap --silent | tapout tap
libsass-3.6.3/script/test-leaks.pl 0000775 0000000 0000000 00000006476 13557420656 0017135 0 ustar 00root root 0000000 0000000 #!/usr/bin/perl
############################################################
# this perl script is meant for developers only!
# it will run all spec-tests (without verifying the
# results) via valgrind to detect possible leaks.
# expect that it takes 1h or more to finish!
############################################################
# Prerequisite install: `cpan Parallel::Runner`
# You may also need to install `cpan File::Find`
# You may also need to install `cpan IPC::Run3`
############################################################
# usage: `perl test-leaks.pl [threads]`
# example: `time perl test-leaks.pl 4`
############################################################
# leaks will be reported in "mem-leaks.log"
############################################################
use strict;
use warnings;
############################################################
# configurations (you may adjust)
############################################################
# number of threads to use
my $threads = $ARGV[0] || 8;
# the github repositories to checkout
# if you need other branch, clone manually!
my $sassc = "https://www.github.com/sass/sassc";
my $specs = "https://www.github.com/sass/sass-spec";
############################################################
# load modules
############################################################
use IPC::Run3;
use IO::Handle;
use Fcntl qw(:flock);
use File::Find::Rule;
use Parallel::Runner;
use List::Util qw(shuffle);
############################################################
# check prerequisites
############################################################
unless (-d "../sassc") {
warn "sassc folder not found\n";
warn "trying to checkout via git\n";
system("git", "clone", $sassc, "../sassc");
die "git command did not exit gracefully" if $?;
}
unless (-d "../sass-spec") {
warn "sass-spec folder not found\n";
warn "trying to checkout via git\n";
system("git", "clone", $specs, "../sass-spec");
die "git command did not exit gracefully" if $?;
}
unless (-f "../sassc/bin/sassc") {
warn "sassc executable not found\n";
warn "trying to compile via make\n";
system("make", "-C", "../sassc", "-j", $threads);
die "make command did not exit gracefully" if $?;
}
############################################################
# main runner code
############################################################
my $root = "../sass-spec/spec";
my @files = File::Find::Rule->file()
->name('input.scss')->in($root);
open(my $leaks, ">", "mem-leaks.log");
die "Cannot open log" unless $leaks;
my $runner = Parallel::Runner->new($threads);
die "Cannot start runner" unless $runner;
print "##########################\n";
print "Testing $#files spec files\n";
print "##########################\n";
foreach my $file (shuffle @files) {
$runner->run(sub {
$| = 1; select STDOUT;
my $cmd = sprintf('../sassc/bin/sassc %s', $file);
my $check = sprintf('valgrind --leak-check=yes %s', $cmd);
run3($check, undef, \ my $out, \ my $err);
if ($err =~ m/in use at exit: 0 bytes in 0 blocks/) {
print "."; # print success indicator
} else {
print "F"; # print error indicator
flock($leaks, LOCK_EX) or die "Cannot lock log";
$leaks->printflush("#" x 80, "\n", $err, "\n");
flock($leaks, LOCK_UN) or die "Cannot unlock log";
}
});
}
$runner->finish;
libsass-3.6.3/src/ 0000775 0000000 0000000 00000000000 13557420656 0013767 5 ustar 00root root 0000000 0000000 libsass-3.6.3/src/GNUmakefile.am 0000664 0000000 0000000 00000002271 13557420656 0016437 0 ustar 00root root 0000000 0000000 ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4 -I script
AM_COPT = -Wall -O2
AM_COVLDFLAGS =
if ENABLE_COVERAGE
AM_COPT = -O0 --coverage
AM_COVLDFLAGS += -lgcov
endif
AM_CPPFLAGS = -I$(top_srcdir)/include
AM_CFLAGS = $(AM_COPT)
AM_CXXFLAGS = $(AM_COPT)
AM_LDFLAGS = $(AM_COPT) $(AM_COVLDFLAGS)
AM_CXXFLAGS += -std=c++11
EXTRA_DIST = \
COPYING \
INSTALL \
LICENSE \
Readme.md
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = support/libsass.pc
lib_LTLIBRARIES = libsass.la
include $(top_srcdir)/Makefile.conf
libsass_la_SOURCES = ${CSOURCES} ${SOURCES}
libsass_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 1:0:0
if ENABLE_TESTS
if ENABLE_COVERAGE
nodist_EXTRA_libsass_la_SOURCES = non-existent-file-to-force-CXX-linking.cxx
endif
endif
include_HEADERS = $(top_srcdir)/include/sass.h \
$(top_srcdir)/include/sass2scss.h
sass_includedir = $(includedir)/sass
sass_include_HEADERS = $(top_srcdir)/include/sass/base.h \
$(top_srcdir)/include/sass/values.h \
$(top_srcdir)/include/sass/version.h \
$(top_srcdir)/include/sass/context.h \
$(top_srcdir)/include/sass/functions.h
libsass-3.6.3/src/ast.cpp 0000664 0000000 0000000 00000074176 13557420656 0015301 0 ustar 00root root 0000000 0000000 // sass.hpp must go before all system headers to get the
// __EXTENSIONS__ fix on Solaris.
#include "sass.hpp"
#include "ast.hpp"
namespace Sass {
static Null sass_null(ParserState("null"));
const char* sass_op_to_name(enum Sass_OP op) {
switch (op) {
case AND: return "and";
case OR: return "or";
case EQ: return "eq";
case NEQ: return "neq";
case GT: return "gt";
case GTE: return "gte";
case LT: return "lt";
case LTE: return "lte";
case ADD: return "plus";
case SUB: return "minus";
case MUL: return "times";
case DIV: return "div";
case MOD: return "mod";
// this is only used internally!
case NUM_OPS: return "[OPS]";
default: return "invalid";
}
}
const char* sass_op_separator(enum Sass_OP op) {
switch (op) {
case AND: return "&&";
case OR: return "||";
case EQ: return "==";
case NEQ: return "!=";
case GT: return ">";
case GTE: return ">=";
case LT: return "<";
case LTE: return "<=";
case ADD: return "+";
case SUB: return "-";
case MUL: return "*";
case DIV: return "/";
case MOD: return "%";
// this is only used internally!
case NUM_OPS: return "[OPS]";
default: return "invalid";
}
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
void AST_Node::update_pstate(const ParserState& pstate)
{
pstate_.offset += pstate - pstate_ + pstate.offset;
}
std::string AST_Node::to_string(Sass_Inspect_Options opt) const
{
Sass_Output_Options out(opt);
Emitter emitter(out);
Inspect i(emitter);
i.in_declaration = true;
// ToDo: inspect should be const
const_cast(this)->perform(&i);
return i.get_buffer();
}
std::string AST_Node::to_css(Sass_Inspect_Options opt) const
{
opt.output_style = TO_CSS;
Sass_Output_Options out(opt);
Emitter emitter(out);
Inspect i(emitter);
i.in_declaration = true;
// ToDo: inspect should be const
const_cast(this)->perform(&i);
return i.get_buffer();
}
std::string AST_Node::to_string() const
{
return to_string({ NESTED, 5 });
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Statement::Statement(ParserState pstate, Type st, size_t t)
: AST_Node(pstate), statement_type_(st), tabs_(t), group_end_(false)
{ }
Statement::Statement(const Statement* ptr)
: AST_Node(ptr),
statement_type_(ptr->statement_type_),
tabs_(ptr->tabs_),
group_end_(ptr->group_end_)
{ }
bool Statement::bubbles()
{
return false;
}
bool Statement::has_content()
{
return statement_type_ == CONTENT;
}
bool Statement::is_invisible() const
{
return false;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Block::Block(ParserState pstate, size_t s, bool r)
: Statement(pstate),
Vectorized(s),
is_root_(r)
{ }
Block::Block(const Block* ptr)
: Statement(ptr),
Vectorized(*ptr),
is_root_(ptr->is_root_)
{ }
bool Block::isInvisible() const
{
for (auto& item : elements()) {
if (!item->is_invisible()) return false;
}
return true;
}
bool Block::has_content()
{
for (size_t i = 0, L = elements().size(); i < L; ++i) {
if (elements()[i]->has_content()) return true;
}
return Statement::has_content();
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Has_Block::Has_Block(ParserState pstate, Block_Obj b)
: Statement(pstate), block_(b)
{ }
Has_Block::Has_Block(const Has_Block* ptr)
: Statement(ptr), block_(ptr->block_)
{ }
bool Has_Block::has_content()
{
return (block_ && block_->has_content()) || Statement::has_content();
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Ruleset::Ruleset(ParserState pstate, SelectorListObj s, Block_Obj b)
: Has_Block(pstate, b), selector_(s), schema_(), is_root_(false)
{ statement_type(RULESET); }
Ruleset::Ruleset(const Ruleset* ptr)
: Has_Block(ptr),
selector_(ptr->selector_),
schema_(ptr->schema_),
is_root_(ptr->is_root_)
{ statement_type(RULESET); }
bool Ruleset::is_invisible() const {
if (const SelectorList * sl = Cast(selector())) {
for (size_t i = 0, L = sl->length(); i < L; i += 1)
if (!(*sl)[i]->isInvisible()) return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Bubble::Bubble(ParserState pstate, Statement_Obj n, Statement_Obj g, size_t t)
: Statement(pstate, Statement::BUBBLE, t), node_(n), group_end_(g == nullptr)
{ }
Bubble::Bubble(const Bubble* ptr)
: Statement(ptr),
node_(ptr->node_),
group_end_(ptr->group_end_)
{ }
bool Bubble::bubbles()
{
return true;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Trace::Trace(ParserState pstate, std::string n, Block_Obj b, char type)
: Has_Block(pstate, b), type_(type), name_(n)
{ }
Trace::Trace(const Trace* ptr)
: Has_Block(ptr),
type_(ptr->type_),
name_(ptr->name_)
{ }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Directive::Directive(ParserState pstate, std::string kwd, SelectorListObj sel, Block_Obj b, Expression_Obj val)
: Has_Block(pstate, b), keyword_(kwd), selector_(sel), value_(val) // set value manually if needed
{ statement_type(DIRECTIVE); }
Directive::Directive(const Directive* ptr)
: Has_Block(ptr),
keyword_(ptr->keyword_),
selector_(ptr->selector_),
value_(ptr->value_) // set value manually if needed
{ statement_type(DIRECTIVE); }
bool Directive::bubbles() { return is_keyframes() || is_media(); }
bool Directive::is_media() {
return keyword_.compare("@-webkit-media") == 0 ||
keyword_.compare("@-moz-media") == 0 ||
keyword_.compare("@-o-media") == 0 ||
keyword_.compare("@media") == 0;
}
bool Directive::is_keyframes() {
return keyword_.compare("@-webkit-keyframes") == 0 ||
keyword_.compare("@-moz-keyframes") == 0 ||
keyword_.compare("@-o-keyframes") == 0 ||
keyword_.compare("@keyframes") == 0;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Keyframe_Rule::Keyframe_Rule(ParserState pstate, Block_Obj b)
: Has_Block(pstate, b), name_()
{ statement_type(KEYFRAMERULE); }
Keyframe_Rule::Keyframe_Rule(const Keyframe_Rule* ptr)
: Has_Block(ptr), name_(ptr->name_)
{ statement_type(KEYFRAMERULE); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Declaration::Declaration(ParserState pstate, String_Obj prop, Expression_Obj val, bool i, bool c, Block_Obj b)
: Has_Block(pstate, b), property_(prop), value_(val), is_important_(i), is_custom_property_(c), is_indented_(false)
{ statement_type(DECLARATION); }
Declaration::Declaration(const Declaration* ptr)
: Has_Block(ptr),
property_(ptr->property_),
value_(ptr->value_),
is_important_(ptr->is_important_),
is_custom_property_(ptr->is_custom_property_),
is_indented_(ptr->is_indented_)
{ statement_type(DECLARATION); }
bool Declaration::is_invisible() const
{
if (is_custom_property()) return false;
return !(value_ && !Cast(value_));
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Assignment::Assignment(ParserState pstate, std::string var, Expression_Obj val, bool is_default, bool is_global)
: Statement(pstate), variable_(var), value_(val), is_default_(is_default), is_global_(is_global)
{ statement_type(ASSIGNMENT); }
Assignment::Assignment(const Assignment* ptr)
: Statement(ptr),
variable_(ptr->variable_),
value_(ptr->value_),
is_default_(ptr->is_default_),
is_global_(ptr->is_global_)
{ statement_type(ASSIGNMENT); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Import::Import(ParserState pstate)
: Statement(pstate),
urls_(std::vector()),
incs_(std::vector()),
import_queries_()
{ statement_type(IMPORT); }
Import::Import(const Import* ptr)
: Statement(ptr),
urls_(ptr->urls_),
incs_(ptr->incs_),
import_queries_(ptr->import_queries_)
{ statement_type(IMPORT); }
std::vector& Import::incs() { return incs_; }
std::vector& Import::urls() { return urls_; }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Import_Stub::Import_Stub(ParserState pstate, Include res)
: Statement(pstate), resource_(res)
{ statement_type(IMPORT_STUB); }
Import_Stub::Import_Stub(const Import_Stub* ptr)
: Statement(ptr), resource_(ptr->resource_)
{ statement_type(IMPORT_STUB); }
Include Import_Stub::resource() { return resource_; };
std::string Import_Stub::imp_path() { return resource_.imp_path; };
std::string Import_Stub::abs_path() { return resource_.abs_path; };
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Warning::Warning(ParserState pstate, Expression_Obj msg)
: Statement(pstate), message_(msg)
{ statement_type(WARNING); }
Warning::Warning(const Warning* ptr)
: Statement(ptr), message_(ptr->message_)
{ statement_type(WARNING); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Error::Error(ParserState pstate, Expression_Obj msg)
: Statement(pstate), message_(msg)
{ statement_type(ERROR); }
Error::Error(const Error* ptr)
: Statement(ptr), message_(ptr->message_)
{ statement_type(ERROR); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Debug::Debug(ParserState pstate, Expression_Obj val)
: Statement(pstate), value_(val)
{ statement_type(DEBUGSTMT); }
Debug::Debug(const Debug* ptr)
: Statement(ptr), value_(ptr->value_)
{ statement_type(DEBUGSTMT); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Comment::Comment(ParserState pstate, String_Obj txt, bool is_important)
: Statement(pstate), text_(txt), is_important_(is_important)
{ statement_type(COMMENT); }
Comment::Comment(const Comment* ptr)
: Statement(ptr),
text_(ptr->text_),
is_important_(ptr->is_important_)
{ statement_type(COMMENT); }
bool Comment::is_invisible() const
{
return false;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
If::If(ParserState pstate, Expression_Obj pred, Block_Obj con, Block_Obj alt)
: Has_Block(pstate, con), predicate_(pred), alternative_(alt)
{ statement_type(IF); }
If::If(const If* ptr)
: Has_Block(ptr),
predicate_(ptr->predicate_),
alternative_(ptr->alternative_)
{ statement_type(IF); }
bool If::has_content()
{
return Has_Block::has_content() || (alternative_ && alternative_->has_content());
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
For::For(ParserState pstate,
std::string var, Expression_Obj lo, Expression_Obj hi, Block_Obj b, bool inc)
: Has_Block(pstate, b),
variable_(var), lower_bound_(lo), upper_bound_(hi), is_inclusive_(inc)
{ statement_type(FOR); }
For::For(const For* ptr)
: Has_Block(ptr),
variable_(ptr->variable_),
lower_bound_(ptr->lower_bound_),
upper_bound_(ptr->upper_bound_),
is_inclusive_(ptr->is_inclusive_)
{ statement_type(FOR); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Each::Each(ParserState pstate, std::vector vars, Expression_Obj lst, Block_Obj b)
: Has_Block(pstate, b), variables_(vars), list_(lst)
{ statement_type(EACH); }
Each::Each(const Each* ptr)
: Has_Block(ptr), variables_(ptr->variables_), list_(ptr->list_)
{ statement_type(EACH); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
While::While(ParserState pstate, Expression_Obj pred, Block_Obj b)
: Has_Block(pstate, b), predicate_(pred)
{ statement_type(WHILE); }
While::While(const While* ptr)
: Has_Block(ptr), predicate_(ptr->predicate_)
{ statement_type(WHILE); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Return::Return(ParserState pstate, Expression_Obj val)
: Statement(pstate), value_(val)
{ statement_type(RETURN); }
Return::Return(const Return* ptr)
: Statement(ptr), value_(ptr->value_)
{ statement_type(RETURN); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
ExtendRule::ExtendRule(ParserState pstate, SelectorListObj s)
: Statement(pstate), isOptional_(false), selector_(s), schema_()
{ statement_type(EXTEND); }
ExtendRule::ExtendRule(ParserState pstate, Selector_Schema_Obj s)
: Statement(pstate), isOptional_(false), selector_(), schema_(s)
{
statement_type(EXTEND);
}
ExtendRule::ExtendRule(const ExtendRule* ptr)
: Statement(ptr),
isOptional_(ptr->isOptional_),
selector_(ptr->selector_),
schema_(ptr->schema_)
{ statement_type(EXTEND); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Definition::Definition(const Definition* ptr)
: Has_Block(ptr),
name_(ptr->name_),
parameters_(ptr->parameters_),
environment_(ptr->environment_),
type_(ptr->type_),
native_function_(ptr->native_function_),
c_function_(ptr->c_function_),
cookie_(ptr->cookie_),
is_overload_stub_(ptr->is_overload_stub_),
signature_(ptr->signature_)
{ }
Definition::Definition(ParserState pstate,
std::string n,
Parameters_Obj params,
Block_Obj b,
Type t)
: Has_Block(pstate, b),
name_(n),
parameters_(params),
environment_(0),
type_(t),
native_function_(0),
c_function_(0),
cookie_(0),
is_overload_stub_(false),
signature_(0)
{ }
Definition::Definition(ParserState pstate,
Signature sig,
std::string n,
Parameters_Obj params,
Native_Function func_ptr,
bool overload_stub)
: Has_Block(pstate, {}),
name_(n),
parameters_(params),
environment_(0),
type_(FUNCTION),
native_function_(func_ptr),
c_function_(0),
cookie_(0),
is_overload_stub_(overload_stub),
signature_(sig)
{ }
Definition::Definition(ParserState pstate,
Signature sig,
std::string n,
Parameters_Obj params,
Sass_Function_Entry c_func)
: Has_Block(pstate, {}),
name_(n),
parameters_(params),
environment_(0),
type_(FUNCTION),
native_function_(0),
c_function_(c_func),
cookie_(sass_function_get_cookie(c_func)),
is_overload_stub_(false),
signature_(sig)
{ }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Mixin_Call::Mixin_Call(ParserState pstate, std::string n, Arguments_Obj args, Parameters_Obj b_params, Block_Obj b)
: Has_Block(pstate, b), name_(n), arguments_(args), block_parameters_(b_params)
{ }
Mixin_Call::Mixin_Call(const Mixin_Call* ptr)
: Has_Block(ptr),
name_(ptr->name_),
arguments_(ptr->arguments_),
block_parameters_(ptr->block_parameters_)
{ }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Content::Content(ParserState pstate, Arguments_Obj args)
: Statement(pstate),
arguments_(args)
{ statement_type(CONTENT); }
Content::Content(const Content* ptr)
: Statement(ptr),
arguments_(ptr->arguments_)
{ statement_type(CONTENT); }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Expression::Expression(ParserState pstate, bool d, bool e, bool i, Type ct)
: AST_Node(pstate),
is_delayed_(d),
is_expanded_(e),
is_interpolant_(i),
concrete_type_(ct)
{ }
Expression::Expression(const Expression* ptr)
: AST_Node(ptr),
is_delayed_(ptr->is_delayed_),
is_expanded_(ptr->is_expanded_),
is_interpolant_(ptr->is_interpolant_),
concrete_type_(ptr->concrete_type_)
{ }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Unary_Expression::Unary_Expression(ParserState pstate, Type t, Expression_Obj o)
: Expression(pstate), optype_(t), operand_(o), hash_(0)
{ }
Unary_Expression::Unary_Expression(const Unary_Expression* ptr)
: Expression(ptr),
optype_(ptr->optype_),
operand_(ptr->operand_),
hash_(ptr->hash_)
{ }
const std::string Unary_Expression::type_name() {
switch (optype_) {
case PLUS: return "plus";
case MINUS: return "minus";
case SLASH: return "slash";
case NOT: return "not";
default: return "invalid";
}
}
bool Unary_Expression::operator==(const Expression& rhs) const
{
try
{
const Unary_Expression* m = Cast(&rhs);
if (m == 0) return false;
return type() == m->type() &&
*operand() == *m->operand();
}
catch (std::bad_cast&)
{
return false;
}
catch (...) { throw; }
}
size_t Unary_Expression::hash() const
{
if (hash_ == 0) {
hash_ = std::hash()(optype_);
hash_combine(hash_, operand()->hash());
};
return hash_;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Argument::Argument(ParserState pstate, Expression_Obj val, std::string n, bool rest, bool keyword)
: Expression(pstate), value_(val), name_(n), is_rest_argument_(rest), is_keyword_argument_(keyword), hash_(0)
{
if (!name_.empty() && is_rest_argument_) {
coreError("variable-length argument may not be passed by name", pstate_);
}
}
Argument::Argument(const Argument* ptr)
: Expression(ptr),
value_(ptr->value_),
name_(ptr->name_),
is_rest_argument_(ptr->is_rest_argument_),
is_keyword_argument_(ptr->is_keyword_argument_),
hash_(ptr->hash_)
{
if (!name_.empty() && is_rest_argument_) {
coreError("variable-length argument may not be passed by name", pstate_);
}
}
void Argument::set_delayed(bool delayed)
{
if (value_) value_->set_delayed(delayed);
is_delayed(delayed);
}
bool Argument::operator==(const Expression& rhs) const
{
try
{
const Argument* m = Cast(&rhs);
if (!(m && name() == m->name())) return false;
return *value() == *m->value();
}
catch (std::bad_cast&)
{
return false;
}
catch (...) { throw; }
}
size_t Argument::hash() const
{
if (hash_ == 0) {
hash_ = std::hash()(name());
hash_combine(hash_, value()->hash());
}
return hash_;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Arguments::Arguments(ParserState pstate)
: Expression(pstate),
Vectorized(),
has_named_arguments_(false),
has_rest_argument_(false),
has_keyword_argument_(false)
{ }
Arguments::Arguments(const Arguments* ptr)
: Expression(ptr),
Vectorized(*ptr),
has_named_arguments_(ptr->has_named_arguments_),
has_rest_argument_(ptr->has_rest_argument_),
has_keyword_argument_(ptr->has_keyword_argument_)
{ }
void Arguments::set_delayed(bool delayed)
{
for (Argument_Obj arg : elements()) {
if (arg) arg->set_delayed(delayed);
}
is_delayed(delayed);
}
Argument_Obj Arguments::get_rest_argument()
{
if (this->has_rest_argument()) {
for (Argument_Obj arg : this->elements()) {
if (arg->is_rest_argument()) {
return arg;
}
}
}
return {};
}
Argument_Obj Arguments::get_keyword_argument()
{
if (this->has_keyword_argument()) {
for (Argument_Obj arg : this->elements()) {
if (arg->is_keyword_argument()) {
return arg;
}
}
}
return {};
}
void Arguments::adjust_after_pushing(Argument_Obj a)
{
if (!a->name().empty()) {
if (has_keyword_argument()) {
coreError("named arguments must precede variable-length argument", a->pstate());
}
has_named_arguments(true);
}
else if (a->is_rest_argument()) {
if (has_rest_argument()) {
coreError("functions and mixins may only be called with one variable-length argument", a->pstate());
}
if (has_keyword_argument_) {
coreError("only keyword arguments may follow variable arguments", a->pstate());
}
has_rest_argument(true);
}
else if (a->is_keyword_argument()) {
if (has_keyword_argument()) {
coreError("functions and mixins may only be called with one keyword argument", a->pstate());
}
has_keyword_argument(true);
}
else {
if (has_rest_argument()) {
coreError("ordinal arguments must precede variable-length arguments", a->pstate());
}
if (has_named_arguments()) {
coreError("ordinal arguments must precede named arguments", a->pstate());
}
}
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Media_Query::Media_Query(ParserState pstate, String_Obj t, size_t s, bool n, bool r)
: Expression(pstate), Vectorized(s),
media_type_(t), is_negated_(n), is_restricted_(r)
{ }
Media_Query::Media_Query(const Media_Query* ptr)
: Expression(ptr),
Vectorized(*ptr),
media_type_(ptr->media_type_),
is_negated_(ptr->is_negated_),
is_restricted_(ptr->is_restricted_)
{ }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Media_Query_Expression::Media_Query_Expression(ParserState pstate,
Expression_Obj f, Expression_Obj v, bool i)
: Expression(pstate), feature_(f), value_(v), is_interpolated_(i)
{ }
Media_Query_Expression::Media_Query_Expression(const Media_Query_Expression* ptr)
: Expression(ptr),
feature_(ptr->feature_),
value_(ptr->value_),
is_interpolated_(ptr->is_interpolated_)
{ }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
At_Root_Query::At_Root_Query(ParserState pstate, Expression_Obj f, Expression_Obj v, bool i)
: Expression(pstate), feature_(f), value_(v)
{ }
At_Root_Query::At_Root_Query(const At_Root_Query* ptr)
: Expression(ptr),
feature_(ptr->feature_),
value_(ptr->value_)
{ }
bool At_Root_Query::exclude(std::string str)
{
bool with = feature() && unquote(feature()->to_string()).compare("with") == 0;
List* l = static_cast(value().ptr());
std::string v;
if (with)
{
if (!l || l->length() == 0) return str.compare("rule") != 0;
for (size_t i = 0, L = l->length(); i < L; ++i)
{
v = unquote((*l)[i]->to_string());
if (v.compare("all") == 0 || v == str) return false;
}
return true;
}
else
{
if (!l || !l->length()) return str.compare("rule") == 0;
for (size_t i = 0, L = l->length(); i < L; ++i)
{
v = unquote((*l)[i]->to_string());
if (v.compare("all") == 0 || v == str) return true;
}
return false;
}
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
At_Root_Block::At_Root_Block(ParserState pstate, Block_Obj b, At_Root_Query_Obj e)
: Has_Block(pstate, b), expression_(e)
{ statement_type(ATROOT); }
At_Root_Block::At_Root_Block(const At_Root_Block* ptr)
: Has_Block(ptr), expression_(ptr->expression_)
{ statement_type(ATROOT); }
bool At_Root_Block::bubbles() {
return true;
}
bool At_Root_Block::exclude_node(Statement_Obj s) {
if (expression() == nullptr)
{
return s->statement_type() == Statement::RULESET;
}
if (s->statement_type() == Statement::DIRECTIVE)
{
if (Directive_Obj dir = Cast(s))
{
std::string keyword(dir->keyword());
if (keyword.length() > 0) keyword.erase(0, 1);
return expression()->exclude(keyword);
}
}
if (s->statement_type() == Statement::MEDIA)
{
return expression()->exclude("media");
}
if (s->statement_type() == Statement::RULESET)
{
return expression()->exclude("rule");
}
if (s->statement_type() == Statement::SUPPORTS)
{
return expression()->exclude("supports");
}
if (Directive_Obj dir = Cast(s))
{
if (dir->is_keyframes()) return expression()->exclude("keyframes");
}
return false;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Parameter::Parameter(ParserState pstate, std::string n, Expression_Obj def, bool rest)
: AST_Node(pstate), name_(n), default_value_(def), is_rest_parameter_(rest)
{ }
Parameter::Parameter(const Parameter* ptr)
: AST_Node(ptr),
name_(ptr->name_),
default_value_(ptr->default_value_),
is_rest_parameter_(ptr->is_rest_parameter_)
{ }
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Parameters::Parameters(ParserState pstate)
: AST_Node(pstate),
Vectorized(),
has_optional_parameters_(false),
has_rest_parameter_(false)
{ }
Parameters::Parameters(const Parameters* ptr)
: AST_Node(ptr),
Vectorized(*ptr),
has_optional_parameters_(ptr->has_optional_parameters_),
has_rest_parameter_(ptr->has_rest_parameter_)
{ }
void Parameters::adjust_after_pushing(Parameter_Obj p)
{
if (p->default_value()) {
if (has_rest_parameter()) {
coreError("optional parameters may not be combined with variable-length parameters", p->pstate());
}
has_optional_parameters(true);
}
else if (p->is_rest_parameter()) {
if (has_rest_parameter()) {
coreError("functions and mixins cannot have more than one variable-length parameter", p->pstate());
}
has_rest_parameter(true);
}
else {
if (has_rest_parameter()) {
coreError("required parameters must precede variable-length parameters", p->pstate());
}
if (has_optional_parameters()) {
coreError("required parameters must precede optional parameters", p->pstate());
}
}
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// If you forget to add a class here you will get
// undefined reference to `vtable for Sass::Class'
IMPLEMENT_AST_OPERATORS(Ruleset);
IMPLEMENT_AST_OPERATORS(MediaRule);
IMPLEMENT_AST_OPERATORS(CssMediaRule);
IMPLEMENT_AST_OPERATORS(CssMediaQuery);
IMPLEMENT_AST_OPERATORS(Import);
IMPLEMENT_AST_OPERATORS(Import_Stub);
IMPLEMENT_AST_OPERATORS(Directive);
IMPLEMENT_AST_OPERATORS(At_Root_Block);
IMPLEMENT_AST_OPERATORS(While);
IMPLEMENT_AST_OPERATORS(Each);
IMPLEMENT_AST_OPERATORS(For);
IMPLEMENT_AST_OPERATORS(If);
IMPLEMENT_AST_OPERATORS(Mixin_Call);
IMPLEMENT_AST_OPERATORS(ExtendRule);
IMPLEMENT_AST_OPERATORS(Media_Query);
IMPLEMENT_AST_OPERATORS(Media_Query_Expression);
IMPLEMENT_AST_OPERATORS(Debug);
IMPLEMENT_AST_OPERATORS(Error);
IMPLEMENT_AST_OPERATORS(Warning);
IMPLEMENT_AST_OPERATORS(Assignment);
IMPLEMENT_AST_OPERATORS(Return);
IMPLEMENT_AST_OPERATORS(At_Root_Query);
IMPLEMENT_AST_OPERATORS(Comment);
IMPLEMENT_AST_OPERATORS(Parameters);
IMPLEMENT_AST_OPERATORS(Parameter);
IMPLEMENT_AST_OPERATORS(Arguments);
IMPLEMENT_AST_OPERATORS(Argument);
IMPLEMENT_AST_OPERATORS(Unary_Expression);
IMPLEMENT_AST_OPERATORS(Block);
IMPLEMENT_AST_OPERATORS(Content);
IMPLEMENT_AST_OPERATORS(Trace);
IMPLEMENT_AST_OPERATORS(Keyframe_Rule);
IMPLEMENT_AST_OPERATORS(Bubble);
IMPLEMENT_AST_OPERATORS(Definition);
IMPLEMENT_AST_OPERATORS(Declaration);
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
}
libsass-3.6.3/src/ast.hpp 0000664 0000000 0000000 00000107133 13557420656 0015274 0 ustar 00root root 0000000 0000000 #ifndef SASS_AST_H
#define SASS_AST_H
// sass.hpp must go before all system headers to get the
// __EXTENSIONS__ fix on Solaris.
#include "sass.hpp"
#include
#include
#include "sass/base.h"
#include "ast_helpers.hpp"
#include "ast_fwd_decl.hpp"
#include "ast_def_macros.hpp"
#include "file.hpp"
#include "position.hpp"
#include "operation.hpp"
#include "environment.hpp"
#include "fn_utils.hpp"
namespace Sass {
// ToDo: where does this fit best?
// We don't share this with C-API?
class Operand {
public:
Operand(Sass_OP operand, bool ws_before = false, bool ws_after = false)
: operand(operand), ws_before(ws_before), ws_after(ws_after)
{ }
public:
enum Sass_OP operand;
bool ws_before;
bool ws_after;
};
//////////////////////////////////////////////////////////
// `hash_combine` comes from boost (functional/hash):
// http://www.boost.org/doc/libs/1_35_0/doc/html/hash/combine.html
// Boost Software License - Version 1.0
// http://www.boost.org/users/license.html
template
void hash_combine (std::size_t& seed, const T& val)
{
seed ^= std::hash()(val) + 0x9e3779b9
+ (seed<<6) + (seed>>2);
}
//////////////////////////////////////////////////////////
const char* sass_op_to_name(enum Sass_OP op);
const char* sass_op_separator(enum Sass_OP op);
//////////////////////////////////////////////////////////
// Abstract base class for all abstract syntax tree nodes.
//////////////////////////////////////////////////////////
class AST_Node : public SharedObj {
ADD_PROPERTY(ParserState, pstate)
public:
AST_Node(ParserState pstate)
: pstate_(pstate)
{ }
AST_Node(const AST_Node* ptr)
: pstate_(ptr->pstate_)
{ }
// allow implicit conversion to string
// needed for by SharedPtr implementation
operator std::string() {
return to_string();
}
// AST_Node(AST_Node& ptr) = delete;
virtual ~AST_Node() = 0;
virtual size_t hash() const { return 0; }
virtual std::string inspect() const { return to_string({ INSPECT, 5 }); }
virtual std::string to_sass() const { return to_string({ TO_SASS, 5 }); }
virtual std::string to_string(Sass_Inspect_Options opt) const;
virtual std::string to_css(Sass_Inspect_Options opt) const;
virtual std::string to_string() const;
virtual void cloneChildren() {};
// generic find function (not fully implemented yet)
// ToDo: add specific implementions to all children
virtual bool find ( bool (*f)(AST_Node_Obj) ) { return f(this); };
void update_pstate(const ParserState& pstate);
Offset off() { return pstate(); }
Position pos() { return pstate(); }
// Some obects are not meant to be compared
// ToDo: maybe fallback to pointer comparison?
virtual bool operator== (const AST_Node& rhs) const {
throw std::runtime_error("operator== not implemented");
}
// We can give some reasonable implementations by using
// inverst operators on the specialized implementations
virtual bool operator!= (const AST_Node& rhs) const {
// Unequal if not equal
return !(*this == rhs);
}
ATTACH_ABSTRACT_AST_OPERATIONS(AST_Node);
ATTACH_ABSTRACT_CRTP_PERFORM_METHODS()
};
inline AST_Node::~AST_Node() { }
//////////////////////////////////////////////////////////////////////
// define cast template now (need complete type)
//////////////////////////////////////////////////////////////////////
template
T* Cast(AST_Node* ptr) {
return ptr && typeid(T) == typeid(*ptr) ?
static_cast(ptr) : NULL;
};
template
const T* Cast(const AST_Node* ptr) {
return ptr && typeid(T) == typeid(*ptr) ?
static_cast(ptr) : NULL;
};
//////////////////////////////////////////////////////////////////////
// Abstract base class for expressions. This side of the AST hierarchy
// represents elements in value contexts, which exist primarily to be
// evaluated and returned.
//////////////////////////////////////////////////////////////////////
class Expression : public AST_Node {
public:
enum Type {
NONE,
BOOLEAN,
NUMBER,
COLOR,
STRING,
LIST,
MAP,
SELECTOR,
NULL_VAL,
FUNCTION_VAL,
C_WARNING,
C_ERROR,
FUNCTION,
VARIABLE,
PARENT,
NUM_TYPES
};
private:
// expressions in some contexts shouldn't be evaluated
ADD_PROPERTY(bool, is_delayed)
ADD_PROPERTY(bool, is_expanded)
ADD_PROPERTY(bool, is_interpolant)
ADD_PROPERTY(Type, concrete_type)
public:
Expression(ParserState pstate, bool d = false, bool e = false, bool i = false, Type ct = NONE);
virtual operator bool() { return true; }
virtual ~Expression() { }
virtual bool is_invisible() const { return false; }
virtual std::string type() const { return ""; }
static std::string type_name() { return ""; }
virtual bool is_false() { return false; }
// virtual bool is_true() { return !is_false(); }
virtual bool operator< (const Expression& rhs) const { return false; }
virtual bool operator== (const Expression& rhs) const { return false; }
inline bool operator>(const Expression& rhs) const { return rhs < *this; }
inline bool operator!=(const Expression& rhs) const { return !(rhs == *this); }
virtual bool eq(const Expression& rhs) const { return *this == rhs; };
virtual void set_delayed(bool delayed) { is_delayed(delayed); }
virtual bool has_interpolant() const { return is_interpolant(); }
virtual bool is_left_interpolant() const { return is_interpolant(); }
virtual bool is_right_interpolant() const { return is_interpolant(); }
ATTACH_VIRTUAL_AST_OPERATIONS(Expression);
size_t hash() const override { return 0; }
};
}
/////////////////////////////////////////////////////////////////////////////////////
// Hash method specializations for std::unordered_map to work with Sass::Expression
/////////////////////////////////////////////////////////////////////////////////////
namespace std {
template<>
struct hash
{
size_t operator()(Sass::Expression_Obj s) const
{
return s->hash();
}
};
template<>
struct equal_to
{
bool operator()( Sass::Expression_Obj lhs, Sass::Expression_Obj rhs) const
{
return lhs->hash() == rhs->hash();
}
};
}
namespace Sass {
/////////////////////////////////////////////////////////////////////////////
// Mixin class for AST nodes that should behave like vectors. Uses the
// "Template Method" design pattern to allow subclasses to adjust their flags
// when certain objects are pushed.
/////////////////////////////////////////////////////////////////////////////
template
class Vectorized {
std::vector elements_;
protected:
mutable size_t hash_;
void reset_hash() { hash_ = 0; }
virtual void adjust_after_pushing(T element) { }
public:
Vectorized(size_t s = 0) : hash_(0)
{ elements_.reserve(s); }
Vectorized(std::vector vec) :
elements_(std::move(vec)),
hash_(0)
{}
virtual ~Vectorized() = 0;
size_t length() const { return elements_.size(); }
bool empty() const { return elements_.empty(); }
void clear() { return elements_.clear(); }
T& last() { return elements_.back(); }
T& first() { return elements_.front(); }
const T& last() const { return elements_.back(); }
const T& first() const { return elements_.front(); }
bool operator== (const Vectorized& rhs) const {
// Abort early if sizes do not match
if (length() != rhs.length()) return false;
// Otherwise test each node for object equalicy in order
return std::equal(begin(), end(), rhs.begin(), ObjEqualityFn);
}
bool operator!= (const Vectorized& rhs) const {
return !(*this == rhs);
}
T& operator[](size_t i) { return elements_[i]; }
virtual const T& at(size_t i) const { return elements_.at(i); }
virtual T& at(size_t i) { return elements_.at(i); }
const T& get(size_t i) const { return elements_[i]; }
const T& operator[](size_t i) const { return elements_[i]; }
// Implicitly get the std::vector from our object
// Makes the Vector directly assignable to std::vector
// You are responsible to make a copy if needed
// Note: since this returns the real object, we can't
// Note: guarantee that the hash will not get out of sync
operator std::vector&() { return elements_; }
operator const std::vector&() const { return elements_; }
// Explicitly request all elements as a real std::vector
// You are responsible to make a copy if needed
// Note: since this returns the real object, we can't
// Note: guarantee that the hash will not get out of sync
std::vector& elements() { return elements_; }
const std::vector& elements() const { return elements_; }
// Insert all items from compatible vector
void concat(const std::vector& v)
{
if (!v.empty()) reset_hash();
elements().insert(end(), v.begin(), v.end());
}
// Syntatic sugar for pointers
void concat(const Vectorized* v)
{
if (v != nullptr) {
return concat(*v);
}
}
// Insert one item on the front
void unshift(T element)
{
reset_hash();
elements_.insert(begin(), element);
}
// Remove and return item on the front
// ToDo: handle empty vectors
T shift() {
reset_hash();
T first = get(0);
elements_.erase(begin());
return first;
}
// Insert one item on the back
// ToDo: rename this to push
void append(T element)
{
reset_hash();
elements_.insert(end(), element);
// ToDo: Mostly used by parameters and arguments
// ToDo: Find a more elegant way to support this
adjust_after_pushing(element);
}
// Check if an item already exists
// Uses underlying object `operator==`
// E.g. compares the actual objects
bool contains(const T& el) const {
for (const T& rhs : elements_) {
// Test the underlying objects for equality
// A std::find checks for pointer equality
if (ObjEqualityFn(el, rhs)) {
return true;
}
}
return false;
}
// This might be better implemented as `operator=`?
void elements(std::vector e) {
reset_hash();
elements_ = std::move(e);
}
virtual size_t hash() const
{
if (hash_ == 0) {
for (const T& el : elements_) {
hash_combine(hash_, el->hash());
}
}
return hash_;
}
template
typename std::vector::iterator insert(P position, const V& val) {
reset_hash();
return elements_.insert(position, val);
}
typename std::vector::iterator end() { return elements_.end(); }
typename std::vector::iterator begin() { return elements_.begin(); }
typename std::vector::const_iterator end() const { return elements_.end(); }
typename std::vector::const_iterator begin() const { return elements_.begin(); }
typename std::vector::iterator erase(typename std::vector::iterator el) { reset_hash(); return elements_.erase(el); }
typename std::vector::const_iterator erase(typename std::vector::const_iterator el) { reset_hash(); return elements_.erase(el); }
};
template
inline Vectorized::~Vectorized() { }
/////////////////////////////////////////////////////////////////////////////
// Mixin class for AST nodes that should behave like a hash table. Uses an
// extra internally to maintain insertion order for interation.
/////////////////////////////////////////////////////////////////////////////
template
class Hashed {
private:
std::unordered_map<
K, T, ObjHash, ObjEquality
> elements_;
std::vector _keys;
std::vector _values;
protected:
mutable size_t hash_;
K duplicate_key_;
void reset_hash() { hash_ = 0; }
void reset_duplicate_key() { duplicate_key_ = {}; }
virtual void adjust_after_pushing(std::pair p) { }
public:
Hashed(size_t s = 0)
: elements_(),
_keys(),
_values(),
hash_(0), duplicate_key_({})
{
_keys.reserve(s);
_values.reserve(s);
elements_.reserve(s);
}
virtual ~Hashed();
size_t length() const { return _keys.size(); }
bool empty() const { return _keys.empty(); }
bool has(K k) const {
return elements_.find(k) != elements_.end();
}
T at(K k) const {
if (elements_.count(k))
{
return elements_.at(k);
}
else { return {}; }
}
bool has_duplicate_key() const { return duplicate_key_ != nullptr; }
K get_duplicate_key() const { return duplicate_key_; }
const std::unordered_map<
K, T, ObjHash, ObjEquality
>& elements() { return elements_; }
Hashed& operator<<(std::pair p)
{
reset_hash();
if (!has(p.first)) {
_keys.push_back(p.first);
_values.push_back(p.second);
}
else if (!duplicate_key_) {
duplicate_key_ = p.first;
}
elements_[p.first] = p.second;
adjust_after_pushing(p);
return *this;
}
Hashed& operator+=(Hashed* h)
{
if (length() == 0) {
this->elements_ = h->elements_;
this->_values = h->_values;
this->_keys = h->_keys;
return *this;
}
for (auto key : h->keys()) {
*this << std::make_pair(key, h->at(key));
}
reset_duplicate_key();
return *this;
}
const std::unordered_map<
K, T, ObjHash, ObjEquality
>& pairs() const { return elements_; }
const std::vector& keys() const { return _keys; }
const std::vector& values() const { return _values; }
// std::unordered_map::iterator end() { return elements_.end(); }
// std::unordered_map::iterator begin() { return elements_.begin(); }
// std::unordered_map::const_iterator end() const { return elements_.end(); }
// std::unordered_map::const_iterator begin() const { return elements_.begin(); }
};
template
inline Hashed::~Hashed() { }
/////////////////////////////////////////////////////////////////////////
// Abstract base class for statements. This side of the AST hierarchy
// represents elements in expansion contexts, which exist primarily to be
// rewritten and macro-expanded.
/////////////////////////////////////////////////////////////////////////
class Statement : public AST_Node {
public:
enum Type {
NONE,
RULESET,
MEDIA,
DIRECTIVE,
SUPPORTS,
ATROOT,
BUBBLE,
CONTENT,
KEYFRAMERULE,
DECLARATION,
ASSIGNMENT,
IMPORT_STUB,
IMPORT,
COMMENT,
WARNING,
RETURN,
EXTEND,
ERROR,
DEBUGSTMT,
WHILE,
EACH,
FOR,
IF
};
private:
ADD_PROPERTY(Type, statement_type)
ADD_PROPERTY(size_t, tabs)
ADD_PROPERTY(bool, group_end)
public:
Statement(ParserState pstate, Type st = NONE, size_t t = 0);
virtual ~Statement() = 0; // virtual destructor
// needed for rearranging nested rulesets during CSS emission
virtual bool bubbles();
virtual bool has_content();
virtual bool is_invisible() const;
ATTACH_VIRTUAL_AST_OPERATIONS(Statement)
};
inline Statement::~Statement() { }
////////////////////////
// Blocks of statements.
////////////////////////
class Block final : public Statement, public Vectorized {
ADD_PROPERTY(bool, is_root)
// needed for properly formatted CSS emission
protected:
void adjust_after_pushing(Statement_Obj s) override {}
public:
Block(ParserState pstate, size_t s = 0, bool r = false);
bool isInvisible() const;
bool has_content() override;
ATTACH_AST_OPERATIONS(Block)
ATTACH_CRTP_PERFORM_METHODS()
};
////////////////////////////////////////////////////////////////////////
// Abstract base class for statements that contain blocks of statements.
////////////////////////////////////////////////////////////////////////
class Has_Block : public Statement {
ADD_PROPERTY(Block_Obj, block)
public:
Has_Block(ParserState pstate, Block_Obj b);
Has_Block(const Has_Block* ptr); // copy constructor
virtual ~Has_Block() = 0; // virtual destructor
virtual bool has_content() override;
};
inline Has_Block::~Has_Block() { }
/////////////////////////////////////////////////////////////////////////////
// Rulesets (i.e., sets of styles headed by a selector and containing a block
// of style declarations.
/////////////////////////////////////////////////////////////////////////////
class Ruleset final : public Has_Block {
ADD_PROPERTY(SelectorListObj, selector)
ADD_PROPERTY(Selector_Schema_Obj, schema)
ADD_PROPERTY(bool, is_root);
public:
Ruleset(ParserState pstate, SelectorListObj s = {}, Block_Obj b = {});
bool is_invisible() const override;
ATTACH_AST_OPERATIONS(Ruleset)
ATTACH_CRTP_PERFORM_METHODS()
};
/////////////////
// Bubble.
/////////////////
class Bubble final : public Statement {
ADD_PROPERTY(Statement_Obj, node)
ADD_PROPERTY(bool, group_end)
public:
Bubble(ParserState pstate, Statement_Obj n, Statement_Obj g = {}, size_t t = 0);
bool bubbles() override;
ATTACH_AST_OPERATIONS(Bubble)
ATTACH_CRTP_PERFORM_METHODS()
};
/////////////////
// Trace.
/////////////////
class Trace final : public Has_Block {
ADD_CONSTREF(char, type)
ADD_CONSTREF(std::string, name)
public:
Trace(ParserState pstate, std::string n, Block_Obj b = {}, char type = 'm');
ATTACH_AST_OPERATIONS(Trace)
ATTACH_CRTP_PERFORM_METHODS()
};
///////////////////////////////////////////////////////////////////////
// At-rules -- arbitrary directives beginning with "@" that may have an
// optional statement block.
///////////////////////////////////////////////////////////////////////
class Directive final : public Has_Block {
ADD_CONSTREF(std::string, keyword)
ADD_PROPERTY(SelectorListObj, selector)
ADD_PROPERTY(Expression_Obj, value)
public:
Directive(ParserState pstate, std::string kwd, SelectorListObj sel = {}, Block_Obj b = {}, Expression_Obj val = {});
bool bubbles() override;
bool is_media();
bool is_keyframes();
ATTACH_AST_OPERATIONS(Directive)
ATTACH_CRTP_PERFORM_METHODS()
};
///////////////////////////////////////////////////////////////////////
// Keyframe-rules -- the child blocks of "@keyframes" nodes.
///////////////////////////////////////////////////////////////////////
class Keyframe_Rule final : public Has_Block {
// according to css spec, this should be
// = |
ADD_PROPERTY(SelectorListObj, name)
public:
Keyframe_Rule(ParserState pstate, Block_Obj b);
ATTACH_AST_OPERATIONS(Keyframe_Rule)
ATTACH_CRTP_PERFORM_METHODS()
};
////////////////////////////////////////////////////////////////////////
// Declarations -- style rules consisting of a property name and values.
////////////////////////////////////////////////////////////////////////
class Declaration final : public Has_Block {
ADD_PROPERTY(String_Obj, property)
ADD_PROPERTY(Expression_Obj, value)
ADD_PROPERTY(bool, is_important)
ADD_PROPERTY(bool, is_custom_property)
ADD_PROPERTY(bool, is_indented)
public:
Declaration(ParserState pstate, String_Obj prop, Expression_Obj val, bool i = false, bool c = false, Block_Obj b = {});
bool is_invisible() const override;
ATTACH_AST_OPERATIONS(Declaration)
ATTACH_CRTP_PERFORM_METHODS()
};
/////////////////////////////////////
// Assignments -- variable and value.
/////////////////////////////////////
class Assignment final : public Statement {
ADD_CONSTREF(std::string, variable)
ADD_PROPERTY(Expression_Obj, value)
ADD_PROPERTY(bool, is_default)
ADD_PROPERTY(bool, is_global)
public:
Assignment(ParserState pstate, std::string var, Expression_Obj val, bool is_default = false, bool is_global = false);
ATTACH_AST_OPERATIONS(Assignment)
ATTACH_CRTP_PERFORM_METHODS()
};
////////////////////////////////////////////////////////////////////////////
// Import directives. CSS and Sass import lists can be intermingled, so it's
// necessary to store a list of each in an Import node.
////////////////////////////////////////////////////////////////////////////
class Import final : public Statement {
std::vector urls_;
std::vector incs_;
ADD_PROPERTY(List_Obj, import_queries);
public:
Import(ParserState pstate);
std::vector& incs();
std::vector& urls();
ATTACH_AST_OPERATIONS(Import)
ATTACH_CRTP_PERFORM_METHODS()
};
// not yet resolved single import
// so far we only know requested name
class Import_Stub final : public Statement {
Include resource_;
public:
Import_Stub(ParserState pstate, Include res);
Include resource();
std::string imp_path();
std::string abs_path();
ATTACH_AST_OPERATIONS(Import_Stub)
ATTACH_CRTP_PERFORM_METHODS()
};
//////////////////////////////
// The Sass `@warn` directive.
//////////////////////////////
class Warning final : public Statement {
ADD_PROPERTY(Expression_Obj, message)
public:
Warning(ParserState pstate, Expression_Obj msg);
ATTACH_AST_OPERATIONS(Warning)
ATTACH_CRTP_PERFORM_METHODS()
};
///////////////////////////////
// The Sass `@error` directive.
///////////////////////////////
class Error final : public Statement {
ADD_PROPERTY(Expression_Obj, message)
public:
Error(ParserState pstate, Expression_Obj msg);
ATTACH_AST_OPERATIONS(Error)
ATTACH_CRTP_PERFORM_METHODS()
};
///////////////////////////////
// The Sass `@debug` directive.
///////////////////////////////
class Debug final : public Statement {
ADD_PROPERTY(Expression_Obj, value)
public:
Debug(ParserState pstate, Expression_Obj val);
ATTACH_AST_OPERATIONS(Debug)
ATTACH_CRTP_PERFORM_METHODS()
};
///////////////////////////////////////////
// CSS comments. These may be interpolated.
///////////////////////////////////////////
class Comment final : public Statement {
ADD_PROPERTY(String_Obj, text)
ADD_PROPERTY(bool, is_important)
public:
Comment(ParserState pstate, String_Obj txt, bool is_important);
virtual bool is_invisible() const override;
ATTACH_AST_OPERATIONS(Comment)
ATTACH_CRTP_PERFORM_METHODS()
};
////////////////////////////////////
// The Sass `@if` control directive.
////////////////////////////////////
class If final : public Has_Block {
ADD_PROPERTY(Expression_Obj, predicate)
ADD_PROPERTY(Block_Obj, alternative)
public:
If(ParserState pstate, Expression_Obj pred, Block_Obj con, Block_Obj alt = {});
virtual bool has_content() override;
ATTACH_AST_OPERATIONS(If)
ATTACH_CRTP_PERFORM_METHODS()
};
/////////////////////////////////////
// The Sass `@for` control directive.
/////////////////////////////////////
class For final : public Has_Block {
ADD_CONSTREF(std::string, variable)
ADD_PROPERTY(Expression_Obj, lower_bound)
ADD_PROPERTY(Expression_Obj, upper_bound)
ADD_PROPERTY(bool, is_inclusive)
public:
For(ParserState pstate, std::string var, Expression_Obj lo, Expression_Obj hi, Block_Obj b, bool inc);
ATTACH_AST_OPERATIONS(For)
ATTACH_CRTP_PERFORM_METHODS()
};
//////////////////////////////////////
// The Sass `@each` control directive.
//////////////////////////////////////
class Each final : public Has_Block {
ADD_PROPERTY(std::vector, variables)
ADD_PROPERTY(Expression_Obj, list)
public:
Each(ParserState pstate, std::vector vars, Expression_Obj lst, Block_Obj b);
ATTACH_AST_OPERATIONS(Each)
ATTACH_CRTP_PERFORM_METHODS()
};
///////////////////////////////////////
// The Sass `@while` control directive.
///////////////////////////////////////
class While final : public Has_Block {
ADD_PROPERTY(Expression_Obj, predicate)
public:
While(ParserState pstate, Expression_Obj pred, Block_Obj b);
ATTACH_AST_OPERATIONS(While)
ATTACH_CRTP_PERFORM_METHODS()
};
/////////////////////////////////////////////////////////////
// The @return directive for use inside SassScript functions.
/////////////////////////////////////////////////////////////
class Return final : public Statement {
ADD_PROPERTY(Expression_Obj, value)
public:
Return(ParserState pstate, Expression_Obj val);
ATTACH_AST_OPERATIONS(Return)
ATTACH_CRTP_PERFORM_METHODS()
};
/////////////////////////////////////////////////////////////////////////////
// Definitions for both mixins and functions. The two cases are distinguished
// by a type tag.
/////////////////////////////////////////////////////////////////////////////
class Definition final : public Has_Block {
public:
enum Type { MIXIN, FUNCTION };
ADD_CONSTREF(std::string, name)
ADD_PROPERTY(Parameters_Obj, parameters)
ADD_PROPERTY(Env*, environment)
ADD_PROPERTY(Type, type)
ADD_PROPERTY(Native_Function, native_function)
ADD_PROPERTY(Sass_Function_Entry, c_function)
ADD_PROPERTY(void*, cookie)
ADD_PROPERTY(bool, is_overload_stub)
ADD_PROPERTY(Signature, signature)
public:
Definition(ParserState pstate,
std::string n,
Parameters_Obj params,
Block_Obj b,
Type t);
Definition(ParserState pstate,
Signature sig,
std::string n,
Parameters_Obj params,
Native_Function func_ptr,
bool overload_stub = false);
Definition(ParserState pstate,
Signature sig,
std::string n,
Parameters_Obj params,
Sass_Function_Entry c_func);
ATTACH_AST_OPERATIONS(Definition)
ATTACH_CRTP_PERFORM_METHODS()
};
//////////////////////////////////////
// Mixin calls (i.e., `@include ...`).
//////////////////////////////////////
class Mixin_Call final : public Has_Block {
ADD_CONSTREF(std::string, name)
ADD_PROPERTY(Arguments_Obj, arguments)
ADD_PROPERTY(Parameters_Obj, block_parameters)
public:
Mixin_Call(ParserState pstate, std::string n, Arguments_Obj args, Parameters_Obj b_params = {}, Block_Obj b = {});
ATTACH_AST_OPERATIONS(Mixin_Call)
ATTACH_CRTP_PERFORM_METHODS()
};
///////////////////////////////////////////////////
// The @content directive for mixin content blocks.
///////////////////////////////////////////////////
class Content final : public Statement {
ADD_PROPERTY(Arguments_Obj, arguments)
public:
Content(ParserState pstate, Arguments_Obj args);
ATTACH_AST_OPERATIONS(Content)
ATTACH_CRTP_PERFORM_METHODS()
};
////////////////////////////////////////////////////////////////////////////
// Arithmetic negation (logical negation is just an ordinary function call).
////////////////////////////////////////////////////////////////////////////
class Unary_Expression final : public Expression {
public:
enum Type { PLUS, MINUS, NOT, SLASH };
private:
HASH_PROPERTY(Type, optype)
HASH_PROPERTY(Expression_Obj, operand)
mutable size_t hash_;
public:
Unary_Expression(ParserState pstate, Type t, Expression_Obj o);
const std::string type_name();
virtual bool operator==(const Expression& rhs) const override;
size_t hash() const override;
ATTACH_AST_OPERATIONS(Unary_Expression)
ATTACH_CRTP_PERFORM_METHODS()
};
////////////////////////////////////////////////////////////
// Individual argument objects for mixin and function calls.
////////////////////////////////////////////////////////////
class Argument final : public Expression {
HASH_PROPERTY(Expression_Obj, value)
HASH_CONSTREF(std::string, name)
ADD_PROPERTY(bool, is_rest_argument)
ADD_PROPERTY(bool, is_keyword_argument)
mutable size_t hash_;
public:
Argument(ParserState pstate, Expression_Obj val, std::string n = "", bool rest = false, bool keyword = false);
void set_delayed(bool delayed) override;
bool operator==(const Expression& rhs) const override;
size_t hash() const override;
ATTACH_AST_OPERATIONS(Argument)
ATTACH_CRTP_PERFORM_METHODS()
};
////////////////////////////////////////////////////////////////////////
// Argument lists -- in their own class to facilitate context-sensitive
// error checking (e.g., ensuring that all ordinal arguments precede all
// named arguments).
////////////////////////////////////////////////////////////////////////
class Arguments final : public Expression, public Vectorized {
ADD_PROPERTY(bool, has_named_arguments)
ADD_PROPERTY(bool, has_rest_argument)
ADD_PROPERTY(bool, has_keyword_argument)
protected:
void adjust_after_pushing(Argument_Obj a) override;
public:
Arguments(ParserState pstate);
void set_delayed(bool delayed) override;
Argument_Obj get_rest_argument();
Argument_Obj get_keyword_argument();
ATTACH_AST_OPERATIONS(Arguments)
ATTACH_CRTP_PERFORM_METHODS()
};
// A Media Ruleset before it has been evaluated
// Could be already final or an interpolation
class MediaRule final : public Has_Block {
ADD_PROPERTY(List_Obj, schema)
public:
MediaRule(ParserState pstate, Block_Obj block = {});
bool bubbles() override { return true; };
bool is_invisible() const override { return false; };
ATTACH_AST_OPERATIONS(MediaRule)
ATTACH_CRTP_PERFORM_METHODS()
};
// A Media Ruleset after it has been evaluated
// Representing the static or resulting css
class CssMediaRule final : public Has_Block,
public Vectorized {
public:
CssMediaRule(ParserState pstate, Block_Obj b);
bool bubbles() override { return true; };
bool isInvisible() const { return empty(); }
bool is_invisible() const override { return false; };
public:
// Hash and equality implemtation from vector
size_t hash() const override { return Vectorized::hash(); }
// Check if two instances are considered equal
bool operator== (const CssMediaRule& rhs) const {
return Vectorized::operator== (rhs);
}
bool operator!=(const CssMediaRule& rhs) const {
// Invert from equality
return !(*this == rhs);
}
ATTACH_AST_OPERATIONS(CssMediaRule)
ATTACH_CRTP_PERFORM_METHODS()
};
// Media Queries after they have been evaluated
// Representing the static or resulting css
class CssMediaQuery final : public AST_Node {
// The modifier, probably either "not" or "only".
// This may be `null` if no modifier is in use.
ADD_PROPERTY(std::string, modifier);
// The media type, for example "screen" or "print".
// This may be `null`. If so, [features] will not be empty.
ADD_PROPERTY(std::string, type);
// Feature queries, including parentheses.
ADD_PROPERTY(std::vector, features);
public:
CssMediaQuery(ParserState pstate);
// Check if two instances are considered equal
bool operator== (const CssMediaQuery& rhs) const;
bool operator!=(const CssMediaQuery& rhs) const {
// Invert from equality
return !(*this == rhs);
}
// Returns true if this query is empty
// Meaning it has no type and features
bool empty() const {
return type_.empty()
&& modifier_.empty()
&& features_.empty();
}
// Whether this media query matches all media types.
bool matchesAllTypes() const {
return type_.empty() || Util::equalsLiteral("all", type_);
}
// Merges this with [other] and adds a query that matches the intersection
// of both inputs to [result]. Returns false if the result is unrepresentable
CssMediaQuery_Obj merge(CssMediaQuery_Obj& other);
ATTACH_AST_OPERATIONS(CssMediaQuery)
ATTACH_CRTP_PERFORM_METHODS()
};
////////////////////////////////////////////////////
// Media queries (replaced by MediaRule at al).
// ToDo: only used for interpolation case
////////////////////////////////////////////////////
class Media_Query final : public Expression,
public Vectorized {
ADD_PROPERTY(String_Obj, media_type)
ADD_PROPERTY(bool, is_negated)
ADD_PROPERTY(bool, is_restricted)
public:
Media_Query(ParserState pstate, String_Obj t = {}, size_t s = 0, bool n = false, bool r = false);
ATTACH_AST_OPERATIONS(Media_Query)
ATTACH_CRTP_PERFORM_METHODS()
};
////////////////////////////////////////////////////
// Media expressions (for use inside media queries).
// ToDo: only used for interpolation case
////////////////////////////////////////////////////
class Media_Query_Expression final : public Expression {
ADD_PROPERTY(Expression_Obj, feature)
ADD_PROPERTY(Expression_Obj, value)
ADD_PROPERTY(bool, is_interpolated)
public:
Media_Query_Expression(ParserState pstate, Expression_Obj f, Expression_Obj v, bool i = false);
ATTACH_AST_OPERATIONS(Media_Query_Expression)
ATTACH_CRTP_PERFORM_METHODS()
};
/////////////////////////////////////////////////
// At root expressions (for use inside @at-root).
/////////////////////////////////////////////////
class At_Root_Query final : public Expression {
private:
ADD_PROPERTY(Expression_Obj, feature)
ADD_PROPERTY(Expression_Obj, value)
public:
At_Root_Query(ParserState pstate, Expression_Obj f = {}, Expression_Obj v = {}, bool i = false);
bool exclude(std::string str);
ATTACH_AST_OPERATIONS(At_Root_Query)
ATTACH_CRTP_PERFORM_METHODS()
};
///////////
// At-root.
///////////
class At_Root_Block final : public Has_Block {
ADD_PROPERTY(At_Root_Query_Obj, expression)
public:
At_Root_Block(ParserState pstate, Block_Obj b = {}, At_Root_Query_Obj e = {});
bool bubbles() override;
bool exclude_node(Statement_Obj s);
ATTACH_AST_OPERATIONS(At_Root_Block)
ATTACH_CRTP_PERFORM_METHODS()
};
/////////////////////////////////////////////////////////
// Individual parameter objects for mixins and functions.
/////////////////////////////////////////////////////////
class Parameter final : public AST_Node {
ADD_CONSTREF(std::string, name)
ADD_PROPERTY(Expression_Obj, default_value)
ADD_PROPERTY(bool, is_rest_parameter)
public:
Parameter(ParserState pstate, std::string n, Expression_Obj def = {}, bool rest = false);
ATTACH_AST_OPERATIONS(Parameter)
ATTACH_CRTP_PERFORM_METHODS()
};
/////////////////////////////////////////////////////////////////////////
// Parameter lists -- in their own class to facilitate context-sensitive
// error checking (e.g., ensuring that all optional parameters follow all
// required parameters).
/////////////////////////////////////////////////////////////////////////
class Parameters final : public AST_Node, public Vectorized {
ADD_PROPERTY(bool, has_optional_parameters)
ADD_PROPERTY(bool, has_rest_parameter)
protected:
void adjust_after_pushing(Parameter_Obj p) override;
public:
Parameters(ParserState pstate);
ATTACH_AST_OPERATIONS(Parameters)
ATTACH_CRTP_PERFORM_METHODS()
};
}
#include "ast_values.hpp"
#include "ast_supports.hpp"
#include "ast_selectors.hpp"
#ifdef __clang__
// #pragma clang diagnostic pop
// #pragma clang diagnostic push
#endif
#endif
libsass-3.6.3/src/ast2c.cpp 0000664 0000000 0000000 00000004305 13557420656 0015511 0 ustar 00root root 0000000 0000000 // sass.hpp must go before all system headers to get the
// __EXTENSIONS__ fix on Solaris.
#include "sass.hpp"
#include "ast2c.hpp"
#include "ast.hpp"
namespace Sass {
union Sass_Value* AST2C::operator()(Boolean* b)
{ return sass_make_boolean(b->value()); }
union Sass_Value* AST2C::operator()(Number* n)
{ return sass_make_number(n->value(), n->unit().c_str()); }
union Sass_Value* AST2C::operator()(Custom_Warning* w)
{ return sass_make_warning(w->message().c_str()); }
union Sass_Value* AST2C::operator()(Custom_Error* e)
{ return sass_make_error(e->message().c_str()); }
union Sass_Value* AST2C::operator()(Color_RGBA* c)
{ return sass_make_color(c->r(), c->g(), c->b(), c->a()); }
union Sass_Value* AST2C::operator()(Color_HSLA* c)
{
Color_RGBA_Obj rgba = c->copyAsRGBA();
return operator()(rgba.ptr());
}
union Sass_Value* AST2C::operator()(String_Constant* s)
{
if (s->quote_mark()) {
return sass_make_qstring(s->value().c_str());
} else {
return sass_make_string(s->value().c_str());
}
}
union Sass_Value* AST2C::operator()(String_Quoted* s)
{ return sass_make_qstring(s->value().c_str()); }
union Sass_Value* AST2C::operator()(List* l)
{
union Sass_Value* v = sass_make_list(l->length(), l->separator(), l->is_bracketed());
for (size_t i = 0, L = l->length(); i < L; ++i) {
sass_list_set_value(v, i, (*l)[i]->perform(this));
}
return v;
}
union Sass_Value* AST2C::operator()(Map* m)
{
union Sass_Value* v = sass_make_map(m->length());
int i = 0;
for (auto key : m->keys()) {
sass_map_set_key(v, i, key->perform(this));
sass_map_set_value(v, i, m->at(key)->perform(this));
i++;
}
return v;
}
union Sass_Value* AST2C::operator()(Arguments* a)
{
union Sass_Value* v = sass_make_list(a->length(), SASS_COMMA, false);
for (size_t i = 0, L = a->length(); i < L; ++i) {
sass_list_set_value(v, i, (*a)[i]->perform(this));
}
return v;
}
union Sass_Value* AST2C::operator()(Argument* a)
{ return a->value()->perform(this); }
// not strictly necessary because of the fallback
union Sass_Value* AST2C::operator()(Null* n)
{ return sass_make_null(); }
};
libsass-3.6.3/src/ast2c.hpp 0000664 0000000 0000000 00000001772 13557420656 0015523 0 ustar 00root root 0000000 0000000 #ifndef SASS_AST2C_H
#define SASS_AST2C_H
#include "ast_fwd_decl.hpp"
#include "operation.hpp"
#include "sass/values.h"
namespace Sass {
class AST2C : public Operation_CRTP {
public:
AST2C() { }
~AST2C() { }
union Sass_Value* operator()(Boolean*);
union Sass_Value* operator()(Number*);
union Sass_Value* operator()(Color_RGBA*);
union Sass_Value* operator()(Color_HSLA*);
union Sass_Value* operator()(String_Constant*);
union Sass_Value* operator()(String_Quoted*);
union Sass_Value* operator()(Custom_Warning*);
union Sass_Value* operator()(Custom_Error*);
union Sass_Value* operator()(List*);
union Sass_Value* operator()(Map*);
union Sass_Value* operator()(Null*);
union Sass_Value* operator()(Arguments*);
union Sass_Value* operator()(Argument*);
// return sass error if type is not supported
union Sass_Value* fallback(AST_Node* x)
{ return sass_make_error("unknown type for C-API"); }
};
}
#endif
libsass-3.6.3/src/ast_def_macros.hpp 0000664 0000000 0000000 00000007254 13557420656 0017461 0 ustar 00root root 0000000 0000000 #ifndef SASS_AST_DEF_MACROS_H
#define SASS_AST_DEF_MACROS_H
// Helper class to switch a flag and revert once we go out of scope
template
class LocalOption {
private:
T* var; // pointer to original variable
T orig; // copy of the original option
public:
LocalOption(T& var)
{
this->var = &var;
this->orig = var;
}
LocalOption(T& var, T orig)
{
this->var = &var;
this->orig = var;
*(this->var) = orig;
}
void reset()
{
*(this->var) = this->orig;
}
~LocalOption() {
*(this->var) = this->orig;
}
};
#define LOCAL_FLAG(name,opt) LocalOption flag_##name(name, opt)
#define LOCAL_COUNT(name,opt) LocalOption cnt_##name(name, opt)
#define NESTING_GUARD(name) \
LocalOption cnt_##name(name, name + 1); \
if (name > MAX_NESTING) throw Exception::NestingLimitError(pstate, traces); \
#define ADD_PROPERTY(type, name)\
protected:\
type name##_;\
public:\
type name() const { return name##_; }\
type name(type name##__) { return name##_ = name##__; }\
private:
#define HASH_PROPERTY(type, name)\
protected:\
type name##_;\
public:\
type name() const { return name##_; }\
type name(type name##__) { hash_ = 0; return name##_ = name##__; }\
private:
#define ADD_CONSTREF(type, name) \
protected: \
type name##_; \
public: \
const type& name() const { return name##_; } \
void name(type name##__) { name##_ = name##__; } \
private:
#define HASH_CONSTREF(type, name) \
protected: \
type name##_; \
public: \
const type& name() const { return name##_; } \
void name(type name##__) { hash_ = 0; name##_ = name##__; } \
private:
#ifdef DEBUG_SHARED_PTR
#define ATTACH_ABSTRACT_AST_OPERATIONS(klass) \
virtual klass* copy(std::string, size_t) const = 0; \
virtual klass* clone(std::string, size_t) const = 0; \
#define ATTACH_VIRTUAL_AST_OPERATIONS(klass) \
klass(const klass* ptr); \
virtual klass* copy(std::string, size_t) const override = 0; \
virtual klass* clone(std::string, size_t) const override = 0; \
#define ATTACH_AST_OPERATIONS(klass) \
klass(const klass* ptr); \
virtual klass* copy(std::string, size_t) const override; \
virtual klass* clone(std::string, size_t) const override; \
#else
#define ATTACH_ABSTRACT_AST_OPERATIONS(klass) \
virtual klass* copy() const = 0; \
virtual klass* clone() const = 0; \
#define ATTACH_VIRTUAL_AST_OPERATIONS(klass) \
klass(const klass* ptr); \
virtual klass* copy() const override = 0; \
virtual klass* clone() const override = 0; \
#define ATTACH_AST_OPERATIONS(klass) \
klass(const klass* ptr); \
virtual klass* copy() const override; \
virtual klass* clone() const override; \
#endif
#define ATTACH_VIRTUAL_CMP_OPERATIONS(klass) \
virtual bool operator==(const klass& rhs) const = 0; \
virtual bool operator!=(const klass& rhs) const { return !(*this == rhs); }; \
#define ATTACH_CMP_OPERATIONS(klass) \
virtual bool operator==(const klass& rhs) const; \
virtual bool operator!=(const klass& rhs) const { return !(*this == rhs); }; \
#ifdef DEBUG_SHARED_PTR
#define IMPLEMENT_AST_OPERATORS(klass) \
klass* klass::copy(std::string file, size_t line) const { \
klass* cpy = new klass(this); \
cpy->trace(file, line); \
return cpy; \
} \
klass* klass::clone(std::string file, size_t line) const { \
klass* cpy = copy(file, line); \
cpy->cloneChildren(); \
return cpy; \
} \
#else
#define IMPLEMENT_AST_OPERATORS(klass) \
klass* klass::copy() const { \
return new klass(this); \
} \
klass* klass::clone() const { \
klass* cpy = copy(); \
cpy->cloneChildren(); \
return cpy; \
} \
#endif
#endif
libsass-3.6.3/src/ast_fwd_decl.cpp 0000664 0000000 0000000 00000001351 13557420656 0017111 0 ustar 00root root 0000000 0000000 #include "ast.hpp"
namespace Sass {
#define IMPLEMENT_BASE_CAST(T) \
template<> \
T* Cast(AST_Node* ptr) { \
return dynamic_cast(ptr); \
}; \
\
template<> \
const T* Cast(const AST_Node* ptr) { \
return dynamic_cast(ptr); \
}; \
IMPLEMENT_BASE_CAST(AST_Node)
IMPLEMENT_BASE_CAST(Expression)
IMPLEMENT_BASE_CAST(Statement)
IMPLEMENT_BASE_CAST(Has_Block)
IMPLEMENT_BASE_CAST(PreValue)
IMPLEMENT_BASE_CAST(Value)
IMPLEMENT_BASE_CAST(Color)
IMPLEMENT_BASE_CAST(List)
IMPLEMENT_BASE_CAST(String)
IMPLEMENT_BASE_CAST(String_Constant)
IMPLEMENT_BASE_CAST(Supports_Condition)
IMPLEMENT_BASE_CAST(Selector)
IMPLEMENT_BASE_CAST(SelectorComponent)
IMPLEMENT_BASE_CAST(SimpleSelector)
}
libsass-3.6.3/src/ast_fwd_decl.hpp 0000664 0000000 0000000 00000014600 13557420656 0017117 0 ustar 00root root 0000000 0000000 #ifndef SASS_AST_FWD_DECL_H
#define SASS_AST_FWD_DECL_H
// sass.hpp must go before all system headers to get the
// __EXTENSIONS__ fix on Solaris.
#include "sass.hpp"
#include "sass/functions.h"
#include "memory/SharedPtr.hpp"
/////////////////////////////////////////////
// Forward declarations for the AST visitors.
/////////////////////////////////////////////
namespace Sass {
class AST_Node;
class Has_Block;
class SimpleSelector;
class Parent_Reference;
class PreValue;
class Block;
class Expression;
class Statement;
class Value;
class Declaration;
class Ruleset;
class Bubble;
class Trace;
class MediaRule;
class CssMediaRule;
class CssMediaQuery;
class Supports_Block;
class Directive;
class Keyframe_Rule;
class At_Root_Block;
class Assignment;
class Import;
class Import_Stub;
class Warning;
class Error;
class Debug;
class Comment;
class If;
class For;
class Each;
class While;
class Return;
class Content;
class ExtendRule;
class Definition;
class List;
class Map;
class Function;
class Mixin_Call;
class Binary_Expression;
class Unary_Expression;
class Function_Call;
class Custom_Warning;
class Custom_Error;
class Variable;
class Number;
class Color;
class Color_RGBA;
class Color_HSLA;
class Boolean;
class String;
class Null;
class String_Schema;
class String_Constant;
class String_Quoted;
class Media_Query;
class Media_Query_Expression;
class Supports_Condition;
class Supports_Operator;
class Supports_Negation;
class Supports_Declaration;
class Supports_Interpolation;
class At_Root_Query;
class Parameter;
class Parameters;
class Argument;
class Arguments;
class Selector;
class Selector_Schema;
class Placeholder_Selector;
class Type_Selector;
class Class_Selector;
class Id_Selector;
class Attribute_Selector;
class Pseudo_Selector;
class SelectorComponent;
class SelectorCombinator;
class CompoundSelector;
class ComplexSelector;
class SelectorList;
// common classes
class Context;
class Expand;
class Eval;
class Extension;
// declare classes that are instances of memory nodes
// Note: also add a mapping without underscore
// ToDo: move to camelCase vars in the future
#define IMPL_MEM_OBJ(type) \
typedef SharedImpl type##Obj; \
typedef SharedImpl type##_Obj; \
IMPL_MEM_OBJ(AST_Node);
IMPL_MEM_OBJ(Statement);
IMPL_MEM_OBJ(Block);
IMPL_MEM_OBJ(Ruleset);
IMPL_MEM_OBJ(Bubble);
IMPL_MEM_OBJ(Trace);
IMPL_MEM_OBJ(MediaRule);
IMPL_MEM_OBJ(CssMediaRule);
IMPL_MEM_OBJ(CssMediaQuery);
IMPL_MEM_OBJ(Supports_Block);
IMPL_MEM_OBJ(Directive);
IMPL_MEM_OBJ(Keyframe_Rule);
IMPL_MEM_OBJ(At_Root_Block);
IMPL_MEM_OBJ(Declaration);
IMPL_MEM_OBJ(Assignment);
IMPL_MEM_OBJ(Import);
IMPL_MEM_OBJ(Import_Stub);
IMPL_MEM_OBJ(Warning);
IMPL_MEM_OBJ(Error);
IMPL_MEM_OBJ(Debug);
IMPL_MEM_OBJ(Comment);
IMPL_MEM_OBJ(PreValue);
IMPL_MEM_OBJ(Has_Block);
IMPL_MEM_OBJ(If);
IMPL_MEM_OBJ(For);
IMPL_MEM_OBJ(Each);
IMPL_MEM_OBJ(While);
IMPL_MEM_OBJ(Return);
IMPL_MEM_OBJ(Content);
IMPL_MEM_OBJ(ExtendRule);
IMPL_MEM_OBJ(Definition);
IMPL_MEM_OBJ(Mixin_Call);
IMPL_MEM_OBJ(Value);
IMPL_MEM_OBJ(Expression);
IMPL_MEM_OBJ(List);
IMPL_MEM_OBJ(Map);
IMPL_MEM_OBJ(Function);
IMPL_MEM_OBJ(Binary_Expression);
IMPL_MEM_OBJ(Unary_Expression);
IMPL_MEM_OBJ(Function_Call);
IMPL_MEM_OBJ(Custom_Warning);
IMPL_MEM_OBJ(Custom_Error);
IMPL_MEM_OBJ(Variable);
IMPL_MEM_OBJ(Number);
IMPL_MEM_OBJ(Color);
IMPL_MEM_OBJ(Color_RGBA);
IMPL_MEM_OBJ(Color_HSLA);
IMPL_MEM_OBJ(Boolean);
IMPL_MEM_OBJ(String_Schema);
IMPL_MEM_OBJ(String);
IMPL_MEM_OBJ(String_Constant);
IMPL_MEM_OBJ(String_Quoted);
IMPL_MEM_OBJ(Media_Query);
IMPL_MEM_OBJ(Media_Query_Expression);
IMPL_MEM_OBJ(Supports_Condition);
IMPL_MEM_OBJ(Supports_Operator);
IMPL_MEM_OBJ(Supports_Negation);
IMPL_MEM_OBJ(Supports_Declaration);
IMPL_MEM_OBJ(Supports_Interpolation);
IMPL_MEM_OBJ(At_Root_Query);
IMPL_MEM_OBJ(Null);
IMPL_MEM_OBJ(Parent_Reference);
IMPL_MEM_OBJ(Parameter);
IMPL_MEM_OBJ(Parameters);
IMPL_MEM_OBJ(Argument);
IMPL_MEM_OBJ(Arguments);
IMPL_MEM_OBJ(Selector);
IMPL_MEM_OBJ(Selector_Schema);
IMPL_MEM_OBJ(SimpleSelector);
IMPL_MEM_OBJ(Placeholder_Selector);
IMPL_MEM_OBJ(Type_Selector);
IMPL_MEM_OBJ(Class_Selector);
IMPL_MEM_OBJ(Id_Selector);
IMPL_MEM_OBJ(Attribute_Selector);
IMPL_MEM_OBJ(Pseudo_Selector);
IMPL_MEM_OBJ(SelectorComponent);
IMPL_MEM_OBJ(SelectorCombinator);
IMPL_MEM_OBJ(CompoundSelector);
IMPL_MEM_OBJ(ComplexSelector);
IMPL_MEM_OBJ(SelectorList);
// ###########################################################################
// some often used typedefs
// ###########################################################################
typedef std::vector BlockStack;
typedef std::vector CalleeStack;
typedef std::vector CallStack;
typedef std::vector MediaStack;
typedef std::vector SelectorStack;
typedef std::vector ImporterStack;
// only to switch implementations for testing
#define environment_map std::map
// ###########################################################################
// explicit type conversion functions
// ###########################################################################
template
T* Cast(AST_Node* ptr);
template
const T* Cast(const AST_Node* ptr);
// sometimes you know the class you want to cast to is final
// in this case a simple typeid check is faster and safe to use
#define DECLARE_BASE_CAST(T) \
template<> T* Cast(AST_Node* ptr); \
template<> const T* Cast(const AST_Node* ptr); \
// ###########################################################################
// implement specialization for final classes
// ###########################################################################
DECLARE_BASE_CAST(AST_Node)
DECLARE_BASE_CAST(Expression)
DECLARE_BASE_CAST(Statement)
DECLARE_BASE_CAST(Has_Block)
DECLARE_BASE_CAST(PreValue)
DECLARE_BASE_CAST(Value)
DECLARE_BASE_CAST(List)
DECLARE_BASE_CAST(Color)
DECLARE_BASE_CAST(String)
DECLARE_BASE_CAST(String_Constant)
DECLARE_BASE_CAST(Supports_Condition)
DECLARE_BASE_CAST(Selector)
DECLARE_BASE_CAST(SimpleSelector)
DECLARE_BASE_CAST(SelectorComponent)
}
#endif
libsass-3.6.3/src/ast_helpers.hpp 0000664 0000000 0000000 00000022203 13557420656 0017010 0 ustar 00root root 0000000 0000000 #ifndef SASS_AST_HELPERS_H
#define SASS_AST_HELPERS_H
// sass.hpp must go before all system headers to get the
// __EXTENSIONS__ fix on Solaris.
#include "sass.hpp"
#include
#include
#include "util_string.hpp"
namespace Sass {
// ###########################################################################
// ###########################################################################
// easier to search with name
const bool DELAYED = true;
// ToDo: should this really be hardcoded
// Note: most methods follow precision option
const double NUMBER_EPSILON = 1e-12;
// macro to test if numbers are equal within a small error margin
#define NEAR_EQUAL(lhs, rhs) std::fabs(lhs - rhs) < NUMBER_EPSILON
// ###########################################################################
// We define various functions and functors here.
// Functions satisfy the BinaryPredicate requirement
// Functors are structs used for e.g. unordered_map
// ###########################################################################
// ###########################################################################
// Implement compare and hashing operations for raw pointers
// ###########################################################################
template
size_t PtrHashFn(const T* ptr) {
return std::hash()((size_t)ptr);
}
struct PtrHash {
template
size_t operator() (const T* ptr) const {
return PtrHashFn(ptr);
}
};
template
bool PtrEqualityFn(const T* lhs, const T* rhs) {
return lhs == rhs; // compare raw pointers
}
struct PtrEquality {
template
bool operator() (const T* lhs, const T* rhs) const {
return PtrEqualityFn(lhs, rhs);
}
};
// ###########################################################################
// Implement compare and hashing operations for AST Nodes
// ###########################################################################
// TODO: get rid of funtions and use ObjEquality
template
// Hash the raw pointer instead of object
size_t ObjPtrHashFn(const T& obj) {
return PtrHashFn(obj.ptr());
}
struct ObjPtrHash {
template
// Hash the raw pointer instead of object
size_t operator() (const T& obj) const {
return ObjPtrHashFn(obj);
}
};
template
// Hash the object and its content
size_t ObjHashFn(const T& obj) {
return obj ? obj->hash() : 0;
}
struct ObjHash {
template
// Hash the object and its content
size_t operator() (const T& obj) const {
return ObjHashFn(obj);
}
};
template
// Hash the object behind pointer
size_t PtrObjHashFn(const T* obj) {
return obj ? obj->hash() : 0;
}
struct PtrObjHash {
template
// Hash the object behind pointer
size_t operator() (const T* obj) const {
return PtrObjHashFn(obj);
}
};
template
// Compare raw pointers to the object
bool ObjPtrEqualityFn(const T& lhs, const T& rhs) {
return PtrEqualityFn(lhs.ptr(), rhs.ptr());
}
struct ObjPtrEquality {
template
// Compare raw pointers to the object
bool operator() (const T& lhs, const T& rhs) const {
return ObjPtrEqualityFn(lhs, rhs);
}
};
template
// Compare the objects behind the pointers
bool PtrObjEqualityFn(const T* lhs, const T* rhs) {
if (lhs == nullptr) return rhs == nullptr;
else if (rhs == nullptr) return false;
else return *lhs == *rhs;
}
struct PtrObjEquality {
template
// Compare the objects behind the pointers
bool operator() (const T* lhs, const T* rhs) const {
return PtrObjEqualityFn(lhs, rhs);
}
};
template
// Compare the objects and its contents
bool ObjEqualityFn(const T& lhs, const T& rhs) {
return PtrObjEqualityFn(lhs.ptr(), rhs.ptr());
}
struct ObjEquality {
template
// Compare the objects and its contents
bool operator() (const T& lhs, const T& rhs) const {
return ObjEqualityFn(lhs, rhs);
}
};
// ###########################################################################
// Implement ordering operations for AST Nodes
// ###########################################################################
template
// Compare the objects behind pointers
bool PtrObjLessThanFn(const T* lhs, const T* rhs) {
if (lhs == nullptr) return rhs != nullptr;
else if (rhs == nullptr) return false;
else return *lhs < *rhs;
}
struct PtrObjLessThan {
template
// Compare the objects behind pointers
bool operator() (const T* lhs, const T* rhs) const {
return PtrObjLessThanFn(lhs, rhs);
}
};
template
// Compare the objects and its content
bool ObjLessThanFn(const T& lhs, const T& rhs) {
return PtrObjLessThanFn(lhs.ptr(), rhs.ptr());
};
struct ObjLessThan {
template
// Compare the objects and its content
bool operator() (const T& lhs, const T& rhs) const {
return ObjLessThanFn(lhs, rhs);
}
};
// ###########################################################################
// Some STL helper functions
// ###########################################################################
// Check if all elements are equal
template
bool ListEquality(const X& lhs, const Y& rhs,
bool(*cmp)(const XT*, const YT*))
{
return lhs.size() == rhs.size() &&
std::equal(lhs.begin(), lhs.end(),
rhs.begin(), cmp);
}
// Return if Vector is empty
template
bool listIsEmpty(T* cnt) {
return cnt && cnt->empty();
}
// Erase items from vector that match predicate
template
void listEraseItemIf(T& vec, UnaryPredicate* predicate)
{
vec.erase(std::remove_if(vec.begin(), vec.end(), predicate), vec.end());
}
// Check that every item in `lhs` is also in `rhs`
// Note: this works by comparing the raw pointers
template
bool listIsSubsetOrEqual(const T& lhs, const T& rhs) {
for (const auto& item : lhs) {
if (std::find(rhs.begin(), rhs.end(), item) == rhs.end())
return false;
}
return true;
}
// ##########################################################################
// Returns whether [name] is the name of a pseudo-element
// that can be written with pseudo-class syntax (CSS2 vs CSS3):
// `:before`, `:after`, `:first-line`, or `:first-letter`
// ##########################################################################
inline bool isFakePseudoElement(const std::string& name)
{
return Util::equalsLiteral("after", name)
|| Util::equalsLiteral("before", name)
|| Util::equalsLiteral("first-line", name)
|| Util::equalsLiteral("first-letter", name);
}
// ##########################################################################
// Names of pseudo selectors that take selectors as arguments,
// and that are subselectors of their arguments.
// For example, `.foo` is a superselector of `:matches(.foo)`.
// ##########################################################################
inline bool isSubselectorPseudo(const std::string& norm)
{
return Util::equalsLiteral("any", norm)
|| Util::equalsLiteral("matches", norm)
|| Util::equalsLiteral("nth-child", norm)
|| Util::equalsLiteral("nth-last-child", norm);
}
// EO isSubselectorPseudo
// ###########################################################################
// Pseudo-class selectors that take unadorned selectors as arguments.
// ###########################################################################
inline bool isSelectorPseudoClass(const std::string& test)
{
return Util::equalsLiteral("not", test)
|| Util::equalsLiteral("matches", test)
|| Util::equalsLiteral("current", test)
|| Util::equalsLiteral("any", test)
|| Util::equalsLiteral("has", test)
|| Util::equalsLiteral("host", test)
|| Util::equalsLiteral("host-context", test);
}
// EO isSelectorPseudoClass
// ###########################################################################
// Pseudo-element selectors that take unadorned selectors as arguments.
// ###########################################################################
inline bool isSelectorPseudoElement(const std::string& test)
{
return Util::equalsLiteral("slotted", test);
}
// EO isSelectorPseudoElement
// ###########################################################################
// Pseudo-element selectors that has binominals
// ###########################################################################
inline bool isSelectorPseudoBinominal(const std::string& test)
{
return Util::equalsLiteral("nth-child", test)
|| Util::equalsLiteral("nth-last-child", test);
}
// isSelectorPseudoBinominal
// ###########################################################################
// ###########################################################################
}
#endif
libsass-3.6.3/src/ast_sel_cmp.cpp 0000664 0000000 0000000 00000032630 13557420656 0016770 0 ustar 00root root 0000000 0000000 // sass.hpp must go before all system headers to get the
// __EXTENSIONS__ fix on Solaris.
#include "sass.hpp"
#include "ast_selectors.hpp"
namespace Sass {
/*#########################################################################*/
// Compare against base class on right hand side
// try to find the most specialized implementation
/*#########################################################################*/
// Selector lists can be compared to comma lists
bool SelectorList::operator== (const Expression& rhs) const
{
if (auto l = Cast(&rhs)) { return *this == *l; }
if (auto s = Cast(&rhs)) { return *this == *s; }
if (Cast(&rhs) || Cast(&rhs)) { return false; }
throw std::runtime_error("invalid selector base classes to compare");
}
// Selector lists can be compared to comma lists
bool SelectorList::operator== (const Selector& rhs) const
{
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto list = Cast(&rhs)) { return *this == *list; }
throw std::runtime_error("invalid selector base classes to compare");
}
bool ComplexSelector::operator== (const Selector& rhs) const
{
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *sel == *this; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
throw std::runtime_error("invalid selector base classes to compare");
}
bool SelectorCombinator::operator== (const Selector& rhs) const
{
if (auto cpx = Cast(&rhs)) { return *this == *cpx; }
return false;
}
bool CompoundSelector::operator== (const Selector& rhs) const
{
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
throw std::runtime_error("invalid selector base classes to compare");
}
bool SimpleSelector::operator== (const Selector& rhs) const
{
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) { return *this == *sel; }
if (auto sel = Cast(&rhs)) return *this == *sel;
throw std::runtime_error("invalid selector base classes to compare");
}
/*#########################################################################*/
/*#########################################################################*/
bool SelectorList::operator== (const SelectorList& rhs) const
{
if (&rhs == this) return true;
if (rhs.length() != length()) return false;
std::unordered_set lhs_set;
lhs_set.reserve(length());
for (const ComplexSelectorObj& element : elements()) {
lhs_set.insert(element.ptr());
}
for (const ComplexSelectorObj& element : rhs.elements()) {
if (lhs_set.find(element.ptr()) == lhs_set.end()) return false;
}
return true;
}
/*#########################################################################*/
// Compare SelectorList against all other selector types
/*#########################################################################*/
bool SelectorList::operator== (const ComplexSelector& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (length() != 1) return false;
// Compare simple selectors
return *get(0) == rhs;
}
bool SelectorList::operator== (const CompoundSelector& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (length() != 1) return false;
// Compare simple selectors
return *get(0) == rhs;
}
bool SelectorList::operator== (const SimpleSelector& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (length() != 1) return false;
// Compare simple selectors
return *get(0) == rhs;
}
/*#########################################################################*/
// Compare ComplexSelector against itself
/*#########################################################################*/
bool ComplexSelector::operator== (const ComplexSelector& rhs) const
{
size_t len = length();
size_t rlen = rhs.length();
if (len != rlen) return false;
for (size_t i = 0; i < len; i += 1) {
if (*get(i) != *rhs.get(i)) return false;
}
return true;
}
/*#########################################################################*/
// Compare ComplexSelector against all other selector types
/*#########################################################################*/
bool ComplexSelector::operator== (const SelectorList& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (rhs.length() != 1) return false;
// Compare complex selector
return *this == *rhs.get(0);
}
bool ComplexSelector::operator== (const CompoundSelector& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (length() != 1) return false;
// Compare compound selector
return *get(0) == rhs;
}
bool ComplexSelector::operator== (const SimpleSelector& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (length() != 1) return false;
// Compare simple selectors
return *get(0) == rhs;
}
/*#########################################################################*/
// Compare SelectorCombinator against itself
/*#########################################################################*/
bool SelectorCombinator::operator==(const SelectorCombinator& rhs) const
{
return combinator() == rhs.combinator();
}
/*#########################################################################*/
// Compare SelectorCombinator against SelectorComponent
/*#########################################################################*/
bool SelectorCombinator::operator==(const SelectorComponent& rhs) const
{
if (const SelectorCombinator * sel = rhs.getCombinator()) {
return *this == *sel;
}
return false;
}
bool CompoundSelector::operator==(const SelectorComponent& rhs) const
{
if (const CompoundSelector * sel = rhs.getCompound()) {
return *this == *sel;
}
return false;
}
/*#########################################################################*/
// Compare CompoundSelector against itself
/*#########################################################################*/
// ToDo: Verifiy implementation
/*#########################################################################*/
bool CompoundSelector::operator== (const CompoundSelector& rhs) const
{
// std::cerr << "comp vs comp\n";
if (&rhs == this) return true;
if (rhs.length() != length()) return false;
std::unordered_set lhs_set;
lhs_set.reserve(length());
for (const SimpleSelectorObj& element : elements()) {
lhs_set.insert(element.ptr());
}
// there is no break?!
for (const SimpleSelectorObj& element : rhs.elements()) {
if (lhs_set.find(element.ptr()) == lhs_set.end()) return false;
}
return true;
}
/*#########################################################################*/
// Compare CompoundSelector against all other selector types
/*#########################################################################*/
bool CompoundSelector::operator== (const SelectorList& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (rhs.length() != 1) return false;
// Compare complex selector
return *this == *rhs.get(0);
}
bool CompoundSelector::operator== (const ComplexSelector& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (rhs.length() != 1) return false;
// Compare compound selector
return *this == *rhs.get(0);
}
bool CompoundSelector::operator== (const SimpleSelector& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return false;
// Must have exactly one item
size_t rlen = length();
if (rlen > 1) return false;
if (rlen == 0) return true;
// Compare simple selectors
return *get(0) < rhs;
}
/*#########################################################################*/
// Compare SimpleSelector against itself (upcast from abstract base)
/*#########################################################################*/
// DOES NOT EXIST FOR ABSTRACT BASE CLASS
/*#########################################################################*/
// Compare SimpleSelector against all other selector types
/*#########################################################################*/
bool SimpleSelector::operator== (const SelectorList& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (rhs.length() != 1) return false;
// Compare complex selector
return *this == *rhs.get(0);
}
bool SimpleSelector::operator== (const ComplexSelector& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return true;
// Must have exactly one item
if (rhs.length() != 1) return false;
// Compare compound selector
return *this == *rhs.get(0);
}
bool SimpleSelector::operator== (const CompoundSelector& rhs) const
{
// If both are empty they are equal
if (empty() && rhs.empty()) return false;
// Must have exactly one item
if (rhs.length() != 1) return false;
// Compare simple selector
return *this == *rhs.get(0);
}
/*#########################################################################*/
/*#########################################################################*/
bool Id_Selector::operator== (const SimpleSelector& rhs) const
{
auto sel = Cast(&rhs);
return sel ? *this == *sel : false;
}
bool Type_Selector::operator== (const SimpleSelector& rhs) const
{
auto sel = Cast(&rhs);
return sel ? *this == *sel : false;
}
bool Class_Selector::operator== (const SimpleSelector& rhs) const
{
auto sel = Cast(&rhs);
return sel ? *this == *sel : false;
}
bool Pseudo_Selector::operator== (const SimpleSelector& rhs) const
{
auto sel = Cast(&rhs);
return sel ? *this == *sel : false;
}
bool Attribute_Selector::operator== (const SimpleSelector& rhs) const
{
auto sel = Cast(&rhs);
return sel ? *this == *sel : false;
}
bool Placeholder_Selector::operator== (const SimpleSelector& rhs) const
{
auto sel = Cast(&rhs);
return sel ? *this == *sel : false;
}
/*#########################################################################*/
/*#########################################################################*/
bool Id_Selector::operator== (const Id_Selector& rhs) const
{
// ID has no namespacing
return name() == rhs.name();
}
bool Type_Selector::operator== (const Type_Selector& rhs) const
{
return is_ns_eq(rhs) && name() == rhs.name();
}
bool Class_Selector::operator== (const Class_Selector& rhs) const
{
// Class has no namespacing
return name() == rhs.name();
}
bool Placeholder_Selector::operator== (const Placeholder_Selector& rhs) const
{
// Placeholder has no namespacing
return name() == rhs.name();
}
bool Attribute_Selector::operator== (const Attribute_Selector& rhs) const
{
// smaller return, equal go on, bigger abort
if (is_ns_eq(rhs)) {
if (name() != rhs.name()) return false;
if (matcher() != rhs.matcher()) return false;
if (modifier() != rhs.modifier()) return false;
const String* lhs_val = value();
const String* rhs_val = rhs.value();
return PtrObjEquality()(lhs_val, rhs_val);
}
else { return false; }
}
bool Pseudo_Selector::operator== (const Pseudo_Selector& rhs) const
{
if (is_ns_eq(rhs)) {
if (name() != rhs.name()) return false;
if (isElement() != rhs.isElement()) return false;
const String* lhs_arg = argument();
const String* rhs_arg = rhs.argument();
if (!PtrObjEquality()(lhs_arg, rhs_arg)) return false;
const SelectorList* lhs_sel = selector();
const SelectorList* rhs_sel = rhs.selector();
return PtrObjEquality()(lhs_sel, rhs_sel);
}
else { return false; }
}
/*#########################################################################*/
/*#########################################################################*/
}
libsass-3.6.3/src/ast_sel_super.cpp 0000664 0000000 0000000 00000052456 13557420656 0017357 0 ustar 00root root 0000000 0000000 // sass.hpp must go before all system headers to get the
// __EXTENSIONS__ fix on Solaris.
#include "sass.hpp"
#include "ast.hpp"
#include "util_string.hpp"
namespace Sass {
// ##########################################################################
// To compare/debug against libsass you can use debugger.hpp:
// c++: std::cerr << "result " << debug_vec(compound) << "\n";
// dart: stderr.writeln("result " + compound.toString());
// ##########################################################################
// ##########################################################################
// Returns whether [list1] is a superselector of [list2].
// That is, whether [list1] matches every element that
// [list2] matches, as well as possibly additional elements.
// ##########################################################################
bool listIsSuperslector(
const std::vector& list1,
const std::vector& list2);
// ##########################################################################
// Returns whether [complex1] is a superselector of [complex2].
// That is, whether [complex1] matches every element that
// [complex2] matches, as well as possibly additional elements.
// ##########################################################################
bool complexIsSuperselector(
const std::vector& complex1,
const std::vector& complex2);
// ##########################################################################
// Returns all pseudo selectors in [compound] that have
// a selector argument, and that have the given [name].
// ##########################################################################
std::vector selectorPseudoNamed(
CompoundSelectorObj compound, std::string name)
{
std::vector rv;
for (SimpleSelectorObj sel : compound->elements()) {
if (Pseudo_Selector_Obj pseudo = Cast(sel)) {
if (pseudo->isClass() && pseudo->selector()) {
if (sel->name() == name) {
rv.push_back(sel);
}
}
}
}
return rv;
}
// EO selectorPseudoNamed
// ##########################################################################
// Returns whether [simple1] is a superselector of [simple2].
// That is, whether [simple1] matches every element that
// [simple2] matches, as well as possibly additional elements.
// ##########################################################################
bool simpleIsSuperselector(
const SimpleSelectorObj& simple1,
const SimpleSelectorObj& simple2)
{
// If they are equal they are superselectors
if (ObjEqualityFn(simple1, simple2)) {
return true;
}
// Some selector pseudoclasses can match normal selectors.
if (const Pseudo_Selector* pseudo = Cast(simple2)) {
if (pseudo->selector() && isSubselectorPseudo(pseudo->normalized())) {
for (auto complex : pseudo->selector()->elements()) {
// Make sure we have exacly one items
if (complex->length() != 1) {
return false;
}
// That items must be a compound selector
if (auto compound = Cast(complex->at(0))) {
// It must contain the lhs simple selector
if (!compound->contains(simple1)) {
return false;
}
}
}
return true;
}
}
return false;
}
// EO simpleIsSuperselector
// ##########################################################################
// Returns whether [simple] is a superselector of [compound].
// That is, whether [simple] matches every element that
// [compound] matches, as well as possibly additional elements.
// ##########################################################################
bool simpleIsSuperselectorOfCompound(
const SimpleSelectorObj& simple,
const CompoundSelectorObj& compound)
{
for (SimpleSelectorObj simple2 : compound->elements()) {
if (simpleIsSuperselector(simple, simple2)) {
return true;
}
}
return false;
}
// EO simpleIsSuperselectorOfCompound
// ##########################################################################
// ##########################################################################
bool typeIsSuperselectorOfCompound(
const Type_Selector_Obj& type,
const CompoundSelectorObj& compound)
{
for (const SimpleSelectorObj& simple : compound->elements()) {
if (const Type_Selector_Obj& rhs = Cast