View
@@ -2,7 +2,7 @@
"""
libstr.py - String library functions that can be exposed with a saner syntax.
Instead of
Instead of
local y=${x//a*/b}
@@ -27,7 +27,7 @@
# (1) PatSub: I think we fill in GlobToExtendedRegex, then use regcomp and
# regexec. in a loop. fnmatch() does NOT given positions of matches.
#
# (2) Strip -- % %% # ## -
# (2) Strip -- % %% # ## -
#
# a. Fast path for constant strings.
# b. Convert to POSIX extended regex, to see if it matches at ALL. If it
@@ -108,7 +108,7 @@ def DoUnarySuffixOp(s, op, arg):
return s[:i]
else:
return s
elif op.op_id == Id.VOp1_DPercent: # longest suffix
# 'abcd': match 'abc', 'bc', 'c', ...
for i in xrange(0, n):
@@ -156,7 +156,7 @@ def PatSub(s, op, pat, replace_str):
"""Helper for ${x/pat/replace}."""
#log('PAT %r REPLACE %r', pat, replace_str)
regex, err = glob_.GlobToExtendedRegex(pat)
regex, err = glob_.GlobParser().GlobToExtendedRegex(pat)
if err:
e_die("Can't convert glob to regex: %r", pat)
View
@@ -672,7 +672,7 @@ def ParseForWords(self):
"""
words = []
# The span_id of any semi-colon, so we can remove it.
semi_spid = const.NO_INTEGER
semi_spid = const.NO_INTEGER
while True:
if not self._Peek(): return None
View
@@ -2,8 +2,8 @@
--
-- NOTE: This schema is currently unused. It would be useful for parsing
-- and translating globs to Python's regex engine, which supports non-greedy
-- matches. But we don't want to depend on Python regexes, so we use a
-- quadratic loop like bash/mksh. This is unfortunate, but strings are
-- matches. But we don't want to depend on Python regexes, so we use a
-- quadratic loop like bash/mksh. This is unfortunate, but strings are
-- generally short.
--
-- The schema could still be used for some kind of automatic glob translation.
@@ -19,20 +19,12 @@ module glob {
glob = (glob_part* parts)
-- Example: *.[ch] is Star, Literal('.'), CharClass(False, ...)
glob_part =
Literal(string s)
| EscapedChar(string c) -- \* \? \[
| Star -- * is 0 or more characters, like the regex .*
-- Example: *.[ch] is Star, Literal('.'), CharClassExpr(False, 'ch')
glob_part =
Literal(string s)
| Star -- * is 0 or more characters, like the regex .*
| QMark -- ? is a single character
| BracketExpr(bool negated, char_clause* clauses)
char_clause =
LiteralChar(string c)
-- NOTE: Name conflict with above. Should be namespaced.
| EscapedChar2(string c) -- \! \-
| CharRange(string begin, string end) -- a-z 0-9
| CharClass(string name) -- [:alpha:]
| CharClassExpr(bool negated, string body)
-- TODO:
-- * Collating symbols are [. .]
View
@@ -141,6 +141,26 @@ def IdInstance(i):
f.close()
#
# Instantiate osh/glob.asdl
#
f = util.GetResourceLoader().open('osh/glob.asdl')
_asdl_module, _type_lookup = asdl.LoadSchema(f, APP_TYPES)
glob = _AsdlModule()
if 0:
py_meta.MakeTypes(_asdl_module, glob, _type_lookup)
else:
# Exported for the generated code to use
GLOB_TYPE_LOOKUP = _type_lookup
# Get the types from elsewhere
from _devbuild.gen import glob_asdl
py_meta.AssignTypes(glob_asdl, glob)
f.close()
#
# Instantiate core/runtime.asdl
#