博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zephir开发的扩展“wudimei框架”之模板词法扫描(三)完成代码切分
阅读量:5957 次
发布时间:2019-06-19

本文共 19152 字,大约阅读时间需要 63 分钟。

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

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

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

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

你可能感兴趣的文章
2014.10.1 Form中显示pdf文件
查看>>
NERDTree 快捷键辑录
查看>>
Python数据分析Numpy库方法简介(一)
查看>>
javaWeb:相关监听方法汇总
查看>>
JSP 实现 之 读取数据库显示图片
查看>>
JS——特效秀
查看>>
Beta冲刺——day6
查看>>
前端:CheckBox事件函数js
查看>>
Comet OJ - Contest #3 题解
查看>>
[网络流24题-9]试题库问题
查看>>
jquery选择器详解
查看>>
C# 保留2位小数
查看>>
使用xshell远程连接Linux
查看>>
杭电ACM1007
查看>>
faster-RCNN台标检测
查看>>
Unix环境高级编程 centos中配置apue编译环境
查看>>
运算符
查看>>
数据结构之各排序算法
查看>>
网页分帧操作<frameset>,<iframe>标签
查看>>
Vue生产环境部署
查看>>