Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
TokenizerPatterns example
class
Tokenizer
{
/** * @var Handler\HandlerInterface[] */
private
array
$handlers
;
public
function
__construct
(
)
{
$patterns
=
new
TokenizerPatterns
(
)
;
$escaping
=
new
TokenizerEscaping
(
$patterns
)
;
$this
->handlers =
[
new
Handler\
WhitespaceHandler
(
)
,
new
Handler\
IdentifierHandler
(
$patterns
,
$escaping
)
,
new
Handler\
HashHandler
(
$patterns
,
$escaping
)
,
new
Handler\
StringHandler
(
$patterns
,
$escaping
)
,
new
Handler\
NumberHandler
(
$patterns
)
,
new
Handler\
CommentHandler
(
)
,
]
;
}
return
[
[
'id'
]
,
[
'123'
]
,
[
'<'
]
,
[
'<'
]
,
[
'#'
]
,
]
;
}
protected
function
generateHandler
(
)
{
$patterns
=
new
TokenizerPatterns
(
)
;
return
new
HashHandler
(
$patterns
,
new
TokenizerEscaping
(
$patterns
)
)
;
}
}
return
[
[
'>'
]
,
[
'+'
]
,
[
' '
]
,
[
'*|foo'
]
,
[
'/* comment */'
]
,
]
;
}
protected
function
generateHandler
(
)
{
$patterns
=
new
TokenizerPatterns
(
)
;
return
new
IdentifierHandler
(
$patterns
,
new
TokenizerEscaping
(
$patterns
)
)
;
}
}
return
[
[
'hello'
]
,
[
'>'
]
,
[
'1'
]
,
[
' '
]
,
]
;
}
protected
function
generateHandler
(
)
{
$patterns
=
new
TokenizerPatterns
(
)
;
return
new
StringHandler
(
$patterns
,
new
TokenizerEscaping
(
$patterns
)
)
;
}
}
return
[
[
'hello'
]
,
[
'>'
]
,
[
'+'
]
,
[
' '
]
,
[
'/* comment */'
]
,
]
;
}
protected
function
generateHandler
(
)
{
$patterns
=
new
TokenizerPatterns
(
)
;
return
new
NumberHandler
(
$patterns
)
;
}
}