zephir开发的扩展“wudimei框架”之模板词法扫描(三)完成代码切分

{% if
user_name == "YangQing-rong‘s username" || user_name == ‘admin‘ %}
 {{10*20.043123+8*times}}
{% endif %}

以上是待切分的模板view/test1.html。

以下是lexer.php,用来测试切分效果的。

<?php

use Wudimei\View\Lexer;

$viewName = ‘view/test1.html‘;
$c = file_get_contents(__DIR__.‘/‘ . $viewName );

$l =new Lexer();
$dt = $l->scan($viewName , $c );
print_r( $dt );

切分是1.先按{%%}和{{}}切分成文本块和代码块,2.然后再对代码块进行切分,主要切分的有 数字,运算符,字符串,名称。

以下是切分后的输出。有tokens元素的是代码块。

Array
(
    [0] => Wudimei\View\Token Object
        (
            [line:protected] => 1
            [column:protected] => 0
            [position:protected] => 0
            [content:protected] => {%
            [length:protected] => 2
            [tokenValue:protected] => 1
            [tokens:protected] => Array
                (
                )

        )

    [1] => Wudimei\View\Token Object
        (
            [line:protected] => 1
            [column:protected] => 2
            [position:protected] => 2
            [content:protected] =>  if
user_name == "YangQing-rong‘s username" || user_name == ‘admin‘
            [length:protected] => 69
            [tokenValue:protected] => 7
            [tokens:protected] => Array
                (
                    [0] => Wudimei\View\Token Object
                        (
                            [line:protected] => 1
                            [column:protected] => 3
                            [position:protected] => 2
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [1] => Wudimei\View\Token Object
                        (
                            [line:protected] => 1
                            [column:protected] => 4
                            [position:protected] => 3
                            [content:protected] => if
                            [length:protected] => 2
                            [tokenValue:protected] => 15
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [2] => Wudimei\View\Token Object
                        (
                            [line:protected] => 1
                            [column:protected] => 6
                            [position:protected] => 5
                            [content:protected] =>  

                            [length:protected] => 2
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [3] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 1
                            [position:protected] => 7
                            [content:protected] => user_name
                            [length:protected] => 9
                            [tokenValue:protected] => 15
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [4] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 10
                            [position:protected] => 16
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [5] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 11
                            [position:protected] => 17
                            [content:protected] => ==
                            [length:protected] => 2
                            [tokenValue:protected] => 13
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [6] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 13
                            [position:protected] => 19
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [7] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 14
                            [position:protected] => 20
                            [content:protected] => "YangQing-rong‘s username"
                            [length:protected] => 26
                            [tokenValue:protected] => 13
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [8] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 40
                            [position:protected] => 46
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [9] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 41
                            [position:protected] => 47
                            [content:protected] => ||
                            [length:protected] => 2
                            [tokenValue:protected] => 13
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [10] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 43
                            [position:protected] => 49
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [11] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 44
                            [position:protected] => 50
                            [content:protected] => user_name
                            [length:protected] => 9
                            [tokenValue:protected] => 15
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [12] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 53
                            [position:protected] => 59
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [13] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 54
                            [position:protected] => 60
                            [content:protected] => ==
                            [length:protected] => 2
                            [tokenValue:protected] => 13
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [14] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 56
                            [position:protected] => 62
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [15] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 57
                            [position:protected] => 63
                            [content:protected] => ‘admin‘
                            [length:protected] => 7
                            [tokenValue:protected] => 13
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [16] => Wudimei\View\Token Object
                        (
                            [line:protected] => 2
                            [column:protected] => 64
                            [position:protected] => 70
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                )

        )

    [2] => Wudimei\View\Token Object
        (
            [line:protected] => 2
            [column:protected] => 65
            [position:protected] => 71
            [content:protected] => %}
            [length:protected] => 2
            [tokenValue:protected] => 2
            [tokens:protected] => Array
                (
                )

        )

    [3] => Wudimei\View\Token Object
        (
            [line:protected] => 2
            [column:protected] => 67
            [position:protected] => 73
            [content:protected] => 

            [length:protected] => 2
            [tokenValue:protected] => 10
            [tokens:protected] => Array
                (
                )

        )

    [4] => Wudimei\View\Token Object
        (
            [line:protected] => 3
            [column:protected] => 2
            [position:protected] => 75
            [content:protected] => {{
            [length:protected] => 2
            [tokenValue:protected] => 3
            [tokens:protected] => Array
                (
                )

        )

    [5] => Wudimei\View\Token Object
        (
            [line:protected] => 3
            [column:protected] => 4
            [position:protected] => 77
            [content:protected] => 10*20.043123+8*times
            [length:protected] => 20
            [tokenValue:protected] => 8
            [tokens:protected] => Array
                (
                    [0] => Wudimei\View\Token Object
                        (
                            [line:protected] => 3
                            [column:protected] => 5
                            [position:protected] => 77
                            [content:protected] => 10
                            [length:protected] => 2
                            [tokenValue:protected] => 11
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [1] => Wudimei\View\Token Object
                        (
                            [line:protected] => 3
                            [column:protected] => 7
                            [position:protected] => 79
                            [content:protected] => *
                            [length:protected] => 1
                            [tokenValue:protected] => 13
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [2] => Wudimei\View\Token Object
                        (
                            [line:protected] => 3
                            [column:protected] => 8
                            [position:protected] => 80
                            [content:protected] => 20.043123
                            [length:protected] => 9
                            [tokenValue:protected] => 11
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [3] => Wudimei\View\Token Object
                        (
                            [line:protected] => 3
                            [column:protected] => 17
                            [position:protected] => 89
                            [content:protected] => +
                            [length:protected] => 1
                            [tokenValue:protected] => 13
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [4] => Wudimei\View\Token Object
                        (
                            [line:protected] => 3
                            [column:protected] => 18
                            [position:protected] => 90
                            [content:protected] => 8
                            [length:protected] => 1
                            [tokenValue:protected] => 11
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [5] => Wudimei\View\Token Object
                        (
                            [line:protected] => 3
                            [column:protected] => 19
                            [position:protected] => 91
                            [content:protected] => *
                            [length:protected] => 1
                            [tokenValue:protected] => 13
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [6] => Wudimei\View\Token Object
                        (
                            [line:protected] => 3
                            [column:protected] => 20
                            [position:protected] => 92
                            [content:protected] => times
                            [length:protected] => 5
                            [tokenValue:protected] => 15
                            [tokens:protected] => Array
                                (
                                )

                        )

                )

        )

    [6] => Wudimei\View\Token Object
        (
            [line:protected] => 3
            [column:protected] => 24
            [position:protected] => 97
            [content:protected] => }}
            [length:protected] => 2
            [tokenValue:protected] => 4
            [tokens:protected] => Array
                (
                )

        )

    [7] => Wudimei\View\Token Object
        (
            [line:protected] => 3
            [column:protected] => 26
            [position:protected] => 99
            [content:protected] => 

            [length:protected] => 1
            [tokenValue:protected] => 10
            [tokens:protected] => Array
                (
                )

        )

    [8] => Wudimei\View\Token Object
        (
            [line:protected] => 4
            [column:protected] => 1
            [position:protected] => 100
            [content:protected] => {%
            [length:protected] => 2
            [tokenValue:protected] => 1
            [tokens:protected] => Array
                (
                )

        )

    [9] => Wudimei\View\Token Object
        (
            [line:protected] => 4
            [column:protected] => 3
            [position:protected] => 102
            [content:protected] =>  endif
            [length:protected] => 7
            [tokenValue:protected] => 7
            [tokens:protected] => Array
                (
                    [0] => Wudimei\View\Token Object
                        (
                            [line:protected] => 4
                            [column:protected] => 4
                            [position:protected] => 102
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [1] => Wudimei\View\Token Object
                        (
                            [line:protected] => 4
                            [column:protected] => 5
                            [position:protected] => 103
                            [content:protected] => endif
                            [length:protected] => 5
                            [tokenValue:protected] => 15
                            [tokens:protected] => Array
                                (
                                )

                        )

                    [2] => Wudimei\View\Token Object
                        (
                            [line:protected] => 4
                            [column:protected] => 10
                            [position:protected] => 108
                            [content:protected] =>
                            [length:protected] => 1
                            [tokenValue:protected] => 14
                            [tokens:protected] => Array
                                (
                                )

                        )

                )

        )

    [10] => Wudimei\View\Token Object
        (
            [line:protected] => 4
            [column:protected] => 10
            [position:protected] => 109
            [content:protected] => %}
            [length:protected] => 2
            [tokenValue:protected] => 2
            [tokens:protected] => Array
                (
                )

        )

    [11] => Wudimei\View\Token Object
        (
            [line:protected] => 4
            [column:protected] => 12
            [position:protected] => 111
            [content:protected] => 

            [length:protected] => 2
            [tokenValue:protected] => 10
            [tokens:protected] => Array
                (
                )

        )

)

原文地址:https://www.cnblogs.com/wudimei/p/9157056.html

时间: 2024-11-13 10:22:25

zephir开发的扩展“wudimei框架”之模板词法扫描(三)完成代码切分的相关文章

tinyshop框架教程模板开发与开发手册讲解

第一课 tiny框架的处理流程与目录结构 [录播]了解tiny框架的处理流程与目录结构(27分钟) 02 第二课 tiny框架的程序入口与url模式 [录播]tinyshop框架的程序入口与url模式(15分钟) 03 第三课 tiny框架的配置文件与配置参数讲解 [录播]tinyshop框架的配置文件与配置参数讲解(11分钟) 04 第四课 tiny框架的命名规范 [录播]tinyshop框架的命名规范(13分钟) 05 第五课 tiny框架的配置文件system.php的参数讲解 [录播]t

Android &amp;Swift iOS开发:语言与框架对比

转载自:http://www.infoq.com/cn/articles/from-android-to-swift-ios?utm_campaign=rightbar_v2&utm_source=infoq&utm_medium=articles_link&utm_content=link_text 从Android到Swift iOS开发:语言与框架对比 我从2009年开始做Android开发,开始接触Swift是在2014年底,当时组里曾经做过一个Demo App,感觉技术还

iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)

iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角) 2015-04-05 15:25 2482人阅读 评论(1) 收藏 举报开源框架 图像: 1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作.      下载:https://github.com/mwaterfall/MWPhotoBrowser目前比较活跃的社区仍旧是Github,

iOS开发-常用第三方开源框架介绍

iOS开发-常用第三方开源框架介绍 图像: 1.图片浏览控件MWPhotoBrowser 实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作. 下载:https://github.com/mwaterfall/MWPhotoBrowser 目前比较活跃的社区仍旧是Github,除此以外也有一些不错的库散落在Google Code.SourceForge等地方.由于Github社区太过主流,这里主要介绍一下G

10个用于Web开发的最好 Python 框架

Python 是一门动态.面向对象语言.其最初就是作为一门面向对象语言设计的,并且在后期又加入了一些更高级的特性.除了语言本身的设计目的之外,Python标准 库也是值得大家称赞的,Python甚至还自带服务器.其它方面,Python拥有足够多的免费数据函数库.免费的Web网页模板系统.还有与Web服务 器进行交互的库.这些都可以设计到你的Web应用程序里面.在这篇文章里,我们将为Python Web开发者介绍基于Python的10大Web应用框架. CubicWeb CubicWeb的最重要的

Express 框架、模板,MongoDB数据库

今天跟大家分享的是Express框架.模板.MongoDB数据库:个人觉得很有用,希望能在大家做项目的的过程中能有所帮助. Express 模板 这是一个用户量较大的一个Node框架,提供了一整套的Node模板,在里面可以使用EJS模板引擎.. 基于 Node.js 平台,快速.开放.极简的 web 开发框架.(开发后端) Express的性能对Node没有影响,依然很高. 安装方法: 1. 全局安装express 和 express应用生成器 npm install express -g np

Web高效开发必备的PHP框架

Web高效开发必备的PHP框架项目名称:多功能THinkPHP开源框架项目名称:基于Laravel的轻量级web部署系统Fixhub 1.项目名称:多功能 THinkPHP 开源框架 项目简介:使用 THinkPHP 开发项目的过程中把一些常用的功能或者第三方 sdk 整合好,开源供亲们参考,如 Auth 权限管理.支付宝.微信支付.阿里oss.友盟推送.融云即时通讯.云通讯短信.Email.Excel.PDF 等等.这些都是经过线上运营考验的,无毒害可以免费放心折腾使用.只要不会某一天找到我说

AppleWatch开发入门一——Watch的开发思路与应用框架

AppleWatch开发入门一--Watch的开发思路与应用框架 一.引言 Apple Watch无疑是apple在智能手表领域的一次革命,如何在Watch上开发出实用且具有美感的应用,是iOS开发者们开始思考的一个问题,由于watch的随身性和快捷性,在某些方面,它有比iphone更加大的优势,要抓住watch的这些特点,开发出淋漓尽致的应用,就需要改变一些在iphone开发的思路,正如一句话:只有忘掉经验,才会有意想不到的突破. 这一系列博客,首先是总结我在公司watch项目开发中的一些经验

跨平台开发之阿里Weex框架环境搭建(一)

申明:原创文章,转载请注明出处,谢谢! https://i.cnblogs.com/EditPosts.aspx?postid=5995122 一.介绍 Weex是阿里今年6月份推出的跨平台解决方案,6月底正式开源.官网 https://alibaba.github.io/weex/ 1.官方支持iOS.Android.HTML5. 2.Write Once, Run Everywhere.一次编写可生成三平台代码. 3.DSL模板学习超简单,直接写HTML.CSS.JS.这意味着可以直接用现有