mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 05:22:23 +00:00
Remove Re2 hack
This commit is contained in:
parent
46d6d3f467
commit
ce6f3d29b5
106
.ameba.yml
106
.ameba.yml
@ -1,5 +1,5 @@
|
|||||||
# This configuration file was generated by `ameba --gen-config`
|
# This configuration file was generated by `ameba --gen-config`
|
||||||
# on 2024-08-04 23:09:09 UTC using Ameba version 1.6.1.
|
# on 2024-08-12 22:00:49 UTC using Ameba version 1.6.1.
|
||||||
# The point is for the user to remove these configuration records
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the reported problems are removed from the code base.
|
# one by one as the reported problems are removed from the code base.
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ Documentation/DocumentationAdmonition:
|
|||||||
Description: Reports documentation admonitions
|
Description: Reports documentation admonitions
|
||||||
Timezone: UTC
|
Timezone: UTC
|
||||||
Excluded:
|
Excluded:
|
||||||
- src/tartrazine.cr
|
- src/lexer.cr
|
||||||
- src/actions.cr
|
- src/actions.cr
|
||||||
Admonitions:
|
Admonitions:
|
||||||
- TODO
|
- TODO
|
||||||
@ -17,3 +17,105 @@ Documentation/DocumentationAdmonition:
|
|||||||
- BUG
|
- BUG
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Severity: Warning
|
Severity: Warning
|
||||||
|
|
||||||
|
# Problems found: 22
|
||||||
|
# Run `ameba --only Lint/MissingBlockArgument` for details
|
||||||
|
Lint/MissingBlockArgument:
|
||||||
|
Description: Disallows yielding method definitions without block argument
|
||||||
|
Excluded:
|
||||||
|
- pygments/tests/examplefiles/cr/test.cr
|
||||||
|
Enabled: true
|
||||||
|
Severity: Warning
|
||||||
|
|
||||||
|
# Problems found: 1
|
||||||
|
# Run `ameba --only Lint/NotNil` for details
|
||||||
|
Lint/NotNil:
|
||||||
|
Description: Identifies usage of `not_nil!` calls
|
||||||
|
Excluded:
|
||||||
|
- pygments/tests/examplefiles/cr/test.cr
|
||||||
|
Enabled: true
|
||||||
|
Severity: Warning
|
||||||
|
|
||||||
|
# Problems found: 34
|
||||||
|
# Run `ameba --only Lint/ShadowingOuterLocalVar` for details
|
||||||
|
Lint/ShadowingOuterLocalVar:
|
||||||
|
Description: Disallows the usage of the same name as outer local variables for block
|
||||||
|
or proc arguments
|
||||||
|
Excluded:
|
||||||
|
- pygments/tests/examplefiles/cr/test.cr
|
||||||
|
Enabled: true
|
||||||
|
Severity: Warning
|
||||||
|
|
||||||
|
# Problems found: 1
|
||||||
|
# Run `ameba --only Lint/UnreachableCode` for details
|
||||||
|
Lint/UnreachableCode:
|
||||||
|
Description: Reports unreachable code
|
||||||
|
Excluded:
|
||||||
|
- pygments/tests/examplefiles/cr/test.cr
|
||||||
|
Enabled: true
|
||||||
|
Severity: Warning
|
||||||
|
|
||||||
|
# Problems found: 6
|
||||||
|
# Run `ameba --only Lint/UselessAssign` for details
|
||||||
|
Lint/UselessAssign:
|
||||||
|
Description: Disallows useless variable assignments
|
||||||
|
ExcludeTypeDeclarations: false
|
||||||
|
Excluded:
|
||||||
|
- pygments/tests/examplefiles/cr/test.cr
|
||||||
|
Enabled: true
|
||||||
|
Severity: Warning
|
||||||
|
|
||||||
|
# Problems found: 3
|
||||||
|
# Run `ameba --only Naming/BlockParameterName` for details
|
||||||
|
Naming/BlockParameterName:
|
||||||
|
Description: Disallows non-descriptive block parameter names
|
||||||
|
MinNameLength: 3
|
||||||
|
AllowNamesEndingInNumbers: true
|
||||||
|
Excluded:
|
||||||
|
- pygments/tests/examplefiles/cr/test.cr
|
||||||
|
AllowedNames:
|
||||||
|
- _
|
||||||
|
- e
|
||||||
|
- i
|
||||||
|
- j
|
||||||
|
- k
|
||||||
|
- v
|
||||||
|
- x
|
||||||
|
- y
|
||||||
|
- ex
|
||||||
|
- io
|
||||||
|
- ws
|
||||||
|
- op
|
||||||
|
- tx
|
||||||
|
- id
|
||||||
|
- ip
|
||||||
|
- k1
|
||||||
|
- k2
|
||||||
|
- v1
|
||||||
|
- v2
|
||||||
|
ForbiddenNames: []
|
||||||
|
Enabled: true
|
||||||
|
Severity: Convention
|
||||||
|
|
||||||
|
# Problems found: 1
|
||||||
|
# Run `ameba --only Naming/RescuedExceptionsVariableName` for details
|
||||||
|
Naming/RescuedExceptionsVariableName:
|
||||||
|
Description: Makes sure that rescued exceptions variables are named as expected
|
||||||
|
Excluded:
|
||||||
|
- pygments/tests/examplefiles/cr/test.cr
|
||||||
|
AllowedNames:
|
||||||
|
- e
|
||||||
|
- ex
|
||||||
|
- exception
|
||||||
|
- error
|
||||||
|
Enabled: true
|
||||||
|
Severity: Convention
|
||||||
|
|
||||||
|
# Problems found: 6
|
||||||
|
# Run `ameba --only Naming/TypeNames` for details
|
||||||
|
Naming/TypeNames:
|
||||||
|
Description: Enforces type names in camelcase manner
|
||||||
|
Excluded:
|
||||||
|
- pygments/tests/examplefiles/cr/test.cr
|
||||||
|
Enabled: true
|
||||||
|
Severity: Convention
|
||||||
|
38
src/rules.cr
38
src/rules.cr
@ -11,7 +11,7 @@ module Tartrazine
|
|||||||
# This rule matches via a regex pattern
|
# This rule matches via a regex pattern
|
||||||
|
|
||||||
class Rule
|
class Rule
|
||||||
property pattern : Regex = Re2.new ""
|
property pattern : Regex = Regex.new ""
|
||||||
property actions : Array(Action) = [] of Action
|
property actions : Array(Action) = [] of Action
|
||||||
property xml : String = "foo"
|
property xml : String = "foo"
|
||||||
|
|
||||||
@ -33,12 +33,15 @@ module Tartrazine
|
|||||||
|
|
||||||
def initialize(node : XML::Node, multiline, dotall, ignorecase)
|
def initialize(node : XML::Node, multiline, dotall, ignorecase)
|
||||||
@xml = node.to_s
|
@xml = node.to_s
|
||||||
@pattern = Re2.new(
|
pattern = node["pattern"]
|
||||||
node["pattern"],
|
flags = Regex::Options::ANCHORED
|
||||||
multiline,
|
# MULTILINE implies DOTALL which we don't want, so we
|
||||||
dotall,
|
# use in-pattern flag (?m) instead
|
||||||
ignorecase,
|
# flags |= Regex::Options::MULTILINE if multiline
|
||||||
anchored: true)
|
pattern = "(?m)" + pattern if multiline
|
||||||
|
flags |= Regex::Options::DOTALL if dotall
|
||||||
|
flags |= Regex::Options::IGNORE_CASE if ignorecase
|
||||||
|
@pattern = Regex.new(pattern, flags)
|
||||||
add_actions(node)
|
add_actions(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -90,25 +93,4 @@ module Tartrazine
|
|||||||
add_actions(node)
|
add_actions(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is a hack to workaround that Crystal seems to disallow
|
|
||||||
# having regexes multiline but not dot_all
|
|
||||||
class Re2 < Regex
|
|
||||||
@source = "fa"
|
|
||||||
@options = Regex::Options::None
|
|
||||||
@jit = true
|
|
||||||
|
|
||||||
def initialize(pattern : String, multiline = false, dotall = false, ignorecase = false, anchored = false)
|
|
||||||
flags = LibPCRE2::UTF | LibPCRE2::DUPNAMES |
|
|
||||||
LibPCRE2::UCP
|
|
||||||
flags |= LibPCRE2::MULTILINE if multiline
|
|
||||||
flags |= LibPCRE2::DOTALL if dotall
|
|
||||||
flags |= LibPCRE2::CASELESS if ignorecase
|
|
||||||
flags |= LibPCRE2::ANCHORED if anchored
|
|
||||||
flags |= LibPCRE2::NO_UTF_CHECK
|
|
||||||
@re = Regex::PCRE2.compile(pattern, flags) do |error_message|
|
|
||||||
raise Exception.new(error_message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user