
# Parse html and other similar markups (xml, jsp, etc).
#
# start and end tags allow leading/trailing punctuation (% @ etc) used by some markups)
#

syntaxdef php {

/\s+/m :;

/<\?(php)?(.*?)\?>/s : {
    php(${2});
}

context php {
    # comment
    /(?m)#.*$/ : {
        region {
            type=comment;
            index=prose;
            findlinks=true;
        }
    }
    /\/\/.*$/m : {
          region {
             type=comment;
             index=prose;
             findlinks=true;
          }
       }

    /\/\*(.*?)\*\//s : {
          region {
             type=comment;
             index=prose;
             findlinks=true;
          }
       }

    # string literals
    /"/ : {
        context {
            /\\./: ;
            /$/m : exit;
            "\"" : exit;
        }
        region ${ALL} {
               type=string;
        }
    }

    /'/ : {
        context {
            /\\./: ;
            /$/m : exit;
            "'" : exit;
        }
        region ${ALL} {
               type=string;
        }
    }

    #numbers
    /(0(x|X)[0-9A-Fa-f]+(l|L)?)|([0-9]+(\.[0-9]*)?|\.[0-9]+)((e|E)(\+|-)?[0-9]+)?(f|F|l|L|d|D)?/ : {
        region {
            type=numeric;
        }
    }


    /(if|else|elseif|endif|echo|while|endwhile|do|for|foreach|as|break|switch|case|default|continue|declare|return|require|include|require_once)\b/ : {
           region {
             type=keyword;
             index=word;
           }
    }

}
#below is for HTML markup inside php
/<\!--(.*?)-->/s : {
      # todo - support embedded scripts
      region {
        type=comment;
      }
    }

/  <
   ([%@!?=$\s]+)?             # leading punctuation (opt)
   ([\p{N}\p{L}._:-]+  )      # tag name
   /mx : {
          context {           #context for matching attributes
                /
                ([%@!?$\s]+)?              # trailing punctuation (opt)
                (\/\s*)?                   # trailing slash (opt)
                >                          # closing angle brackets
                /mx : exit;

                /
                ([\p{N}\p{L}._:-]+)         # attribute name
                \s*=\s*                     # equals
                ("[^"]*?"|'[^']*?'|[^\s>]+) # attribute data - should consume '>' if encountered inside " or '
                /mx : {
                    region ${1} {
                       type=attrib;
                    }
                    region ${2} {
                       type=string;
                       findlinks=true;
                    }
                }
          }
          region ${ALL} {
            type=starttag;
          }
    }

/  <\/
   ([%@!?=$\s]+)?          # leading punctuation (opt)
   ([\p{N}\p{L}._:-]+)     # tag name
   ([%@!?=$\s]+)?          # trailing punctuation (opt)
   (\/\s*)?                # trailing slash (opt)
   >  /mx : {
      region {
        type=endtag;
      }
    }

/&[\w\d]+;/ : {
      region {
        type=escape;
      }
    }

}