-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0004.py
More file actions
28 lines (18 loc) · 714 Bytes
/
0004.py
File metadata and controls
28 lines (18 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import logging
import combinators.core as core
import combinators.tokenization as tokenization
logging.basicConfig (level = logging.INFO)
logger = logging.getLogger (__name__)
specifications = [ ( "SPACE", ( "[ \t]+", ) ),
( "LETTERS", ( "[a-zA-Z]+", ) ), ]
tokenizer = tokenization.create (specifications)
letters = core.predeclared ("LETTERS")
space = core.token_type ("SPACE")
try:
sequence = core.many (letters + space)
logger.info (sequence.name)
letters.declare (core.token_type ("LETTERS"))
logger.info (sequence.name)
logger.info (sequence.parse (list (tokenizer ("ABC DEF GHI JKL"))))
except core.Error as error:
logger.info (repr (error))