Discover Packages
github.com/wudi/php-parser
examples
token-extraction
command
Version:
v0.1.0
Opens a new window with list of versions in this module.
Published: Sep 3, 2025
License: MIT
Opens a new window with license information.
Imports: 3
Opens a new window with list of imports.
Imported by: ? modules, 0 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
README
README
¶
This example demonstrates how to use the lexer to extract and analyze tokens from PHP code.
What it does
Extracts all tokens from PHP code using the lexer
Analyzes token statistics and distributions
Demonstrates different token types and their properties
Shows how to filter and categorize tokens
Includes examples of string interpolation tokenization
Key Features
Token Analysis
TokenAnalyzer : Collects statistics about token usage
Token Type Counting : Tracks frequency of each token type
Content Extraction : Separates keywords, identifiers, strings, and numbers
Position Tracking : Shows line and column information for each token
Token Categories
Keywords : PHP language keywords (class, function, if, etc.)
Identifiers : User-defined names (variables, function names, etc.)
Literals : String literals, numbers, and constants
Operators : Arithmetic, comparison, and logical operators
Punctuation : Brackets, parentheses, semicolons, etc.
Running the example
cd examples/token-extraction
go run main.go
Expected output
The program will display:
Complete token stream with positions
Statistical analysis of token types
Categorized content (keywords, identifiers, literals)
Operator and punctuation counts
String interpolation tokenization example
Use Cases
This pattern is useful for:
Syntax Highlighting : Identify different token types for coloring
Code Metrics : Analyze code complexity and patterns
Refactoring Tools : Find and replace specific token patterns
Language Servers : Provide editor features like auto-completion
Code Analysis : Detect coding patterns and potential issues
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.