MCPcopy Create free account
hub / github.com/nodejs/node / __init__

Method __init__

deps/v8/third_party/jinja2/lexer.py:477–594  ·  view source on GitHub ↗
(self, environment: "Environment")

Source from the content-addressed store, hash-verified

475 """
476
477 def __init__(self, environment: "Environment") -> None:
478 # shortcuts
479 e = re.escape
480
481 def c(x: str) -> t.Pattern[str]:
482 return re.compile(x, re.M | re.S)
483
484 # lexing rules for tags
485 tag_rules: t.List[_Rule] = [
486 _Rule(whitespace_re, TOKEN_WHITESPACE, None),
487 _Rule(float_re, TOKEN_FLOAT, None),
488 _Rule(integer_re, TOKEN_INTEGER, None),
489 _Rule(name_re, TOKEN_NAME, None),
490 _Rule(string_re, TOKEN_STRING, None),
491 _Rule(operator_re, TOKEN_OPERATOR, None),
492 ]
493
494 # assemble the root lexing rule. because "|" is ungreedy
495 # we have to sort by length so that the lexer continues working
496 # as expected when we have parsing rules like <% for block and
497 # <%= for variables. (if someone wants asp like syntax)
498 # variables are just part of the rules if variable processing
499 # is required.
500 root_tag_rules = compile_rules(environment)
501
502 block_start_re = e(environment.block_start_string)
503 block_end_re = e(environment.block_end_string)
504 comment_end_re = e(environment.comment_end_string)
505 variable_end_re = e(environment.variable_end_string)
506
507 # block suffix if trimming is enabled
508 block_suffix_re = "\\n?" if environment.trim_blocks else ""
509
510 self.lstrip_blocks = environment.lstrip_blocks
511
512 self.newline_sequence = environment.newline_sequence
513 self.keep_trailing_newline = environment.keep_trailing_newline
514
515 root_raw_re = (
516 rf"(?P<raw_begin>{block_start_re}(\-|\+|)\s*raw\s*"
517 rf"(?:\-{block_end_re}\s*|{block_end_re}))"
518 )
519 root_parts_re = "|".join(
520 [root_raw_re] + [rf"(?P<{n}>{r}(\-|\+|))" for n, r in root_tag_rules]
521 )
522
523 # global lexing rules
524 self.rules: t.Dict[str, t.List[_Rule]] = {
525 "root": [
526 # directives
527 _Rule(
528 c(rf"(.*?)(?:{root_parts_re})"),
529 OptionalLStrip(TOKEN_DATA, "#bygroup"), # type: ignore
530 "#bygroup",
531 ),
532 # data
533 _Rule(c(".+"), TOKEN_DATA, None),
534 ],

Callers

nothing calls this directly

Calls 7

_RuleClass · 0.85
OptionalLStripClass · 0.85
compile_rulesFunction · 0.70
FailureClass · 0.70
eFunction · 0.50
cFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected