Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_ascii_letter #418

Merged
merged 18 commits into from
Dec 6, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- run: LLVM_CONFIG=llvm-config-${{ matrix.llvm-version }} make
- run: ./runtests.sh --verbose --jou-flags "${{ matrix.opt-level }}"
- run: ./runtests.sh --verbose --jou-flags "${{ matrix.opt-level }} --verbose"
# Valgrinding is slow, but many files affect valgrind resuls.
# Valgrinding is slow, but many files affect valgrind results.
# We skip it when all changes are to .md files (docs, README etc)
- name: Figure out if we need to run tests with valgrind
id: check-need-valgrind
Expand Down
4 changes: 2 additions & 2 deletions Makefile.posix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Linux has llvm-config-13, on macos brew installs LLVM to a weird place in /usr/local/
# Linux has llvm-config-13/11, on macos brew installs LLVM to a weird place in /usr/local/
LLVM_CONFIG ?= $(shell \
which llvm-config-13 \
|| which /usr/local/opt/llvm@13/bin/llvm-config \
Expand All @@ -20,7 +20,7 @@ compile_flags.txt:
echo "-I$(shell $(LLVM_CONFIG) --includedir)" > compile_flags.txt

config.h:
@v=`$(LLVM_CONFIG) --version`; case "$$v" in 11.*|13.*) ;; *) echo "Error: Found unsupported LLVM version $$v. Only LLVM 11 and LLVM 13 are supported."; exit 1; esac
@v=`$(LLVM_CONFIG) --version`; case "$$v" in 11.*|13.*) ;; *) echo "Error: Found unsupported LLVM version $$v. Only LLVM 11, 13 are supported."; exit 1; esac
echo "// auto-generated by Makefile" > config.h
echo "#define JOU_CLANG_PATH \"$(shell $(LLVM_CONFIG) --bindir)/clang\"" >> config.h

Expand Down
5 changes: 4 additions & 1 deletion stdlib/ascii.jou
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def is_ascii(s: byte*) -> bool:
def is_ascii_digit(b: byte) -> bool:
return '0' <= b and b <= '9'

# Check for 'a-z' 'A-Z'
def is_ascii_letter(b: byte) -> bool:
return ('A' <= b and b <= 'Z') or ('a' <= b and b <= 'z')

# Checks if the given byte is an ASCII punctuation character, such as '*' or '_' or '"'.
def is_ascii_punctuation(b: byte) -> bool:
return b != '\0' and strchr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", b) != NULL
Expand All @@ -35,7 +39,6 @@ def trim_ascii_whitespace(s: byte*) -> void:
memmove(s, start, len)
s[len] = '\0'


# Finds all non-whitespace parts of a string.
# For example: " foo bar baz \n" --> ["foo", "bar", "baz", NULL]
#
Expand Down
8 changes: 8 additions & 0 deletions tests/should_succeed/ascii_test.jou
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def main() -> int:
assert not is_ascii_digit('x')
assert not is_ascii_digit('\0')

assert is_ascii_letter('A')
assert is_ascii_letter('Z')
assert is_ascii_letter('a')
assert is_ascii_letter('z')
littlewhitecloud marked this conversation as resolved.
Show resolved Hide resolved
assert not is_ascii_letter('\0')
assert not is_ascii_letter('\\')
assert not is_ascii_letter('\n')

assert is_ascii_punctuation('!')
assert is_ascii_punctuation('_')
assert not is_ascii_punctuation('a')
Expand Down