diff --git a/frontend/lexer_def.py b/frontend/lexer_def.py index 6db4265b50..069d140c5e 100644 --- a/frontend/lexer_def.py +++ b/frontend/lexer_def.py @@ -207,7 +207,7 @@ def R(pat, tok_type): # These are treated like builtins in bash, but keywords in OSH. However, we # maintain compatibility with bash for the 'type' builtin. -_MORE_KEYWORDS = [ +_CONTROL_FLOW = [ C('break', Id.ControlFlow_Break), C('continue', Id.ControlFlow_Continue), C('return', Id.ControlFlow_Return), @@ -246,12 +246,13 @@ def R(pat, tok_type): # The 'compen' and 'type' builtins introspect on keywords and builtins. OSH_KEYWORD_NAMES = [name for _, name, _ in _KEYWORDS] OSH_KEYWORD_NAMES.append('{') # not in our lexer list -OTHER_OSH_BUILTINS = [name for _, name, _ in _MORE_KEYWORDS] -def IsOtherBuiltin(name): +_CF_NAMES = [name for _, name, _ in _CONTROL_FLOW] + +def IsControlFlow(name): # type: (str) -> bool - return name in OTHER_OSH_BUILTINS + return name in _CF_NAMES def IsKeyword(name): @@ -306,7 +307,7 @@ def IsKeyword(name): C(r'&>', Id.Redir_AndGreat), C(r'&>>', Id.Redir_AndDGreat), -] + _KEYWORDS + _MORE_KEYWORDS + _UNQUOTED + _EXTGLOB_BEGIN +] + _KEYWORDS + _CONTROL_FLOW + _UNQUOTED + _EXTGLOB_BEGIN # Preprocessing before Outer LEXER_DEF[lex_mode_e.Backtick] = [ diff --git a/osh/builtin_pure.py b/osh/builtin_pure.py index c9c9eb9d24..f109766104 100644 --- a/osh/builtin_pure.py +++ b/osh/builtin_pure.py @@ -278,8 +278,8 @@ def _ResolveNames(names, funcs, aliases, search_path): kind = ('builtin', name) elif consts.LookupAssignBuiltin(name) != 0: kind = ('builtin', name) - elif lexer_def.IsOtherBuiltin(name): # continue, etc. - kind = ('builtin', name) + elif lexer_def.IsControlFlow(name): # continue, etc. + kind = ('keyword', name) elif lexer_def.IsKeyword(name): kind = ('keyword', name) diff --git a/spec/builtin-bash.test.sh b/spec/builtin-bash.test.sh index c0644b48cc..18bfae4ffe 100644 --- a/spec/builtin-bash.test.sh +++ b/spec/builtin-bash.test.sh @@ -27,7 +27,7 @@ type -t foo ## stdout: alias #### type -t -> builtin -type -t echo read : [ declare local break continue +type -t echo read : [ declare local ## STDOUT: builtin builtin @@ -35,8 +35,6 @@ builtin builtin builtin builtin -builtin -builtin ## END #### type -t -> keyword @@ -50,6 +48,24 @@ keyword keyword ## END +#### type -t control flow + +# this differs from bash, but don't lie! +type -t break continue return exit +## STDOUT: +keyword +keyword +keyword +keyword +## END +## OK bash STDOUT: +builtin +builtin +builtin +builtin +## END + + #### type -t -> file type -t find xargs ## STDOUT: