Skip to content

Commit

Permalink
LittleDicts
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Oct 2, 2019
1 parent ecd5b76 commit 52abcda
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/JuDoc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using Markdown: htmlesc
using Dates # see jd_vars
using DelimitedFiles: readdlm
using OrderedCollections
using Pkg

import LiveServer

Expand All @@ -32,7 +33,7 @@ const FULL_PASS = Ref(true)
const SUPPRESS_ERR = Ref(false)

"""Dict to keep track of languages and how comments are indicated and their extensions."""
const CODE_LANG = Dict{String,NTuple{2,String}}(
const CODE_LANG = LittleDict{String,NTuple{2,String}}(
"c" => (".c", "//"),
"cpp" => (".cpp", "//"),
"fortran" => (".f90", "!"),
Expand All @@ -58,7 +59,7 @@ else
end

"""Type of the containers for page variables (local and global)."""
const PageVars = Dict{String,Pair{K,NTuple{N, DataType}} where {K, N}}
const PageVars = LittleDict{String,Pair{K,NTuple{N, DataType}} where {K, N}}

"""Relative path to the current file being processed by JuDoc."""
const CUR_PATH = Ref("")
Expand Down
2 changes: 1 addition & 1 deletion src/converter/html_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Dictionary for special html functions. They can take two variables, the first on
arguments passed to the function, the second one `ν` refers to the page variables (i.e. the
context) available to the function.
"""
const HTML_FUNCTIONS = Dict{String, Function}(
const HTML_FUNCTIONS = LittleDict{String, Function}(
"fill" => ((π, ν) -> hfun_fill(π, ν)),
"insert" => ((π, _) -> hfun_insert(π)),
"href" => ((π, _) -> hfun_href(π)),
Expand Down
6 changes: 3 additions & 3 deletions src/converter/lx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ PAGE_EQREFS
Dictionary to keep track of equations that are labelled on a page to allow references within the
page.
"""
const PAGE_EQREFS = Dict{String, Int}()
const PAGE_EQREFS = LittleDict{String, Int}()


"""
Expand Down Expand Up @@ -86,7 +86,7 @@ PAGE_BIBREFS
Dictionary to keep track of bibliographical references on a page to allow citation within the page.
"""
const PAGE_BIBREFS = Dict{String, String}()
const PAGE_BIBREFS = LittleDict{String, String}()

"""
$(SIGNATURES)
Expand Down Expand Up @@ -145,7 +145,7 @@ LXCOM_HREF
Dictionary for latex commands related to hyperreference for which a specific replacement that
depends on context is constructed.
"""
const LXCOM_HREF = Dict{String, Function}(
const LXCOM_HREF = LittleDict{String, Function}(
"\\eqref" =>-> form_href(λ, "EQR"; class="eqref")),
"\\cite" =>-> form_href(λ, "BIBR"; parens=""=>"", class="bibref")),
"\\citet" =>-> form_href(λ, "BIBR"; parens=""=>"", class="bibref")),
Expand Down
4 changes: 2 additions & 2 deletions src/converter/lx_simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ $SIGNATURES
Dictionary of functions to use for different default latex-like commands. The output of these
commands is inserted "as-is" (without re-processing) in the HTML.
"""
const LXCOM_SIMPLE = Dict{String, Function}(
const LXCOM_SIMPLE = LittleDict{String, Function}(
"\\output" => resolve_lx_output, # include plain output generated by code
"\\figalt" => resolve_lx_figalt, # include a figure (may or may not have been generated)
"\\file" => resolve_lx_file, # include a file
Expand All @@ -169,7 +169,7 @@ $SIGNATURES
Same as [`LXCOM_SIMPLE`](@ref) except the output is re-processed before being inserted in the HTML.
"""
const LXCOM_SIMPLE_REPROCESS = Dict{String, Function}(
const LXCOM_SIMPLE_REPROCESS = LittleDict{String, Function}(
"\\textoutput" => resolve_lx_textoutput, # include output generated by code and reproc
"\\textinput" => resolve_lx_textinput,
)
5 changes: 5 additions & 0 deletions src/converter/md.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ function convert_md(mds::String, pre_lxdefs::Vector{LxDef}=Vector{LxDef}();
# as they are in the HTML later
sp_chars = find_special_chars(tokens)

#> 6. if LOCAL_PAGE_VARS["activate"], activate an environment for the page
# if !recursive && LOCAL_PAGE_VARS["activate"]
# Pkg.activate(joinpath())
# end

#
# Forming of the html string
#
Expand Down
8 changes: 4 additions & 4 deletions src/converter/md_blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ replacement.
For instance, `\$ ... \$` will become `\\( ... \\)` chopping off 1 character at the front and the
back (`\$` sign).
"""
const MATH_BLOCKS_PARENS = Dict{Symbol, Tuple{Int,Int,String,String}}(
const MATH_BLOCKS_PARENS = LittleDict{Symbol, Tuple{Int,Int,String,String}}(
:MATH_A => ( 1, 1, "\\(", "\\)"),
:MATH_B => ( 2, 2, "\\[", "\\]"),
:MATH_C => ( 2, 2, "\\[", "\\]"),
Expand Down Expand Up @@ -123,9 +123,9 @@ $(SIGNATURES)
Helper function for the code block case of `convert_block`.
"""
function convert_code_block(ss::SubString)::String
fencer = ifelse(startswith(ss, "`````"), "`````", "```")
reg = Regex("$fencer([a-z-]*)(\\:[a-zA-Z\\\\\\/-_\\.]+)?\\s*\\n?((?:.|\\n)*)$fencer")
m = match(reg, ss)
fence = ifelse(startswith(ss, "`````"), "`````", "```")
reg = Regex("$fence([a-z-]*)(\\:[a-zA-Z\\\\\\/-_\\.]+)?\\s*\\n?((?:.|\\n)*)$fence")
m = match(reg, ss)
lang = m.captures[1]
rpath = m.captures[2]
code = m.captures[3]
Expand Down
5 changes: 3 additions & 2 deletions src/jd_paths.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Dictionary for the paths of the input folders and the output folders. The simple
requires the main input folder to be defined i.e. `PATHS[:src]` and infers the others via the
`set_paths!()` function.
"""
const PATHS = Dict{Symbol,String}()
const PATHS = LittleDict{Symbol,String}()


"""
Expand All @@ -38,7 +38,7 @@ $(SIGNATURES)
This assigns all the paths where files will be read and written with root the `FOLDER_PATH`
which is assigned at runtime.
"""
function set_paths!()::Dict{Symbol,String}
function set_paths!()::LittleDict{Symbol,String}
@assert isassigned(FOLDER_PATH) "FOLDER_PATH undefined"
@assert isdir(FOLDER_PATH[]) "FOLDER_PATH is not a valid path"

Expand All @@ -55,6 +55,7 @@ function set_paths!()::Dict{Symbol,String}
PATHS[:css] = joinpath(PATHS[:folder], "css")
PATHS[:libs] = joinpath(PATHS[:folder], "libs")
PATHS[:assets] = joinpath(PATHS[:folder], "assets")
PATHS[:envs] = joinpath(PATHS[:assets], "envs")

return PATHS
end
9 changes: 5 additions & 4 deletions src/jd_vars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ is processed.
LOCAL_PAGE_VARS["date"] = Pair(Date(1), (String, Date, Nothing))
LOCAL_PAGE_VARS["lang"] = Pair("julia", (String,)) # default lang for indented code
LOCAL_PAGE_VARS["reflinks"] = Pair(true, (Bool,)) # whether there are reflinks or not
LOCAL_PAGE_VARS["activate"] = Pair(false, (Bool,)) # whether to activate an environment

# RSS 2.0 item specs:
# only title, link and description must be defined
Expand Down Expand Up @@ -102,7 +103,7 @@ PAGE_HEADERS
Keep track of seen headers. The key amounts to the ordering (~ordered dict), the value contains
the title, the refstring version of the title, the occurence number and the level (1, ..., 6).
"""
const PAGE_HEADERS = Dict{Int,Tuple{AS,AS,Int,Int}}()
const PAGE_HEADERS = LittleDict{Int,Tuple{AS,AS,Int,Int}}()

"""
$(SIGNATURES)
Expand Down Expand Up @@ -155,7 +156,7 @@ GLOBAL_LXDEFS
List of latex definitions accessible to all pages. This is filled when the config file is read
(via manager/file_utils/process_config).
"""
const GLOBAL_LXDEFS = Dict{String, LxDef}()
const GLOBAL_LXDEFS = LittleDict{String, LxDef}()


"""
Expand Down Expand Up @@ -246,9 +247,9 @@ The entries in `assignments` are of the form `KEY => STR` where `KEY` is a strin
# Example:
```julia-repl
julia> d = Dict("a"=>(0.5=>(Real,)), "b"=>("hello"=>(String,)));
julia> d = LittleDict("a"=>(0.5=>(Real,)), "b"=>("hello"=>(String,)));
julia> JuDoc.set_vars!(d, ["a"=>"5.0", "b"=>"\"goodbye\""])
Dict{String,Pair{K,Tuple{DataType}} where K} with 2 entries:
LittleDict{String,Pair{K,Tuple{DataType}} where K} with 2 entries:
"b" => "goodbye"=>(String,)
"a" => 5.0=>(Real,)
```
Expand Down
2 changes: 1 addition & 1 deletion src/manager/rss_generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct RSSItem
pubDate::Date # note: should respect RFC822 (https://www.w3.org/Protocols/rfc822/)
end

const RSS_DICT = Dict{String,RSSItem}()
const RSS_DICT = LittleDict{String,RSSItem}()


"""Convenience function for fallback fields"""
Expand Down
4 changes: 2 additions & 2 deletions src/parser/html_tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ HTML_1C_TOKENS
Dictionary of single-char tokens for HTML. Note that these characters are
exclusive, they cannot appear again in a larger token.
"""
const HTML_1C_TOKENS = Dict{Char, Symbol}()
const HTML_1C_TOKENS = LittleDict{Char, Symbol}()


"""
Expand All @@ -13,7 +13,7 @@ HTML_TOKENS
Dictionary of tokens for HTML. Note that for each, there may be several possibilities to consider
in which case the order is important: the first case that works will be taken.
"""
const HTML_TOKENS = Dict{Char, Vector{TokenFinder}}(
const HTML_TOKENS = LittleDict{Char, Vector{TokenFinder}}(
'<' => [ isexactly("<!--") => :COMMENT_OPEN ], # <!-- ...
'-' => [ isexactly("-->") => :COMMENT_CLOSE ], # ... -->
'{' => [ isexactly("{{") => :H_BLOCK_OPEN ], # {{
Expand Down
8 changes: 4 additions & 4 deletions src/parser/md_tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MD_1C_TOKENS
Dictionary of single-char tokens for Markdown. Note that these characters are exclusive, they
cannot appear again in a larger token.
"""
const MD_1C_TOKENS = Dict{Char, Symbol}(
const MD_1C_TOKENS = LittleDict{Char, Symbol}(
'{' => :LXB_OPEN,
'}' => :LXB_CLOSE,
'\n' => :LINE_RETURN,
Expand All @@ -17,7 +17,7 @@ MD_TOKENS_LX
Subset of `MD_1C_TOKENS` with only the latex tokens (for parsing what's in a math environment).
"""
const MD_1C_TOKENS_LX = Dict{Char, Symbol}(
const MD_1C_TOKENS_LX = LittleDict{Char, Symbol}(
'{' => :LXB_OPEN,
'}' => :LXB_CLOSE
)
Expand All @@ -29,7 +29,7 @@ MD_TOKENS
Dictionary of tokens for Markdown. Note that for each, there may be several possibilities to
consider in which case the order is important: the first case that works will be taken.
"""
const MD_TOKENS = Dict{Char, Vector{TokenFinder}}(
const MD_TOKENS = LittleDict{Char, Vector{TokenFinder}}(
'<' => [ isexactly("<!--") => :COMMENT_OPEN, # <!-- ...
],
'-' => [ isexactly("-->") => :COMMENT_CLOSE, # ... -->
Expand Down Expand Up @@ -131,7 +131,7 @@ const L_RETURNS = (:LINE_RETURN, :LR_INDENT)
"""
MD_OCB
Dictionary of Open-Close Blocks whose content should be deactivated (any token within their span
List of Open-Close Blocks whose content should be deactivated (any token within their span
should be marked as inactive) until further processing.
The keys are identifier for the type of block, the value is a pair with the opening and closing
tokens followed by a boolean indicating whether the content of the block should be reprocessed.
Expand Down
4 changes: 2 additions & 2 deletions src/parser/tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ that match specific tokens. The list of tokens found is returned.
* `stokens_dict`: dictionaro of possible tokens (single character)
"""
function find_tokens(str::AS,
tokens_dict::Dict{Char,Vector{TokenFinder}},
stokens_dict::Dict{Char,Symbol})::Vector{Token}
tokens_dict::AbstractDict{Char,Vector{TokenFinder}},
stokens_dict::AbstractDict{Char,Symbol})::Vector{Token}
# storage to keep track of the tokens found
tokens = Vector{Token}()

Expand Down

0 comments on commit 52abcda

Please sign in to comment.