# Tag Info

1

Lexicon I'm a fan of using common terminology for best practices. You are creating a lexer rather than a parser. Parser: Within computational linguistics the term is used to refer to the formal analysis by a computer of a sentence or other string of words into its constituents, resulting in a parse tree showing their syntactic relation to each other, which ...

3

I know you said you were fine with not using a parser combinator library like parsec, but I thought you might like to see the how the same thing might look using one, so I wrote an Attoparsec based parser for your data types: {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} module IniParser where import Control.Monad ...

2

Just a few comments – not a full review: parseToIni :: T.Text -> Ini indicates that from any random string, parseToIni can produce an Ini. This makes me wonder how it would handle an invalid .ini file, or e.g. the string foo. In updateSection :: Maybe Section -> T.Text -> Maybe Section the Maybes obfuscate what the function is supposed to do. Can ...

4

Style Your placement of the parameters in a function definition isn't consistent. The typical convention, across languages, is no space between the name and the (. There is no "standard" style for Lua, though, so if you want to put a space before, go ahead! Just do it on all of your functions, and not just most of them. A useful style is to use "trailing ...

0

Bug: singleton objects have no allocation record Since the garbage collector will try to set the mark() in a SYMBOL object, the T_ object needs a dummy allocation record. NIL_ doesn't need one since an INVALID object will not get marked. pc9obj.c: object T_ = &(1[(union uobject[]){{ .t = 0 },{ .Symbol = { SYMBOL, T, "T" } }}]), NIL_ = (union ...

1

I don't have time to check all now but I found some things I want to share If you are using C++17 consider using std::variant instead of the weak union inherited from c. It will probaly also solve youre isue with std::string. See: https://en.cppreference.com/w/cpp/utility/variant Consider using '\n' instead of std::endl. Im pretty sure you only want a ...

0

it is a poor programming practice to include header files those contents are not used. I.E. in the posted code, the contents of the header file: string.h are not being used. Suggest removing the statement: #include <string.h>

5

If you don't need fields other than size, and have no use for lines with no size, a simpler regex like \s(\d+)$is going to be appreciably faster. You could even go with \s(\d{4,})$ and skip the >= 1000 test. If you do keep the full regex, I'd simplify the date portion because date formats are notoriously unpredictable. $[^]]+$ does the job more ...

3

You can get the value for ASCII_POS_OF_0 easily by using '0'. Your code doesn't deal with malformed strings well. If the string is only "123" it will attempt to read beyond the contents of the string. You can fix this by checking for '\0' at the correct places. It also doesn't handle any type of whitespace in the string at all.

4

Apart from the other alternative of using pathlib Here are some comments on the code: rsplit strings have also a method [str.rsplit][1] which start at the right side of the string. So extracting the parent and leaf is as simple as: parent, leaf = path.rsplit(delimiter, maxsplit=1) delimiter Instead of hardcoding the delimiter in a few places, you ...

10

PurePath.drive allows UNC drives, but yours doesn't. pathlib implements everything you need. Which is available from Python 3.4. Note: This code doesn't require the drive to be set. That can be achieved by checking PurePath.drive if it is needed. from pathlib import PurePath def parse_file_path(path): path = PurePath(path) return str(path.parent), ...

1

See, I saw your question on StackOverflow the other day before it was moved here but thought to answer nevertheless. Imo, the way to go is to write yourself a grammar/parser and a NodeVisitor class. This is formulate little parts in a first step and then glue them all together afterwards. from parsimonious.grammar import Grammar from parsimonious.nodes ...

3

I have written parsers for several similar file formats, and one time I started with the same idea as you: iterate over the lines and record the current state in some boolean variables. Over time, these parsers got too large to understand. Therefore I switched to a different strategy: instead of recording the current state in variables, record it implicitly ...

2

(I only looked at the GitHub repository ...) Ah you've got go vet already on, that's why it's not finding anything, great! Dockerfile looks good too. You might want to specify an exact Go version just in case. main.go looks fine to me. Only the unused return value from router.Run() would pop up depending on your linter settings, which you could ...

0

(Disclamer: I only know Kotlin theoretically) You can avoid the second try/catch by using String.toIntOrNull instead of String.toInt. And by extracting the LocalDateTime conversion into a separate function, that also returns null when it fails (which also would help fulfill the single responsibility principle), you could then use a functional approach with ...

4

First, a standard approach for dealing with the skipSpaces issue is to define a higher-order parser combinator, traditionally called lexeme: lexeme :: ReadP a -> ReadP a lexeme p = p <* skipSpaces Here, lexeme takes a space-naive parser p, and converts it into a new parser that parses whatever p was planning to parse, and then reads and discards any ...

Top 50 recent answers are included