0) $ret .= "\n"; preg_match("@^(\s*)(.*)@",$lines[$i],$matches); $indent = $matches[1]; $ret .= $indent; $rest = $matches[2]; if ($in_script !== false) { if (strlen($indent) <= strlen($in_script)) $in_script = false; } if ($in_script !== false) { $ret .= highlight_script($rest); } else { if (preg_match("@^#@",$rest,$matches)) { $ret .= "$rest"; } else if (preg_match("@^([a-zA-Z0-9 _/,]+):(.*)@",$rest,$matches)) { $key = $matches[1]; $value = $matches[2]; if (preg_match("@script|default@", $key)) $in_script = $indent; if (strpos($value,"{")!==false) $in_script = $indent; if ($in_script !== false) { $value = highlight_script($value); } else if (preg_match("@^(\s*)script:(.*)@",$value,$matches)) { $value = $matches[1] . "script:" . highlight_script($matches[2]); //} else if (preg_match("@\\s*rgb\\([0-9]+,[0-9]+,[0-9]+\\)\\s*@",$value,$matches)) { // $value = highlight_script($value); } $ret .= "$key:$value"; } else { // not valid reader code if (strpos($rest,"{")!==false) $in_script = substr($indent,0,-1); if ($in_script !== false) $rest = highlight_script($rest); $ret .= $rest; } } } return $ret; } function highlight_script($code) { $ret = ''; while(strlen($code)) { if (preg_match("@^(if|then|else|for|in|do|and|or|not|rgb)\b@",$code, $matches)) { $ret .= "" . $matches[0] . ""; } else if (preg_match("@^(include file:)(.*)@",$code, $matches)) { $ret .= "" . $matches[1] . "" . $matches[2]; } else if (preg_match("@^[0-9][0-9.]*@",$code, $matches)) { $ret .= "" . $matches[0] . ""; } else if (preg_match("@^(\"|")(\\\\.|[^\\\\])*?(\"|")@",$code, $matches)) { $ret .= "" . $matches[0] . ""; } else if (preg_match("@^\\#.*@",$code, $matches)) { $ret .= "" . $matches[0] . ""; } else if (preg_match("@^([-+*/=!.]|<|>)+|^:=@",$code, $matches)) { $ret .= "" . $matches[0] . ""; } else if (preg_match("@^[\\(\\)\\[\\]{},]+@",$code, $matches)) { $ret .= "" . $matches[0] . ""; } else if (preg_match("@^[a-zA-Z_][a-zA-Z0-9_]*:@",$code, $matches)) { $ret .= "" . $matches[0] . ""; } else if (preg_match("@^([a-zA-Z0-9_]+\s*|\s+|&#?[a-zA-Z0-9]+;)@",$code, $matches)) { //$ret .= '[' . $matches[0] . ']'; $ret .= $matches[0]; } else { // fallback $matches = array($code[0]); //$ret .= '{{{' . $matches[0] . '}}}'; $ret .= $matches[0]; } $code = substr($code, strlen($matches[0])); } return $ret; } ?>