GithubHelp home page GithubHelp logo

emlai / emregex Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 225 KB

Simple regular expression engine in C

License: The Unlicense

CMake 4.35% C 74.57% Ruby 21.08%
regex regular-expression c regular-expression-engine

emregex's Introduction

emregex

Build Status Coverage Status

This is a simple public domain regex engine library and command-line tool, implemented in the C programming language without any external dependencies aside from the C standard library. It is far from full-featured, and there are currently still some known bugs (listed here). For information about the internals of this project, check the contents of the doc directory. Online documentation for the libemregex API can be found here.

Building from source

  1. The following dependencies are needed: a C compiler and CMake. To run the tests you also need Ruby.
  2. Run cmake -G "Unix Makefiles" . to generate a build system. If you wish to compile a release build with optimizations, add the flag -DCMAKE_BUILD_TYPE=Release to the command.
  3. Run make to build everything. This will generate an emregex executable in the project root directory.
  4. Run ctest --output-on-failure to run the tests, reporting any errors in case of test failure. make test can also be used to run the tests, but it doesn't print any error messages for failing test cases.

Usage

The emregex executable works pretty much like grep, except that it matches the whole input string, and currently only reads from standard input. This means that the most useful way to use it is to pipe something to it, e.g. like this:

echo "text to match" | ./emregex "regex pattern"

The program prints match and exits with the status 0 if the given string matches the regex passed as the argument, or no match with a non-zero exit status if it doesn't.

You can also print the abstract syntax tree of the parsed regex pattern by invoking emregex with the --print-ast flag. This might be useful for e.g. debugging the program.

emregex's People

Contributors

emlai avatar

Stargazers

 avatar

Watchers

 avatar  avatar

emregex's Issues

Vertaisarviointi

2.9.2017 20:55

Koodisi on selkeää ja fiksusti toteutettua. Muistinhallinta ja taulukon laajennus on hyvin toteutettu parseSeq funktiossa.

parseSeq-funktiossa on tosin bugi, joka johtaa segfaulttiin. Mikäli syötteessä on yksi ylimääräinen avaava sulku ja parseSeq funktiota kutsutaan seuraavasti: parseSeq(&node,')'), parseSeq lukee nollatavun yli ja osuu laittomaan muistialueeseen.
Asian voi korjata vertaamalla parseSeqin while-loopissa tokenia sekä annettuun terminator-muuttujaan että nollatavuun.

Samanlainen bugi on myös parseRange-funktiossa, kohdassa, jossa tarkistetaan useaa vaihtoehtoista merkkiä hakasulkeiden sisällä. Tällöin, jos sulkevaa hakasulkua ei ole, päädytään taas sallitun muistin ulkopuolelle. Tämän voi korjata samalla tavalla vertaamalla reRBracketin lisäksi myös nollatavuun.

Lisäksi kannattaisi muuttaa else parseRange-funktiossa else if (ch != 0):ksi, jotta vältyttäisiin nollan yli lukemiselta elsen sisällä.

static reNode parseRange(void) {
    reNode node;
    node.lowerbound = lex();
    int ch = lex();
    if (ch == '-') {
        // Contiguous range expressed with a hyphen, e.g. [a-z].
        node.type = reRange;
        node.upperbound = lex();
        if (lex() != reRBracket) error("expected ']' to terminate range");
    } else {
...

Muuten koodisi on melko idiomaattista ja selkeää C:tä, ja globaalin muuttujan root käyttö toimii hyvin kirjastossa.

Koodikatselmointi 2

Moi

ladattu 19.2. 14:30

Ohjelma kääntyi hyvin, eikä virheitä tullut. Testejä en kuitenkaan saanut
toimimaan (ruby 2.3.1), "make test" tuotti virheilmoituksen

Makefile:61: recipe
for target 'test' failed make: *** [test] Error 8

Muutamilla eri lausekkeilla kokeillen ohjelma vaikuttaa toimivan odotetusti.

Itse koodia oli tosi helppo lukea. Kommentointi oli kattavaa ja ohjelman rakenne
vaikutti järkevältä. Myös Testejä näyttää olevan laajasti, rajatapauksille ja
erilaisille syötteille.

Readmehen voisi varmaan lisätä vielä lyhyesti ohjelman käytöstä. Käyttö ei ole
monimutkaista, mutta on mukavampi suorittaa ohjelma kun tietää vähän mitä
odottaa.

Jos aikaa riittää, niin vaikkapa grep-tyylinen väritys matchaaviin osioihin
voisi olla kiva. En osaa kyllä sanoa kuinka helppo/vaikea tälläinen ominaisuus
on tehdä.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.