import { Lexer } from "../text/lexer/Lexer"; import { LexerMatcher } from "../text/lexer/LexerMatcher"; import { ExtendedRegex } from "../text/ExtendedRegex"; export type SPECIAL_SELECTOR_AND_ATTRIBUTE = "SPECIAL_SELECTOR_AND_ATTRIBUTE"; export type SELECTOR_AND_ATTRIBUTE = "SELECTOR_AND_ATTRIBUTE"; export type SPECIAL_SELECTOR = "SPECIAL_SELECTOR"; export type SELECTOR = "SELECTOR"; export type ATTRIBUTE = "ATTRIBUTE"; export type PASS_THROUGH = "PASS_THROUGH"; export type CONTENT = "CONTENT"; export type DEFAULT = "DEFAULT"; export type TemplatesSourceType = SELECTOR_AND_ATTRIBUTE | SELECTOR | ATTRIBUTE | PASS_THROUGH; export class TemplatesSourceLexer extends Lexer { static readonly SPECIAL_SELECTOR_AND_ATTRIBUTE:SPECIAL_SELECTOR_AND_ATTRIBUTE = "SPECIAL_SELECTOR_AND_ATTRIBUTE"; static readonly SELECTOR_AND_ATTRIBUTE:SELECTOR_AND_ATTRIBUTE = "SELECTOR_AND_ATTRIBUTE"; static readonly SPECIAL_SELECTOR:SPECIAL_SELECTOR = "SPECIAL_SELECTOR"; static readonly SELECTOR:SELECTOR = "SELECTOR"; static readonly ATTRIBUTE:ATTRIBUTE = "ATTRIBUTE"; static readonly PASS_THROUGH:PASS_THROUGH = "PASS_THROUGH"; static readonly CONTENT:CONTENT = "CONTENT"; static readonly DEFAULT:DEFAULT = "DEFAULT"; static readonly defaultMatcher = new LexerMatcher( TemplatesSourceLexer.DEFAULT, ExtendedRegex.create( /@\(\(([^\)\)]+)\)\)/ ) ); static readonly specialSelectorAndAttributeMatcher = new LexerMatcher( TemplatesSourceLexer.SPECIAL_SELECTOR_AND_ATTRIBUTE, ExtendedRegex.create( /@\{(\P):(\V)\}\[(\P)\]/ ) ); static readonly selectorAndAttributeMatcher = new LexerMatcher( TemplatesSourceLexer.SELECTOR_AND_ATTRIBUTE, ExtendedRegex.create( /@\{(\V)\}\[(\P)\]/ ) ); static readonly specialSelectorMatcher = new LexerMatcher( TemplatesSourceLexer.SELECTOR, ExtendedRegex.create( /@\{(\P):(\V)\}/ ) ); static readonly selectorMatcher = new LexerMatcher( TemplatesSourceLexer.SELECTOR, ExtendedRegex.create( /@\{(\V)\}/ ) ); static readonly attributeMatcher = new LexerMatcher( TemplatesSourceLexer.ATTRIBUTE, ExtendedRegex.create( /@\[(\P)\]/ ) ); static readonly passThroughMatcher = new LexerMatcher( TemplatesSourceLexer.ATTRIBUTE, ExtendedRegex.create( /@\{\}/ ) ); static readonly contentMatcher = new LexerMatcher( TemplatesSourceLexer.CONTENT, ExtendedRegex.create( /.|\n|\r/ ) ) constructor() { super(); this._create(); } _create() { this.addMatcher( TemplatesSourceLexer.defaultMatcher ); this.addMatcher( TemplatesSourceLexer.specialSelectorAndAttributeMatcher ); this.addMatcher( TemplatesSourceLexer.selectorAndAttributeMatcher ); this.addMatcher( TemplatesSourceLexer.specialSelectorMatcher ); this.addMatcher( TemplatesSourceLexer.selectorMatcher ); this.addMatcher( TemplatesSourceLexer.attributeMatcher ); this.addMatcher( TemplatesSourceLexer.passThroughMatcher ); this.addMatcher( TemplatesSourceLexer.contentMatcher ) ; } }