Skip to main content

jk_php_tokenizer

Introduction

This python module is a tokenizer for configuration files written in PHP.

Information about this module can be found here:

Why this module?

Quite some web applications store their configuration data in PHP files. While this is convenient for the web application developers this has a problematic drawback: If for some reason this configuration needs to be processed (e.g. if you want to do a backup) this is a problem as this configuration data can not be read easily.

This module helps moving towards building a parser for these files by providing a ready to use PHP tokenizer.

Limitations of this module

This module only performs tokenization, not parsing.

As it is intended for reading PHP configuration files it has not been extensively been tested with files other than configuration files.

How to use this module

Import this module

Please include this module into your application using the following code:

import jk_php_tokenizer

Tokenize a file

Tokenizing is easy. The next lines show how to use the tokenizer:

PATH_OF_PHP_FILE = "..."

tokenizer = jk_php_tokenizer.PHPTokenizer()

with open(PATH_OF_PHP_FILE, "r") as f:
	for token in tokenizer.tokenize(f.read()):
		print(token)

The token data structure

A token is a jk_utils.Token data structure. It has the following fields:

  • type - the type of the token
  • value - the token text
  • lineNo - the line number where the token begins
  • colNo - the colum number where the token begins

Token types

The following types of tokens are provided by the tokenizer:

  • int
  • str1
  • str2
  • bool
  • null
  • comment
  • phpintro
  • phpoutro
  • varref
  • commentx
  • lparen1
  • rparen1
  • lparen2
  • rparen2
  • lparen3
  • rparen3
  • bool
  • word
  • op
  • SPACE
  • NEWLINE
  • semicolon

Contact Information

This work is Open Source. This enables you to use this work for free.

Please have in mind this also enables you to contribute. We, the subspecies of software developers, can create great things. But the more collaborate, the more fantastic these things can become. Therefore Feel free to contact the author(s) listed below, either for giving feedback, providing comments, hints, indicate possible collaborations, ideas, improvements. Or maybe for "only" reporting some bugs:

License

This software is provided under the following license:

  • Apache Software License 2.0

Metadata

Release files for jk-php-tokenizer 0.2020.3.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jk-php-tokenizer 0.2020.3.9
File Size Uploaded
jk_php_tokenizer-0.2020.3.9.tar.gz 8.5 kB Details

Release files / jk_php_tokenizer-0.2020.3.9.tar.gz

Download URL jk_php_tokenizer-0.2020.3.9.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d8994310d45cee4f02c2f455da5d070a69e9f1ba933aa9678ca365107032d3c5
BLAKE2b-256 checksum
How to use checksums
10c01cbe222e1796ad903e5e503c220e38a3c9d42f8e2fd9c59200b0480aa885
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.41.1 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.2020.3.9 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page