GithubHelp home page GithubHelp logo

cisen / t2csspareser-flex-bison Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bentleyblanks/t2csspareser

0.0 0.0 0.0 232 KB

使用Flex+Bison完成CSS词法分析与语法分析工作,具体BNF范式实现是参考W3C中CSS2.0标准实现(实现了部分CSS3.0)。

Yacc 39.46% Lex 22.82% Makefile 2.65% CSS 1.26% C++ 33.81%

t2csspareser-flex-bison's Introduction

t2CSSPareser

使用Flex+Bison完成CSS词法分析与语法分析工作,具体BNF是参考W3C中CSS2.0标准实现(实现了部分CSS3.0)。

感谢tang3w给出了使用Flex+Lemon的简易CSS解析器实现,以及其推荐的可视化AST的实现方法。

依赖项说明

1.Flex 2.5.35

2.Bison 2.4.1

(Windows版本可以使用MinGW,OSX为自带)

3.Graphviz(可选),用于可视化生成AST树

构建说明

1.自带Makefile,自带demo.css无需其他平台依赖项

2.不使用g++ 而使用Visual Studio编译时可能会遇到unistd.h无法找到的问题,目前的解决方案可以是直接在VS的include目录下添加

具体操作可以参见在VC下如何使用头文件unistd.h

使用说明

1.目前支持CSS2.0大部分特性,正如demo.css中显示的

2.所有数值不带单位,例如

/* 已知错误 */
font-size: 80;
/* font-size: 80px; */

此处一旦数值带有单位将会发生不可预测错误

3.AST基本数据类型已经在t2CSSNode.hpp中显示,其中可视化AST可以调用printAsDot()方法。

4.目前语法错误无法检测具体错误类型,只能显示Error: syntax error.

5.目前规则不能为空,例如

/* Syntax error */
hello.a{}

6.目前最后一个选择器后建议不加空格

/* Unsupported */
.haha {}

/* supported */
.haha{}

原因是生成的AST会认为.haha之后还有一个selector(紧跟的空格引起),因此外部需要额外的解析工作来消除这一影响,但不影响正常解析。

在t2CSSParser中会被认为有语法错误,目前的解决办法是手工直接删除空规则,等待版本。

7.不支持类function的写法,如color: rgba(...);

可视化AST

此为给出的demo.css生成的AST具体样式 AST

关于作者

int 官某某 = "Bingo";

char[] 个人博客 = "http://bentleyblanks.github.io";

t2csspareser-flex-bison's People

Contributors

bentleyblanks 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.