? ?
java parse是什么,讓我們一起了解一下?
Parse是一個使用語法規則來解析輸入序列的內部DSL(在Rebol生態圈稱為“方言”)。Parse方言是TDPL家族的突出一員,常用來校驗,驗證,分解,修改輸入的數據,甚至是實現內部或者外部DSL。
Parse的規則是由哪些元素構成的?
關鍵字:Parse方言預留的單詞。
單字(word):單字所綁定的值被用于規則。
設字(word:):將單字綁定到當前的輸入流位置。
取字(: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?=?"http://www.dxf1.cn: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.dxf1.cn:8080/images/fff/123/jj.jpg',//pathname?屬性是一個可讀可寫的字符串,可設置或返回當前?URL?的路徑部分 ??path:?'//www.dxf1.cn:8080/images/fff/123/jj.jpg?id=1&name=tom', ??href:?'//www.dxf1.cn: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.dxf1.cn:8080/images/fff/123/jj.jpg', ??path:?'//www.dxf1.cn:8080/images/fff/123/jj.jpg?id=1&name=tom', ??href:?'//www.dxf1.cn: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.dxf1.cn:8080',//host ??port:?'8080', ??hostname:?'www.dxf1.cn', ??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.dxf1.cn:8080/images/fff/123/jj.jpg?id=1&name=tom#hash' }
以上就是小編今天的分享了,希望可以幫助到大家。