def pattern(): """pyparsing pattern of the command """ def attachLocation(s, loc, tocs): return [(loc, tocs[0])] path = CharsNotIn(" \t")("path") path.setParseAction(attachLocation) pat = (Literal('s ') + Optional(White()) + Optional(path)) pat.leaveWhitespace() pat.setParseAction(CommandSaveAs.create) return pat
def pattern(): """pyparsing pattern of the command """ def attachLocation(s, loc, tocs): return [(loc, tocs[0])] from pyparsing import CharsNotIn, Literal, Optional, White # delayed import, performance optimization path = CharsNotIn(" \t")("path") path.setParseAction(attachLocation) pat = (Literal('s ') + Optional(White()) + Optional(path)) pat.leaveWhitespace() pat.setParseAction(CommandSaveAs.create) return pat
def pattern(): """pyparsing pattern """ def attachLocation(s, loc, tocs): """pyparsing callback. Saves path position in the original string """ return [(loc, tocs[0])] path = CharsNotIn(" \t")("path") path.setParseAction(attachLocation) longPath = CharsNotIn(" \t", min=2)("path") longPath.setParseAction(attachLocation) slashPath = Combine(Literal('/') + Optional(CharsNotIn(" \t")))("path") slashPath.setParseAction(attachLocation) pat = ((Literal('f ') + Optional(White()) + Optional(path)) ^ longPath ^ slashPath) + \ Optional(White() + Word(nums)("line")) pat.leaveWhitespace() pat.setParseAction(CommandOpen.create) return pat
def pattern(): """pyparsing pattern """ def attachLocation(s, loc, tocs): """pyparsing callback. Saves path position in the original string """ return [(loc, tocs[0])] from pyparsing import CharsNotIn, Combine, Literal, Optional, White, Word, nums # delayed import, performance optimization path = CharsNotIn(" \t")("path") path.setParseAction(attachLocation) longPath = CharsNotIn(" \t", min=2)("path") longPath.setParseAction(attachLocation) slashPath = Combine(Literal('/') + Optional(CharsNotIn(" \t")))("path") slashPath.setParseAction(attachLocation) pat = ((Literal('f ') + Optional(White()) + Optional(path)) ^ longPath ^ slashPath) + \ Optional(White() + Word(nums)("line")) pat.leaveWhitespace() pat.setParseAction(CommandOpen.create) return pat