Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F119258078
PhutilSimpleOptionsLexer.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jun 25, 16:55
Size
1 KB
Mime Type
text/x-php
Expires
Fri, Jun 27, 16:55 (2 d)
Engine
blob
Format
Raw Data
Handle
26988616
Attached To
rPHU libphutil
PhutilSimpleOptionsLexer.php
View Options
<?php
/**
* Lexer for simple options, like:
*
* eyes=2, legs=4
*
* Values may be quoted and escaped:
*
* eyes="one, or two", legs="{^,\",^}"
*
* @group lexer
*/
final
class
PhutilSimpleOptionsLexer
extends
PhutilLexer
{
public
function
getNiceTokens
(
$input
)
{
$tokens
=
$this
->
getTokens
(
$input
);
foreach
(
$tokens
as
$key
=>
$token
)
{
list
(
$type
,
$value
)
=
$token
;
switch
(
$type
)
{
case
'esc'
:
$tokens
[
$key
][
0
]
=
'word'
;
$tokens
[
$key
][
1
]
=
substr
(
$value
,
1
);
break
;
}
}
$tokens
=
$this
->
mergeTokens
(
$tokens
);
// NOTE: Strip these only after merging tokens, so "a b" merges into two
// words, "a" and "b", not a single "ab" word.
foreach
(
$tokens
as
$key
=>
$token
)
{
list
(
$type
,
$value
)
=
$token
;
switch
(
$type
)
{
case
"'"
:
case
'"'
:
case
' '
:
unset
(
$tokens
[
$key
]);
break
;
}
}
return
array_values
(
$tokens
);
}
protected
function
getRawRules
()
{
return
array
(
'start'
=>
array
(
array
(
'
\s
+'
,
' '
),
array
(
"'"
,
"'"
,
'string1'
),
array
(
'"'
,
'"'
,
'string2'
),
array
(
','
,
','
),
array
(
'='
,
'='
),
array
(
'[^
\\
s
\'
"=,]+'
,
'word'
),
),
'string1'
=>
array
(
array
(
'[^
\'\\\\
]+'
,
'word'
),
array
(
"'"
,
"'"
,
'!pop'
),
array
(
'
\\\\
.'
,
'esc'
),
),
'string2'
=>
array
(
array
(
'[^"
\\\\
]+'
,
'word'
),
array
(
'"'
,
'"'
,
'!pop'
),
array
(
'
\\\\
.'
,
'esc'
),
),
);
}
}
Event Timeline
Log In to Comment