You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
5 years ago | |
---|---|---|
spec | 5 years ago | |
src | 5 years ago | |
.editorconfig | 5 years ago | |
.gitignore | 5 years ago | |
.gitmodules | 5 years ago | |
.travis.yml | 5 years ago | |
LICENSE | 5 years ago | |
README.md | 5 years ago | |
compile.sh | 5 years ago | |
shard.yml | 5 years ago |
README.md
lex
Use the liblex library to tokenize text.
Installation
Add this to your application's shard.yml
:
dependencies:
lex:
git: https://dev.danilafe.com/Chip-8-Wizardry/lex.git
Usage
require "lex"
# Create a lexer
lexer = Lex::Lexer.new
# Add tokens using their regular expression and value.
# Tokens with larger value take higher priority.
lexer.add_pattern(".", 0) # Matches any one character.
lexer.add_pattern("ab+", 1) # Matches ab, abb, abbb...
lexer.add_pattern("(ab)+", 2) # Matches ab, abab, ababab...
lexer.add_pattern("ab*", 3) # Matches a, ab, abb...
lexer.add_pattern("[a-d]", 4) # matches a, b, c, d
lexer.add_pattern("[^a-d]", 5) # matches all chars but a, b, c, d
# Lex some text
tokens = lexer.lex "ab abb"
An array of tuples of type Tuple(String, Int32)
is returned.
Contributing
- Fork it (https://dev.danilafe.com/Chip-8-Wizardry/lex)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- DanilaFe Danila Fedorin - creator, maintainer