Skip to content

Commit

Permalink
PHP: run HTML parser as a guest
Browse files Browse the repository at this point in the history
Close universal-ctags#2256.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Mar 5, 2022
1 parent 2734995 commit f476dfe
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Units/parser-php.r/run-guest.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--sort=no
--extras=+rg
--fields=+rln
8 changes: 8 additions & 0 deletions Units/parser-php.r/run-guest.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
draw input.php /^ function draw($x) {$/;" f line:3 language:PHP roles:def
nothing input.php /^ function nothing($x) {$/;" f line:31 language:PHP roles:def
X input.php /^<html><head><title>X<\/title>$/;" j line:1 language:HTML roles:def
My Home Page input.php /^ <title>My Home Page<\/title>$/;" j line:8 language:HTML roles:def
css/general.css input.php /^ <link rel="stylesheet" href="css\/general.css" type="text\/css">$/;" C line:9 language:HTML roles:extFile
stuff input.php /^ <h1>stuff<\/h1>$/;" h line:13 language:HTML roles:def
f input.php /^ var f = function (n) {$/;" f line:21 language:JavaScript roles:def
.blarg input.php /^.blarg {$/;" c line:26 language:CSS roles:def
34 changes: 34 additions & 0 deletions Units/parser-php.r/run-guest.d/input.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<html><head><title>X</title>
<?php // This test input is derived from #2256 submitted by @StephenWall.
function draw($x) {
echo "$x";
}
?>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>My Home Page</title>
<link rel="stylesheet" href="css/general.css" type="text/css">
<style type="text/css"></stylE>
</head>
<body>
<h1>stuff</h1>
<a href="/blah">nowhere</a>
<?=draw('nowhere')?>
<a href="/blech">somewhere</a>
<?=draw('somewhere')?>
</body>
</html>
<script>
var f = function (n) {
return n + 1;
}
</script>
<style>
.blarg {
position: relative;
}
</style>
<?php
function nothing($x) {
;
}
?>
13 changes: 13 additions & 0 deletions parsers/php.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "routines.h"
#include "debug.h"
#include "objpool.h"
#include "promise.h"

#define isIdentChar(c) (isalnum (c) || (c) == '_' || (c) >= 0x80)
#define newToken() (objPoolGet (TokenPool))
Expand Down Expand Up @@ -901,9 +902,21 @@ static void readToken (tokenInfo *const token)

if (! InPhp)
{
unsigned long startSourceLineNumber = getSourceLineNumber ();
unsigned long startLineNumber = startSourceLineNumber;
int startLineOffset = getInputLineOffset ();

c = findPhpStart ();
if (c != EOF)
InPhp = true;

unsigned long endLineNumber = getInputLineNumber ();
int endLineOffset = getInputLineOffset ();

if ((startLineNumber != endLineNumber)
|| (startLineOffset != endLineOffset))
makePromise ("HTML", startLineNumber, startLineOffset,
endLineNumber, endLineOffset, startSourceLineNumber);
}
else
c = getcFromInputFile ();
Expand Down

0 comments on commit f476dfe

Please sign in to comment.