@@ -1,4 +1,7 @@
|
||||
# regex
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/contrib/10.regexp/cmake/")
|
||||
|
||||
find_package(REGEX)
|
||||
|
||||
if (REGEX_FOUND)
|
||||
@@ -10,4 +13,6 @@ if (REGEX_FOUND)
|
||||
list(APPEND PICRIN_CONTRIB_INITS regexp)
|
||||
list(APPEND PICRIN_CONTRIB_LIBRARIES ${REGEX_LIBRARIES})
|
||||
list(APPEND PICRIN_CONTRIB_SOURCES ${PICRIN_REGEX_SOURCES})
|
||||
add_custom_target(test-regexp for test in ${PROJECT_SOURCE_DIR}/contrib/10.regexp/t/*.scm \; do bin/picrin "$$test" \; done DEPENDS repl)
|
||||
set(CONTRIB_TESTS ${CONTRIB_TESTS} test-regexp)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
# -*- cmake -*-
|
||||
#
|
||||
# FindRegex.cmake: Try to find Regex
|
||||
#
|
||||
# Copyright (C) 2014- Yuichi Nishiwaki
|
||||
# Copyright (C) 2005-2013 EDF-EADS-Phimeca
|
||||
#
|
||||
# This library is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @author dutka
|
||||
# @date 2010-02-04 16:44:49 +0100 (Thu, 04 Feb 2010)
|
||||
#
|
||||
# - Try to find Regex
|
||||
# Once done this will define
|
||||
#
|
||||
# REGEX_FOUND - System has Regex
|
||||
# REGEX_INCLUDE_DIR - The Regex include directory
|
||||
# REGEX_LIBRARIES - The libraries needed to use Regex
|
||||
# REGEX_DEFINITIONS - Compiler switches required for using Regex
|
||||
#
|
||||
#
|
||||
# ChangeLogs:
|
||||
#
|
||||
# 2014/05/07 - Yuichi Nishiwaki
|
||||
# On Mac, it finds /System/Library/Frameworks/Ruby.framework/Headers/regex.h,
|
||||
# which was a part of superold version of glibc when POSIX standard didn't exist.
|
||||
# To avoid this behavior, we call find_path twice, searching /usr/include and
|
||||
# /usr/local/include first and if nothing was found then searching $PATH in the
|
||||
# second stage.
|
||||
#
|
||||
|
||||
IF (REGEX_INCLUDE_DIR AND REGEX_LIBRARIES)
|
||||
# in cache already
|
||||
SET(Regex_FIND_QUIETLY TRUE)
|
||||
ENDIF (REGEX_INCLUDE_DIR AND REGEX_LIBRARIES)
|
||||
|
||||
#IF (NOT WIN32)
|
||||
# # use pkg-config to get the directories and then use these values
|
||||
# # in the FIND_PATH() and FIND_LIBRARY() calls
|
||||
# FIND_PACKAGE(PkgConfig)
|
||||
# PKG_CHECK_MODULES(PC_REGEX regex)
|
||||
# SET(REGEX_DEFINITIONS ${PC_REGEX_CFLAGS_OTHER})
|
||||
#ENDIF (NOT WIN32)
|
||||
|
||||
FIND_PATH(REGEX_INCLUDE_DIR regex.h
|
||||
PATHS /usr/include /usr/local/include
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
IF (NOT REGEX_INCLUDE_DIR)
|
||||
FIND_PATH(REGEX_INCLUDE_DIR regex.h
|
||||
HINTS
|
||||
${REGEX_INCLUDEDIR}
|
||||
${PC_LIBXML_INCLUDE_DIRS}
|
||||
PATH_SUFFIXES regex
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
FIND_LIBRARY(REGEX_LIBRARIES NAMES c regex
|
||||
HINTS
|
||||
${PC_REGEX_LIBDIR}
|
||||
${PC_REGEX_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set REGEX_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Regex DEFAULT_MSG REGEX_LIBRARIES REGEX_INCLUDE_DIR)
|
||||
|
||||
MARK_AS_ADVANCED(REGEX_INCLUDE_DIR REGEX_LIBRARIES)
|
||||
@@ -0,0 +1,12 @@
|
||||
(import (scheme base)
|
||||
(picrin test)
|
||||
(picrin regexp))
|
||||
|
||||
(test #t (regexp? (regexp "simple")))
|
||||
(test #f (regexp? "it\\s[s]e+ms\\s(reg)?exp"))
|
||||
(test-values (values '("abcd" "b") '(5 6)) (regexp-match (regexp "a(b)cd") "abdacabcd"))
|
||||
(test '("a" "b" "c" "d") (regexp-split (regexp ",") "a,b,c,d"))
|
||||
(test '("a" "b" "c" "d") (regexp-split (regexp "\\.+") "a.b....c.....d"))
|
||||
(test "a b c d" (regexp-replace (regexp ",") "a,b,c,d" " "))
|
||||
(test "newline tab space " (regexp-replace (regexp "\\s") "newline
|
||||
tab space " " "))
|
||||
@@ -1,2 +1,4 @@
|
||||
file(GLOB FOR_FILES ${PROJECT_SOURCE_DIR}/contrib/20.for/piclib/*.scm)
|
||||
list(APPEND PICLIB_CONTRIB_LIBS ${FOR_FILES})
|
||||
add_custom_target(test-for for test in ${PROJECT_SOURCE_DIR}/contrib/20.for/t/*.scm \; do bin/picrin "$$test" \; done DEPENDS repl)
|
||||
set(CONTRIB_TESTS ${CONTRIB_TESTS} test-for)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
(import (scheme base)
|
||||
(picrin control list)
|
||||
(picrin test))
|
||||
|
||||
(test '(1 2 3)
|
||||
(for
|
||||
(yield (in '(1 2 3)))))
|
||||
|
||||
(test '((1 a) (1 b) (1 c) (2 a) (2 b) (2 c) (3 a) (3 b) (3 c))
|
||||
(for
|
||||
(let ((n (in '(1 2 3)))
|
||||
(c (in '(a b c))))
|
||||
(yield (list n c)))))
|
||||
|
||||
(test '((2 a) (2 b) (2 c))
|
||||
(for
|
||||
(let ((n (in '(1 2 3)))
|
||||
(c (in '(a b c))))
|
||||
(if (even? n)
|
||||
(yield (list n c))
|
||||
(null)))))
|
||||
Reference in New Issue
Block a user