Skip to content

Commit

Permalink
[osh/prompt] Implement \v and \V
Browse files Browse the repository at this point in the history
Knock off test case #26 in spec/prompt, contributed by Simon Leary.

(Unrelated comments about HTM8)
  • Loading branch information
Andy C committed Jan 27, 2025
1 parent 89fc3bc commit b2da0db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions data_lang/htm8-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#
# TODO:
#
# - htm8.py should use one-pass algorithm
# - micro-syntax should check all errors
# - with tests
# - and then download CommonCrawl data set?
#
# - translate to C++
# - how to handle the regexes in the lexer? Port to re2c directly?
# - for find(), do we need a C++ primitive for it?
Expand Down
12 changes: 11 additions & 1 deletion osh/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ def __init__(self, lang, version_str, parse_ctx, mem):

assert lang in ('osh', 'ysh'), lang
self.lang = lang
self.version_str = version_str
self.version_str = version_str # e.g. OSH version 0.26.0 is \V

# Calculate "0.26" for \v - shortened string that bash uses. I guess
# this saves 2 chars in OSH too.
i = version_str.rfind('.')
assert i != -1, version_str
self.version_str_short = version_str[:i]

self.parse_ctx = parse_ctx
self.mem = mem
# Cache to save syscalls / libc calls.
Expand Down Expand Up @@ -157,6 +164,9 @@ def PromptSubst(self, ch, arg=None):
r = self.lang

elif ch == 'v':
r = self.version_str_short

elif ch == 'V':
r = self.version_str

elif ch == 'A':
Expand Down
2 changes: 1 addition & 1 deletion spec/prompt.test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## compare_shells: bash
## oils_failures_allowed: 9
## oils_failures_allowed: 8

#### sh -i
# Notes:
Expand Down

0 comments on commit b2da0db

Please sign in to comment.