A new example and tests: leopard

This commit is contained in:
Robin Jadoul 2016-05-30 18:51:22 +02:00
parent 83c73f1479
commit 84ea4e866c
21 changed files with 88 additions and 1 deletions

View File

@ -1,4 +1,5 @@
add_subdirectory(keywords)
add_subdirectory(SyntaxHighlighter)
add_subdirectory(leopard)
add_custom_target(examples DEPENDS keywords highlighter)
add_custom_target(examples DEPENDS keywords highlighter leopard)

View File

@ -0,0 +1,15 @@
find_program(LEXESIS_EXE Lexesis PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../build/bin")
add_custom_command(DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/lexer.lxs"
COMMAND ${LEXESIS_EXE} ARGS -d "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/lexer.lxs"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/Lexer.h" "${CMAKE_CURRENT_BINARY_DIR}/Lexer.cpp"
)
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
add_executable(leopard
EXCLUDE_FROM_ALL
main.cpp
"${CMAKE_CURRENT_BINARY_DIR}/Lexer.cpp"
)

View File

@ -0,0 +1,4 @@
# https://xkcd.com/1031/
KEYBOARD_CAP = Keyboard
KEYBOARD = [kK][eE][yY][bB][oO][aA][rR][dD]
OTHER = .|\n

30
examples/leopard/main.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "Lexer.h"
#include <iostream>
int main() {
Lexer lex(std::cin);
try {
while (true) {
Lexer::Token tok = lex.nextToken();
switch (tok.type) {
case Lexer::KEYBOARD_CAP:
std::cout << "Leopard";
break;
case Lexer::KEYBOARD:
std::cout << "leopard";
break;
case Lexer::OTHER:
std::cout << tok.content;
break;
case Lexer::nonmatching: case Lexer::ignore:
std::cout << "Impossible" << std::endl;
break; //These can never occur, just to satisfy the compiler...
}
}
}
catch (Lexer::NoMatch& err) {
std::cout << "Impossible" << std::endl;
}
catch (Lexer::NoMoreTokens& err) {
}
}

View File

@ -51,6 +51,7 @@ REGEXES_DATA = [ # (regexes, should be accepted)
EXAMPLE_TESTS = { #Mapping from test name to executable and number of available test input files
"keywords" : ("examples/keywords/keywords", 2),
"highlighter": ("examples/SyntaxHighlighter/highlighter", 1),
"leopard": ("examples/leopard/leopard", 8),
}
def make_pipeline_test(regexes, should_accept, idx):

1
tests/leopard_0.exp Normal file
View File

@ -0,0 +1 @@
Weird, my leopard just switched to chinese.

1
tests/leopard_0.in Normal file
View File

@ -0,0 +1 @@
Weird, my keyboard just switched to chinese.

1
tests/leopard_1.exp Normal file
View File

@ -0,0 +1 @@
I work with one Leopard on my desk and another in the leopardtray.

1
tests/leopard_1.in Normal file
View File

@ -0,0 +1 @@
I work with one Keyboard on my desk and another in the keyboardtray.

2
tests/leopard_2.exp Normal file
View File

@ -0,0 +1,2 @@
Ever cleaned a leopard?
They're filthy!

2
tests/leopard_2.in Normal file
View File

@ -0,0 +1,2 @@
Ever cleaned a keyboard?
They're filthy!

4
tests/leopard_3.exp Normal file
View File

@ -0,0 +1,4 @@
The IPhone virtual leopard is the fastest.
IMO...

4
tests/leopard_3.in Normal file
View File

@ -0,0 +1,4 @@
The IPhone virtual keyboarD is the fastest.
IMO...

7
tests/leopard_4.exp Normal file
View File

@ -0,0 +1,7 @@
I rarely email from my phone -- I'm so slow when I am not on a leopard.
ε
ε
ε
µµµ
ε
ε

7
tests/leopard_4.in Normal file
View File

@ -0,0 +1,7 @@
I rarely email from my phone -- I'm so slow when I am not on a keyboard.
ε
ε
ε
µµµ
ε
ε

1
tests/leopard_5.exp Normal file
View File

@ -0,0 +1 @@
My leopard died when I spilled tea on it :'(

1
tests/leopard_5.in Normal file
View File

@ -0,0 +1 @@
My keyboARD died when I spilled tea on it :'(

1
tests/leopard_6.exp Normal file
View File

@ -0,0 +1 @@
The internet got 100 times better when, thanks to an extension with a typo'd regex, my browser started replacing the word "keybaord" with "leopard".

1
tests/leopard_6.in Normal file
View File

@ -0,0 +1 @@
The internet got 100 times better when, thanks to an extension with a typo'd regex, my browser started replacing the word "keybaord" with "keyboard".

1
tests/leopard_7.exp Normal file
View File

@ -0,0 +1 @@
Problem Exists Between Leopard And Chair

1
tests/leopard_7.in Normal file
View File

@ -0,0 +1 @@
Problem Exists Between Keyboard And Chair