-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1948c949.2141d7ae.js
1 lines (1 loc) · 4.37 KB
/
1948c949.2141d7ae.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[44],{142:function(e,t,r){"use strict";r.r(t),r.d(t,"frontMatter",(function(){return s})),r.d(t,"metadata",(function(){return i})),r.d(t,"rightToc",(function(){return c})),r.d(t,"default",(function(){return u}));var n=r(2),a=r(6),o=(r(0),r(469)),s={title:"Order matters",sidebar_label:"Order matters"},i={id:"version-0.3.1/tutorial/order_matters",isDocsHomePage:!1,title:"Order matters",description:'The order of clauses in an or() matters. If we do the following parser definition, the parser will consume "http", even if the strings starts with "https", leaving "s://..." as the remainder.',source:"@site/versioned_docs/version-0.3.1/tutorial/order_matters.md",permalink:"/docs/0.3.1/tutorial/order_matters",editUrl:"https://github.com/parsica-php/parsica/tree/main/versioned_docs/version-0.3.1/tutorial/order_matters.md",version:"0.3.1",sidebar_label:"Order matters",sidebar:"version-0.3.1/docs",previous:{title:"Mapping to Objects",permalink:"/docs/0.3.1/tutorial/mapping_to_objects"},next:{title:"Recursion",permalink:"/docs/0.3.1/tutorial/recursion"},latestVersionMainDocPermalink:"/docs"},c=[],p={rightToc:c};function u(e){var t=e.components,r=Object(a.a)(e,["components"]);return Object(o.b)("wrapper",Object(n.a)({},p,r,{components:t,mdxType:"MDXLayout"}),Object(o.b)("p",null,'The order of clauses in an or() matters. If we do the following parser definition, the parser will consume "http", even if the strings starts with "https", leaving "s://..." as the remainder.'),Object(o.b)("pre",null,Object(o.b)("code",Object(n.a)({parentName:"pre"},{className:"language-php"}),'<?php\n$parser = string(\'http\')->or(string(\'https\'));\n$input = "https://verraes.net";\n$result = $parser->run($input);\nassert($result->output() === "http");\nassert($result->remainder() === "s://verraes.net");\n')),Object(o.b)("p",null,"The solution is to consider the order of or clauses:"),Object(o.b)("pre",null,Object(o.b)("code",Object(n.a)({parentName:"pre"},{className:"language-php"}),'<?php\n$parser = string(\'https\')->or(string(\'http\'));\n$input = "https://verraes.net";\n$result = $parser->run($input);\nassert($result->output() === "https");\nassert($result->remainder() === "://verraes.net");\n')))}u.isMDXComponent=!0},469:function(e,t,r){"use strict";r.d(t,"a",(function(){return l})),r.d(t,"b",(function(){return m}));var n=r(0),a=r.n(n);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function s(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?s(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function c(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=a.a.createContext({}),u=function(e){var t=a.a.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},l=function(e){var t=u(e.components);return a.a.createElement(p.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.a.createElement(a.a.Fragment,{},t)}},f=a.a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,s=e.parentName,p=c(e,["components","mdxType","originalType","parentName"]),l=u(r),f=n,m=l["".concat(s,".").concat(f)]||l[f]||d[f]||o;return r?a.a.createElement(m,i(i({ref:t},p),{},{components:r})):a.a.createElement(m,i({ref:t},p))}));function m(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,s=new Array(o);s[0]=f;var i={};for(var c in t)hasOwnProperty.call(t,c)&&(i[c]=t[c]);i.originalType=e,i.mdxType="string"==typeof e?e:n,s[1]=i;for(var p=2;p<o;p++)s[p]=r[p];return a.a.createElement.apply(null,s)}return a.a.createElement.apply(null,r)}f.displayName="MDXCreateElement"}}]);