Changeset View
Changeset View
Standalone View
Standalone View
src/lexer/PhutilPythonFragmentLexer.php
Show First 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | protected function getRawRules() { | ||||
$stringescape = array( | $stringescape = array( | ||||
array( | array( | ||||
'\\\\([\\\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'. | '\\\\([\\\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'. | ||||
'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', | 'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', | ||||
'se' | 'se' | ||||
), | ), | ||||
); | ); | ||||
$nl = array( | |||||
array('\\n', 's'), | |||||
); | |||||
$strings = array( | $strings = array( | ||||
array( | array( | ||||
'%(\\(\\w+\\))?[-#0 +]*([0-9]+|[*])?(\\.([0-9]+|[*]))?'. | '%(\\(\\w+\\))?[-#0 +]*([0-9]+|[*])?(\\.([0-9]+|[*]))?'. | ||||
'[hlL]?[diouxXeEfFgGcrs%]', | '[hlL]?[diouxXeEfFgGcrs%]', | ||||
'si' | 'si' | ||||
), | ), | ||||
array('[^\\\\\'"%\\n]+', 's'), | array('[^\\\\\'"%\\n]+', 's'), | ||||
// quotes, percents, and backslashes must be parsed one at a time | // quotes, percents, and backslashes must be parsed one at a time | ||||
array('[\'"\\\\]', 's'), | array('[\'"\\\\]', 's'), | ||||
// unhandled string formatting sign | // unhandled string formatting sign | ||||
array('%', 's'), | array('%', 's'), | ||||
// newlines are an error (use $nl rules) | // newlines are an error (use $nl rules) | ||||
); | array('', null, '!pop'), | ||||
$nl = array( | |||||
array('\\n', 's'), | |||||
); | ); | ||||
$dqs = array_merge(array( | $dqs = array_merge(array( | ||||
array('"', 's', '!pop'), | array('"', 's', '!pop'), | ||||
// included here for raw strings | // included here for raw strings | ||||
array('(?:\\\\\\\\|\\\\\'|\\\\n)', 's', '!pop'), | array('(?:\\\\\\\\|\\\\\'|\\\\n)', 's'), | ||||
), $strings); | ), $strings); | ||||
$sqs = array_merge(array( | $sqs = array_merge(array( | ||||
array('\'', 's', '!pop'), | array('\'', 's', '!pop'), | ||||
// included here for raw strings | // included here for raw strings | ||||
array('(?:\\\\\\\\|\\\\\'|\\\\n)', 's', '!pop'), | array('(?:\\\\\\\\|\\\\\'|\\\\n)', 's'), | ||||
), $strings); | ), $strings); | ||||
$tdqs = array_merge(array( | $tdqs = array_merge(array( | ||||
array('"""', 's', '!pop'), | array('"""', 's', '!pop'), | ||||
), $strings, $nl); | ), $nl, $strings); | ||||
$tsqs = array_merge(array( | $tsqs = array_merge(array( | ||||
array('\'\'\'', 's', '!pop'), | array('\'\'\'', 's', '!pop'), | ||||
), $strings, $nl); | ), $nl, $strings); | ||||
return array( | return array( | ||||
'start' => array_merge(array( | 'start' => array_merge(array( | ||||
array('\\n', null), | array('\\n', null), | ||||
// TODO: Docstrings should match only at the start of a line | // TODO: Docstrings should match only at the start of a line | ||||
array('""".*?"""', 'sd'), | array('""".*?"""', 'sd'), | ||||
array('\'\'\'.*?\'\'\'', 'sd'), | array('\'\'\'.*?\'\'\'', 'sd'), | ||||
), $nonsemantic_rules, array( | ), $nonsemantic_rules, array( | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |