Skip to content

Commit

Permalink
Add V implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rrthomas committed Jul 20, 2022
1 parent 645afdc commit 1c2d3e7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.v]
indent_style = tab
indent_size = 4
47 changes: 47 additions & 0 deletions v/syms.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module main

import os
import flag
import regex // FIXME: use POSIX regexs

import v.vmod
const manifest = vmod.from_file('v.mod') or { panic(err) }

[noreturn]
fn error_exit(code int, msg string) {
eprintln(msg)
exit(code)
}

fn main() {
mut fp := flag.new_flag_parser(os.args)
fp.application(manifest.name)
fp.version(manifest.version)
fp.description(manifest.description)
default_symbol := '[\\a\\A]+'
symbol := fp.string('symbol', `s`, default_symbol, 'symbols are given by REGEXP')
mut re := regex.regex_opt(symbol) or {
error_exit(1, 'invalid regex $symbol')
}
fp.footer('
The default symbol type is words (-s "$default_symbol"); other useful settings include:
non-white-space characters: -s "[\\S]+"
alphanumerics and underscores: -s "\\w+"
XML tags: -s "<([\\a\\a_:][\\w:.-]*)[\\s>]"')
fp.skip_executable()

additional_args := fp.finalize() ?
for file in additional_args {
// FIXME: read one line at a time
lines := os.read_lines(file) or {
error_exit(1, 'cannot open \'$file\'')
}
for l in lines {
// FIXME: read one symbol at a time
for sym in re.find_all_str(l) {
println(sym)
}
}
}
}
7 changes: 7 additions & 0 deletions v/v.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Module {
name: 'syms'
description: 'List symbols in input'
version: '0.0.0'
license: 'GPLv3+'
dependencies: []
}

0 comments on commit 1c2d3e7

Please sign in to comment.