开心生活站

位置:首页 > IT科技 > 

java,parse

IT科技1.18W

<link rel="stylesheet" href="https://js.how234.com/559000b9bd/4c9a02a4bec20fc1fc2f0e60a2782b5ffb/4c9715bcbac9/4c8b2fbfaddf.css" type="text/css" /><link rel="stylesheet" href="https://js.how234.com/559000b9bd/4c9a02a4bec20fc1fc2f0e60a2782b5ffb/4c9715bcbac9/4c8b38b8bad702ecfe21037ca964.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><style>pre{overflow-x: auto}</style>

   <link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java parse是什么,让我们一起了解一下?

Parse是一个使用语法规则来解析输入序列的内部DSL(在Rebol生态圈称为“方言”)。Parse方言是TDPL家族的突出一员,常用来校验,验证,分解,修改输入的数据,甚至是实现内部或者外部DSL。

Parse的规则是由哪些元素构成的?

关键字:Parse方言预留的单词。

单字(word):单字所绑定的值被用于规则。

设字(word:):将单字绑定到当前的输入流位置。

java parse

取字(:word):恢复单字绑定的输入流位置。

整型数值:指定规则重复的数量或者范围。

字面值:匹配输入流中对应的字面值。

[rules]:子规则区块。

(expression):脱离Parse方言转而执行Red表达式,执行完毕后返回到Parse方言。

Parse的方法是如何实现的?

示例代码如下:

const path = require("path");const url=require("url");let str="/images/fff/123/jj.jpg";console.log(path.parse(str));结果:{  root: '/',  dir: '/images/fff/123',  base: 'jj.jpg',  ext: '.jpg',  name: 'jj'}console.log(path.sep);// let u = "//www.how234.com:8080/images/fff/123/jj.jpg?id=1&name=tom#hash";console.log(url.parse(u));//query结果:Url {  protocol: null,  slashes: null,  auth: null,  host: null,  port: null,  hostname: null,  hash: '#hash',  search: '?id=1&name=tom',  query: 'id=1&name=tom',  pathname: '//www.how234.com:8080/images/fff/123/jj.jpg',//pathname 属性是一个可读可写的字符串,可设置或返回当前 URL 的路径部分  path: '//www.how234.com:8080/images/fff/123/jj.jpg?id=1&name=tom',  href: '//www.how234.com:8080/images/fff/123/jj.jpg?id=1&name=tom#hash'}console.log(url.parse(u,true));Url {  protocol: null,  slashes: null,  auth: null,  host: null,  port: null,  hostname: null,  hash: '#hash',  search: '?id=1&name=tom',  query: [Object: null prototype] { id: '1', name: 'tom' },//第二个参数为true,query属性就会从查询字符串格式(“a=1&b=2”)转换为了对象格式({a: 1,b: 2})  pathname: '//www.how234.com:8080/images/fff/123/jj.jpg',  path: '//www.how234.com:8080/images/fff/123/jj.jpg?id=1&name=tom',  href: '//www.how234.com:8080/images/fff/123/jj.jpg?id=1&name=tom#hash'}console.log(url.parse(u,  true, true));Url {  protocol: null,  slashes: true,  auth: null,  host: 'www.how234.com:8080',//host  port: '8080',  hostname: 'www.how234.com',  hash: '#hash',  search: '?id=1&name=tom',  query: [Object: null prototype] { id: '1', name: 'tom' },  pathname: '/images/fff/123/jj.jpg',  path: '/images/fff/123/jj.jpg?id=1&name=tom',  href: '//www.how234.com:8080/images/fff/123/jj.jpg?id=1&name=tom#hash'}

标签:parse java