def command(self, items, meta): parts = [] for item in items: if isinstance(item, E.Placeholder): parts.append(item) else: parts.append(item.value) return {"command": E.String(sp(self.filename, meta), parts)}
def command(self, items, meta): parts = [] for item in items: if isinstance(item, E.Placeholder): parts.append(item) elif item.type.endswith("_FRAGMENT"): parts.append(item.value[:-2]) else: parts.append(item.value) return {"command": E.String(sp(self.filename, meta), parts)}
def string(self, items, meta) -> E.Base: parts = [] for item in items: if isinstance(item, E.Base): parts.append(E.Placeholder(item.pos, {}, item)) else: parts.append(item.value) assert len(parts) >= 2 assert parts[0] in ['"', "'"] assert parts[-1] in ['"', "'"] return E.String(sp(self.filename, meta), parts)
def string(self, items, meta) -> E.Base: parts = [] for item in items: if isinstance(item, E.Base): parts.append(E.Placeholder(item.pos, {}, item)) elif item.type.endswith("_FRAGMENT"): # for an interpolation fragment, item.value will end with "${" # so we strip that off. it'd be nice to make the grammar filter # that out since it does later filter out the "}"... parts.append(item.value[:-2]) else: parts.append(item.value) # fix up a parsing quirk -- the opening quote got its own item but the # closing quote didn't assert len(parts) >= 2 assert parts[0] in ['"', "'"] assert parts[-1][-1] in ['"', "'"] # pyre-fixme if len(parts[-1]) > 1: parts.append(parts[-1][-1]) # pyre-fixme parts[-2] = parts[-2][:-1] # pyre-fixme return E.String(sp(self.filename, meta), parts)