Questions tagged [parsing]
Use this tag for code that parses its input, or that is source for a parser generator such as yacc or lex.
1,319
questions
3
votes
1
answer
699
views
Parser Composition - a parser directive for Boost Spirit X3
While exploring Boost Spirit X3 (documentation), I noticed that I couldn't find a parser directive that composed parsers. I dug through the source code to see how the existing directives were made, ...
7
votes
1
answer
682
views
Boolean conversion for fscanf()
In answering How to do file I/O with bool in C?, I made a helper function that used fgetc() calls to substitute the missing ...
3
votes
1
answer
105
views
C-style double expression parser
The purpose of this code is to parse any expression as could appear in C that involves doubles or functions that involve only doubles.
I have written parsers before:
Command line calculator in C
...
3
votes
1
answer
93
views
HTTP Request-Line parser
I am trying to write an HTTP/1.0 (RFC 1945) parser in C, so I started with the Request-Line. Ideally, the parser should return one of the three:
The request is valid.
The request is malformed, but ...
8
votes
5
answers
17k
views
Using argparse with parameters defined in config file
I understand that and why using eval is generally considered bad practice in most cases (see e.g. here). Related questions on config files and argparse don't use ...
1
vote
1
answer
107
views
A simple parser for bencoding format
I have been learning rust sporadically for a while now and decided to write some toy projects. While browsing https://github.com/codecrafters-io/build-your-own-x I came across some bittorrent client ...
5
votes
2
answers
354
views
Parsing gateway ip from `/proc/net/route` in a docker container
In try to replicate the outcome of the following command sequence using php:
netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10
I did this using ...
2
votes
1
answer
113
views
Command-line parser with built-in error checking
Simple command-line option parser with automatic setting of variables and built-in error checking.
The story is I was working on another new project that had a lot of configurable options, as they ...
8
votes
2
answers
953
views
JVM bytecode instruction struct with serializer & parser
I am writing a java class file parsing & serialization library. As part of that i needed to implement a structure for the JVM bytecode instructions as well as come up with a way to parse & ...
26
votes
4
answers
8k
views
Filtering a large (50gb+) JSON lines file matching CIDR's
I'm trying to speed up a Python script that reads a large log file (JSON lines, 50gb+) and filter out results that match 1 of 2000 CIDR ranges.
Logfile
20 million lines
...
4
votes
1
answer
117
views
Tokeniser which yields a Range of string views
In my answer to string_view tokenizer function template I suggested that a flexible tokeniser would yield a Range that could be iterated over. This is my implementation of such a tokeniser.
...
6
votes
2
answers
105
views
String unescaping in Dyalog APL
I am adapting the following existing python parser:
...
4
votes
3
answers
3k
views
Parse a GET or POST string in C
This function takes a string from an HTTP POST or GET string, finds the specified variable, and allocates memory for the result and puts it in a string. The destination is given as an address of an ...
0
votes
0
answers
34
views
Detecting the content type of a given http body/string
I am trying to detect the content/mime type of a given Buffer/string. In other words, I am trying to guess what on earth is a given string.
My approach is somewhat brute-force:
...
4
votes
7
answers
262
views
Breaking a string expression in operator and operands
Requesting for a code review for a scala implementation.
Problem
Given an expression string made of numbers and operators +,-,/,* , break it in a list of Integer or ...
2
votes
1
answer
50
views
Parsing one UserData type to a preview
I am currently developing a web app and am using Spring as a Backend. I have some user data that is provided by one of our services and I need to display it in my frontend.
The subject of the code ...
0
votes
1
answer
75
views
Retrieve data from an XML file in Java
few months back I did a code test for a company and I quickly managed to solve it within 5-10 minutes. But, I got rejected because it wasnt "good enough".
What is good enough? they said its ...
7
votes
4
answers
426
views
Separating a String of Text into Separate Words in Python
Occasionally, we want to do a rudimentary parsing on English text; we separate the text into separate words.
...
3
votes
3
answers
631
views
Command line calculator in C
This code is an arithmetic parser as is the code in a previous question of mine. However this parser handles floating point arguments and mathematical functions, and handles them without needing to ...
4
votes
1
answer
601
views
Basic recursive descent parser in C
The purpose of this code is to evaluate simple integer expressions that make use of the C arithmetic and bitwise operators while respecting C operator precedence and parenthesis. I wrote this code ...
12
votes
1
answer
590
views
C++ Parsing with chain of responsibility
The task was to create the parser for the string input, that would return the std::vector< int > of parsed numeric results and the type of given input (e.g. numbers, division by zero error, out of ...
12
votes
1
answer
216
views
Parser for a custom scene definition format for a raytracer
For a raytracer I’ve been writing with a classmate, we use a custom scene definition format that allows specifying shapes, composite shapes, materials, lights, cameras and transform and render ...
4
votes
0
answers
168
views
constraint solving graduation using HTML Parsing, pandas, and z3
not sure if this project fits on code review, but my code is getting extremely messy, and would love some tips to clean it up!
Overview
The project is designed to take in an HTML file (a degree audit),...
7
votes
3
answers
1k
views
VB6/VBA Declaration (Dim) Syntax Parser
As part of a project I'm working on, I've implemented a class that encapsulates the syntax for a vb6/vba Dim statement.
Given a line of code, the ...
2
votes
1
answer
110
views
Powershell file parsing
I am using Powershell 7.
We have the following PowerShell script that will parse some very large file.
I no longer want to use 'Get-Content' as this is to slow.
The script below works, but it takes a ...
3
votes
1
answer
183
views
ANTLR4 grammar for Conventional Commits spec
I would like to create a grammar for the Conventional Commits spec and I would love to hear any feedback for what I wrote.
The spec has some ambiguities, I think, hence my usage of "island ...
12
votes
3
answers
7k
views
Parsing an email string
My program needs to parse an e-mail string. There are two possibilities to enter an e-mail-address. Either with the alias or without one, plain the e-mail-address.
1st possibity:
...
3
votes
2
answers
89
views
Parse a document and returning uniqueness and total number occurrences
I am parsing a document and returning
(1) uniqueness, and
(2) total number occurrence.
I believe my code can still be subjected to review. I would like a review of my code as I have even made it too ...
1
vote
2
answers
215
views
Creating a dictionary from a word document using docx
I have a word document that contains alphabetical bullet points along with the key: value that I am trying to input into a dictionary using docx.
Example:
...
0
votes
1
answer
72
views
Parsing shortcodes out of a string
I wrote this shortcode parsing and it runs in \$O(N^2)\$. Is there a way to better optimize this?
...
6
votes
2
answers
1k
views
Read a large CSV order book
I am trying to read entries of my CSV file into an entries vector whose data type is object OrderBookEntry, which is an object that stores the tokenized variables ...
7
votes
1
answer
223
views
Chess position representation with FEN parser
I'm developing a UCI chess engine and as part of my engine I need a position representation that stores the position of every piece on the board and all the information about the game, like castling ...
0
votes
1
answer
65
views
Checking several strings against a n-depth list of lists and returning one if its values
The data structure I am working with is a list of lists that is created by parsing a file.
The depth of the list can vary. The list can have n Strings before its child-value begins.
My current example ...
3
votes
1
answer
209
views
Generating indent and dedent tokens for python-style indenting code
I found lexy, a C++ template-based parser combinator, that helps a lot to build a language parser.
The problem is that lexy can only deal with context free grammar, and python indentation is not ...
4
votes
3
answers
2k
views
Quadratic equation solver in JavaScript
The task is to implement a solveEquation function, which solves the Quadratic equation. Each equality has exact 2 integer solutions. Return those numbers as an ...
2
votes
0
answers
160
views
Pillow plugin adding support for the QOI image format
Pillow is a popular library for handling images in Python. My code adds support for the QOI image format to Pillow.
Aside from loading and saving QOI images, my goal was to write a streaming decoder ...
1
vote
1
answer
72
views
State machine for parsing GitHub URL formats
A while ago, I wrote a small Rust crate for parsing & generating URLs for GitHub repositories in various formats (HTTPS, SSH, git://, etc.), with the parsing done using regular expressions with ...
2
votes
3
answers
630
views
Function to skip characters
A very simple function that can be used such that it returns a pointer to the first character on which func returned 0. However, ...
5
votes
5
answers
156
views
if you gaze long enough into strtok, strtok will gaze back into you
The tokenise function below splits a given string at the indicated delimiters. As with strtok, it modifies the string by adding <...
0
votes
0
answers
131
views
Top-down parser for arithmetic expressions
Here is a JS parser for a simple language we use at work.
For now it can only parse arithmetic expressions.
I would like to make sure I am on the right track before starting with the other constructs, ...
2
votes
2
answers
352
views
Finding an arbitrary word in a string of words given an offset
Background
Given a string (s) and an offset into that string (offset), find the whole word that can be found at the given ...
1
vote
2
answers
136
views
Parse list of UserPrincipal objects into custom class
I'm wondering how I could optimize this method that takes in a list of UserPrincipal objects, filters them by Regex and inserts the new class instance into a list. It takes 4 to 5 seconds for an input ...
4
votes
2
answers
191
views
Representing and Parsing an Open or Closed Range
I would like to represent a numeric range in C#. Either open-ended, such as "up to 35" or "100 on up" or closed-ended, such as "34 to 65". I'd like to represent the open end with NULL. Further, I'd ...
2
votes
1
answer
154
views
PHP Laravel Check if given date is a week or a regular day
I have a problem. In my project the user can copy a menu for a specific day or for a specific week. The value that will be sent to the back-end will be something like:
...
11
votes
3
answers
2k
views
Parsing expression with exponents and evaluating
I'm programming a basic command line calculator in java that can parse expressions and evaluate them, does not handle brackets yet.
For example an expression: \$9+9/2^2*5-1\$.
At this point I can ...
3
votes
5
answers
1k
views
Struct that parses full name into first name, middle name, last name and suffix
The struct below parses full name into first name, middle name, last name and suffix.
Perhaps Builder pattern is more appropriate here? I remember there was a principle referring to the number of ...
5
votes
1
answer
3k
views
Cleaning up HTML created by users
I have a system that accepts free text from users. This can either be plain text or a heavily limited subset of HTML. I've written the below with Html Agility Pack and Microsoft's AntiXss library. I ...
8
votes
1
answer
1k
views
Mathematical expression evaluator (C++)
I'm new to C++ and I decided to experiment with the language, by writing a mathematical expression evaluator, using the Shunting-Yard algorithm. A design choice that may stand out as weird is the fact ...
2
votes
2
answers
460
views
Parse a text file, and map to an out-of-scope POJO
I need to parse a file, with a standard formatting:
...
4
votes
1
answer
225
views
Parsing an IP routing report with half a million lines into a PANDAS dataframe
I have a file that has around 440K lines of data. I need to read these data and find the actual "table" in the text file. Part of the text file looks like this.
...