博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
fastjson深度源码解析- 词法和语法解析(一) - token定义解析
阅读量:4052 次
发布时间:2019-05-25

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

概要

词法分析是反序列化的重要基础,在其他框架druidparsii等框架都用到了词法分析的技术,个人认为在讲反序列化之前讲词法分析更重要。

写出优秀框架之前,先理解大量优秀框架的实现对未来自己写框架非常有帮助!!!

好了,废话不多说,来看看fastjson中定义的token吧。

JSONToken成员

com.alibaba.fastjson.parser.JSONToken定义了fastjson需要的token标识符:

/** 1 关联到 error */    public final static int ERROR                = 1;    /** 2 关联到 int */    public final static int LITERAL_INT          = 2;    /** 3 关联到 float */    public final static int LITERAL_FLOAT        = 3;    /** 4 关联到 string */    public final static int LITERAL_STRING       = 4;    /** 5 关联到 iso8601 */    public final static int LITERAL_ISO8601_DATE = 5;    /** 6 关联到 true */    public final static int TRUE                 = 6;    /** 7 关联到 false */    public final static int FALSE                = 7;    /** 8 关联到 null */    public final static int NULL                 = 8;    /** 9 关联到 new */    public final static int NEW                  = 9;    /** 10 关联到 ( */    public final static int LPAREN               = 10;    /** 11 关联到 ) */    public final static int RPAREN               = 11;    /** 12 关联到 { */    public final static int LBRACE               = 12;    /** 13 关联到 } */    public final static int RBRACE               = 13;    /** 14 关联到 [ */    public final static int LBRACKET             = 14;    /** 15 关联到 ] */    public final static int RBRACKET             = 15;    /** 16 关联到 , */    public final static int COMMA                = 16;    /** 17 关联到 : */    public final static int COLON                = 17;    /** 18 关联到 ident */    public final static int IDENTIFIER           = 18;    /** 19 关联到 fieldName */    public final static int FIELD_NAME           = 19;    /** 20 关联到 EOF */    public final static int EOF                  = 20;    /** 21 关联到 Set */    public final static int SET                  = 21;    /** 22 关联到 TreeSet */    public final static int TREE_SET             = 22;    /** 23 关联到 undefined */    public final static int UNDEFINED            = 23; // undefined    /** 24 关联到 ; */    public final static int SEMI                 = 24;    /** 25 关联到 . */    public final static int DOT                  = 25;    /** 26 关联到 hex */    public final static int HEX                  = 26;    public static String name(int value) {        switch (value) {            case ERROR:                return "error";            case LITERAL_INT:                return "int";            case LITERAL_FLOAT:                return "float";            case LITERAL_STRING:                return "string";            case LITERAL_ISO8601_DATE:                return "iso8601";            case TRUE:                return "true";            case FALSE:                return "false";            case NULL:                return "null";            case NEW:                return "new";            case LPAREN:                return "(";            case RPAREN:                return ")";            case LBRACE:                return "{";            case RBRACE:                return "}";            case LBRACKET:                return "[";            case RBRACKET:                return "]";            case COMMA:                return ",";            case COLON:                return ":";            case SEMI:                return ";";            case DOT:                return ".";            case IDENTIFIER:                return "ident";            case FIELD_NAME:                return "fieldName";            case EOF:                return "EOF";            case SET:                return "Set";            case TREE_SET:                return "TreeSet";            case UNDEFINED:                return "undefined";            case HEX:                return "hex";            default:                return "Unknown";        }    }

接下来,我们继续分析如何实现具体token解析的。

转载地址:http://pitci.baihongyu.com/

你可能感兴趣的文章
JS牛客网编译环境的使用
查看>>
9、VUE面经
查看>>
关于进制转换的具体实现代码
查看>>
Golang 数据可视化利器 go-echarts ,实际使用
查看>>
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>
dba 常用查询
查看>>
Oracle 异机恢复
查看>>
Oracle 12C DG 搭建(RAC-RAC/RAC-单机)
查看>>
Truncate 表之恢复
查看>>
Oracle DG failover 后恢复
查看>>
mysql 主从同步配置
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
mongdb在java中的应用
查看>>
区块链技术让Yotta企业云盘为行政事业服务助力
查看>>
Yotta企业云盘更好的为媒体广告业服务
查看>>
Yotta企业云盘助力科技行业创高峰
查看>>
Yotta企业云盘更好地为教育行业服务
查看>>
Yotta企业云盘怎么帮助到能源化工行业
查看>>