Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Pegparse is library to create recursive descent parser.
This provide parser base class which has helper methods.
Add this line to your application's Gemfile:
gem 'pegparse'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install pegparse
Pegparse::ParserBase
class.start_rule_symbol
.require 'pegparse'
class MyParser < Pegparse::ParserBase
def initialize(scanner_or_context)
super(scanner_or_context)
self.start_rule_symbol = :number_rule
end
def number_rule
digits = one_or_more { # digits becomes ['1', '2']
read(/[0-9]/)
}
decimal = optional { # decimal is '34'
decimal_rule()
}
return [digits.join.to_i, decimal&.to_i]
end
def decimal_rule
read('.')
read(/[0-9]+/) # decimal_rule returns '34'
end
end
MyParser.new(nil).parse(StringScanner.new('12.34')) # => [12, 34]
raed(str_or_regexp)
: Try to consume input. If success, return string. If failed, make backtrack.peek(str_or_regexp)
: Peek input. If success, return string.peek{ ... }
: Peek input. If success, return block result.optional{ ... }
: Match only available. (PEG's option operator('?'))zero_or_more{ ... }
: Repeat matching. (PEG's repeat operator('*'))one_or_more{ ... }
: Repeat matching. (PEG's repeat operator('+'))choice(proc, proc, ...)
: Choice matching (PEG's choice operator('/'))backtrack()
: Make backtrack.sp()
: Spaces. (Space charactors or comments)inline_sp()
: Spaces without line feed.deeper_sp()
: Spaces without line feed or have deeper indent than previous line.lf()
: Spaces contain line feed.separative(separator){ ... }
: Repeat matching with separator.string_like(end_pattern, normal_pattern){ ... }
: String like "" and ''. Block is for special char handlings like escaping.borrow_next_line{ ... }
: Skip current line and parse next line temporaliry. Used lines become unmatchable with normal process. (For here-document)borrowed_area()
: Only matches to lines used by borrow_next_line
.Pegparse::BiopRuleChain
: Binary operator helper class.You can see sample parser implementations under /samples
.
Use Pegparse::ParserCore#best_errors
to find parsing error location.
best_errors
returns farthest location where parsing failed.
It also returns the deepest rule name.
You can improve message by decorating your rule method with rule
.
rule def your_rule
...
end
If you want to debug your parser with VSCode by breakpoint or step-by-step execution, add this config to your launch.json. (debug gem newer than 1.4.0 required) Then all process inside gem will be skipped while VSCode step-by-step execution.
{
"type": "rdbg",
"name": "Debug specified user program with rdbg",
"request": "launch",
"script": "${workspaceFolder}/YOUR_PARSER_HERE.rb",
"args": [],
"env": {
"RUBY_DEBUG_SKIP_PATH": [
"YOUR_GEM_DIRECTORY_HERE",
],
}
}
Bug reports and pull requests are welcome on GitHub at https://github.com/jljse/pegparse.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that pegparse demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.