Beispiel #1
0
    def start(
            self,
            compiler: 'Compiler',
            match: Match[str],
            state: State,
    ) -> Tuple[State, bool, Regions]:
        scope = state.cur.scope + self.name
        next_scope = scope + self.content_name

        boundary = match.end() == len(match.string)
        reg = make_reg(expand_escaped(match, self.while_))
        state = state.push_while(self, Entry(next_scope, self, reg, boundary))
        regions = _captures(compiler, scope, match, self.begin_captures)
        return state, True, regions
Beispiel #2
0
    def _raw_for_scope(self, scope: str) -> Dict[str, Any]:
        try:
            return self._raw[scope]
        except KeyError:
            pass

        grammar_path = self._scope_to_files.pop(scope)
        with open(grammar_path) as f:
            ret = self._raw[scope] = json.load(f)

        file_types = frozenset(ret.get('fileTypes', ()))
        first_line = make_reg(ret.get('firstLineMatch', '$impossible^'))

        self._file_types.append((file_types, scope))
        self._first_line.append((first_line, scope))

        return ret