GithubHelp home page GithubHelp logo

bioduds / css-grammar-p6 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from css-raku/css-grammar-raku

0.0 2.0 0.0 829 KB

Perl 6 core CSS grammars

License: Artistic License 2.0

Perl 6 66.03% CSS 33.97%

css-grammar-p6's Introduction

perl6-CSS-Grammar

CSS::Grammar is under construction as an experimental set of Perl 6 grammars for the W3C family of CSS standards.

It aims to implement a reasonable portion of the base grammars with an emphasis on:

  • support for CSS1, CSS2.1 and CSS3
  • forward compatibility rules, scanning and error recovery

This module performs generic parsing of declarations in style-sheet rules.

Contents

Base Grammars

  • CSS::Grammar::CSS1 - CSS 1.0 compatible grammar
  • CSS::Grammar::CSS21 - CSS 2.1 compatible grammar
  • CSS::Grammar::CSS3 - CSS 3.0 (core) compatible grammar

The CSS 3.0 core grammar, CSS::Grammar::CSS3, is based on CSS2.1; it understands:

  • #hex and rgb(...) colors; but not rgba(..), hsl(...), hsla(...) or named colors
  • basic @media at-rules; but not advanced media queries, resolutions or embedded @page rules.
  • basic @page page description rules
  • basic css3 level selectors

Parser Actions

CSS::Grammar::Actions can be used with in conjunction with any of the CSS1 CSS21 or CSS3 base grammars. It produces an abstract syntax tree (AST), plus warnings for any unexpected input.

use v6;
use CSS::Grammar::CSS3;
use CSS::Grammar::Actions;

my $css = 'H1 { color: blue; gunk }';

my $actions =  CSS::Grammar::Actions.new;
my $p = CSS::Grammar::CSS3.parse($css, :actions($actions));
.note for $actions.warnings;
say "H1: " ~ $p.ast<stylesheet>[0]<ruleset><selectors>;
# output:
# dropping term: gunk
# H1: selector    simple-selector qname   element-name    h1

Actions Options

  • :lax Pass back, don't drop, quantities with unknown dimensions.

Installation (Rakudo Star)

You'll first need to download and build Rakudo Star 2015.07 or better (http://rakudo.org/downloads/star/ - don't forget the final make install):

Ensure that perl6 and panda are available on your path, e.g. :

% export PATH=~/src/rakudo-star-2015.07/install/bin:$PATH

You can then use panda to test and install CSS::Grammar:

% panda install CSS::Grammar

To try parsing some content:

% perl6 -MCSS::Grammar::CSS3 -e"say CSS::Grammar::CSS3.parse('H1 {color:blue}')"

See Also

  • CSS::Module::CSS3::Selectors extends CSS::Grammar::CSS3 to fully implement CSS Level 3 Selectors.
  • CSS::Module further extends CSS::Grammar levels 1, 2.1 and 3. It understands named colors and is able to perform property-specific parsing and validation.
  • CSS::Drafts further extends CSS::Module, adding support for further draft CSS Level 3 extension modules.
  • CSS::Writer - AST reserializer
  • CSSGrammar.pm from perl6-examples gives an introductory Perl 6 grammar for CSS 2.1.

References

This module been built from the W3C CSS Specifications. In particular:

css-grammar-p6's People

Contributors

dwarring avatar szabgab avatar moritz avatar

Watchers

James Cloos avatar Eduardo Capanema avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.