mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-08 12:40:25 -03:00
Compare commits
No commits in common. "88f56749177126dcb6d7017ef821a8c7574737d1" and "46d6d3f4677d8aba3452332aca9e16117fe70f9c" have entirely different histories.
88f5674917
...
46d6d3f467
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-12 22:00:49 UTC using Ameba version 1.6.1.
|
# on 2024-08-04 23:09:09 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/lexer.cr
|
- src/tartrazine.cr
|
||||||
- src/actions.cr
|
- src/actions.cr
|
||||||
Admonitions:
|
Admonitions:
|
||||||
- TODO
|
- TODO
|
||||||
@ -17,105 +17,3 @@ 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
|
|
||||||
|
@ -15,7 +15,7 @@ module Tartrazine
|
|||||||
property? standalone : Bool = false
|
property? standalone : Bool = false
|
||||||
property? surrounding_pre : Bool = true
|
property? surrounding_pre : Bool = true
|
||||||
property? wrap_long_lines : Bool = false
|
property? wrap_long_lines : Bool = false
|
||||||
property weight_of_bold : Int32 = 600
|
property? weight_of_bold : Int32 = 600
|
||||||
|
|
||||||
def format(text : String, lexer : Lexer, theme : Theme) : String
|
def format(text : String, lexer : Lexer, theme : Theme) : String
|
||||||
text = format_text(text, lexer, theme)
|
text = format_text(text, lexer, theme)
|
||||||
@ -73,7 +73,7 @@ module Tartrazine
|
|||||||
# These are true/false/nil
|
# These are true/false/nil
|
||||||
outp << "border: none;" if style.border == false
|
outp << "border: none;" if style.border == false
|
||||||
outp << "font-weight: bold;" if style.bold
|
outp << "font-weight: bold;" if style.bold
|
||||||
outp << "font-weight: #{@weight_of_bold};" if style.bold == false
|
outp << "font-weight: #{weight_of_bold};" if style.bold == false
|
||||||
outp << "font-style: italic;" if style.italic
|
outp << "font-style: italic;" if style.italic
|
||||||
outp << "font-style: normal;" if style.italic == false
|
outp << "font-style: normal;" if style.italic == false
|
||||||
outp << "text-decoration: underline;" if style.underline
|
outp << "text-decoration: underline;" if style.underline
|
||||||
|
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 = Regex.new ""
|
property pattern : Regex = Re2.new ""
|
||||||
property actions : Array(Action) = [] of Action
|
property actions : Array(Action) = [] of Action
|
||||||
property xml : String = "foo"
|
property xml : String = "foo"
|
||||||
|
|
||||||
@ -33,15 +33,12 @@ 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 = node["pattern"]
|
@pattern = Re2.new(
|
||||||
flags = Regex::Options::ANCHORED
|
node["pattern"],
|
||||||
# MULTILINE implies DOTALL which we don't want, so we
|
multiline,
|
||||||
# use in-pattern flag (?m) instead
|
dotall,
|
||||||
# flags |= Regex::Options::MULTILINE if multiline
|
ignorecase,
|
||||||
pattern = "(?m)" + pattern if multiline
|
anchored: true)
|
||||||
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
|
||||||
|
|
||||||
@ -93,4 +90,25 @@ 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…
x
Reference in New Issue
Block a user