Skip to content

Commit c75948e

Browse files
authored
Merge pull request #108 from jakobnissen/automav1
Bump Automa to v1
2 parents 9708b15 + bad08be commit c75948e

File tree

3 files changed

+30
-43
lines changed

3 files changed

+30
-43
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
1717

1818
[compat]
1919
AbstractTrees = "0.3, 0.4"
20-
Automa = "0.8"
20+
Automa = "1"
2121
DataStructures = "0.18"
2222
FreeTypeAbstraction = "0.10"
2323
GeometryBasics = "0.4.1"

src/MathTeXEngine.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ using FreeTypeAbstraction
88
using LaTeXStrings
99
using UnicodeFun
1010

11-
using Automa.RegExp: @re_str
1211
using DataStructures: Stack
1312
using GeometryBasics: Point2f, Rect2f
1413
using REPL.REPLCompletions: latex_symbols
@@ -20,8 +19,6 @@ import FreeTypeAbstraction:
2019
height_insensitive_boundingbox, leftinkbound, rightinkbound,
2120
topinkbound, bottominkbound
2221

23-
const re = Automa.RegExp
24-
2522
export TeXExpr, texparse
2623
export TeXElement, TeXChar, VLine, HLine, generate_tex_elements
2724
export texfont

src/parser/parser.jl

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,38 +53,31 @@ function show_debug_info(stack, position, data, action_name)
5353
show_state(stack, position, data)
5454
end
5555

56-
# Super and subscript
57-
super = re"\^"
58-
super.actions[:exit] = [:end_command_builder, :setup_decorated, :begin_super]
59-
60-
sub = re"_"
61-
sub.actions[:exit] = [:end_command_builder, :setup_decorated, :begin_sub]
62-
63-
# Groups
64-
lbrace = re"{"
65-
lbrace.actions[:exit] = [:end_command_builder, :begin_group]
66-
67-
rbrace = re"}"
68-
rbrace.actions[:exit] = [:end_command_builder, :end_group, :end_token]
69-
70-
# Commands
71-
bslash = re"\\"
72-
bslash.actions[:exit] = [:end_command_builder, :begin_command_builder]
73-
74-
command_char = re"[A-Za-z]"
75-
command_char.actions[:exit] = [:push_char, :end_token]
76-
77-
# Characters
78-
space = re" "
79-
space.actions[:exit] = [:end_command_builder, :push_space]
80-
special_char = lbrace | rbrace | bslash | super | sub | command_char | space
81-
other_char = re"." \ special_char
82-
other_char.actions[:exit] = [:end_command_builder, :push_char, :end_token]
83-
84-
mathexpr = re.rep(special_char | other_char)
85-
mathexpr.actions[:exit] = [:end_command_builder]
86-
87-
machine = Automa.compile(mathexpr)
56+
machine = let
57+
# Super and subscript
58+
super = onexit!(re"\^", [:end_command_builder, :setup_decorated, :begin_super])
59+
sub = onexit!(re"_", [:end_command_builder, :setup_decorated, :begin_sub])
60+
61+
# Groups
62+
lbrace = onexit!(re"{", [:end_command_builder, :begin_group])
63+
rbrace = onexit!(re"}", [:end_command_builder, :end_group, :end_token])
64+
65+
# Commands
66+
bslash = onexit!(re"\\", [:end_command_builder, :begin_command_builder])
67+
command_char = onexit!(re"[A-Za-z]", [:push_char, :end_token])
68+
69+
# Characters
70+
space = onexit!(re" ", [:end_command_builder, :push_space])
71+
special_char = lbrace | rbrace | bslash | super | sub | command_char | space
72+
other_char = onexit!(
73+
re"." \ special_char,
74+
[:end_command_builder, :push_char, :end_token]
75+
)
76+
77+
mathexpr = onexit!(Automa.rep(special_char | other_char), :end_command_builder)
78+
79+
Automa.compile(mathexpr)
80+
end
8881

8982
current(stack) = first(stack)
9083
current_head(stack) = head(current(stack))
@@ -283,22 +276,19 @@ end
283276

284277
actions = Dict(actions...)
285278

286-
context = Automa.CodeGenContext()
287279
@eval function texparse(data ; showdebug=false)
288280
# Allows string to start with _ or ^
289281
if !isempty(data) && (data[1] == '_' || data[1] == '^')
290282
data = "{}" * data
291283
end
292284

293-
$(Automa.generate_init_code(context, machine))
294-
p_end = p_eof = lastindex(data)
295-
285+
$(Automa.generate_init_code(machine))
296286
# Needed to avoid problem with multi bytes unicode chars
297287
stack = Stack{Any}()
298288
push!(stack, TeXExpr(:expr))
299289

300290
try
301-
$(Automa.generate_exec_code(context, machine, actions))
291+
$(Automa.generate_exec_code(machine, actions))
302292
catch
303293
throw(TeXParseError("unexpected error while parsing", stack, p, data))
304294
end
@@ -310,7 +300,7 @@ context = Automa.CodeGenContext()
310300
if length(stack) > 1
311301
err = TeXParseError(
312302
"end of string reached with unfinished $(current(stack).head)",
313-
stack, p_eof, data)
303+
stack, p, data)
314304
throw(err)
315305
end
316306

@@ -339,4 +329,4 @@ Setting `showdebug` to `true` show a very verbose break down of the parsing.
339329
Parse a LaTeXString composed of a single LaTeX math expression into nested
340330
TeXExpr.
341331
"""
342-
texparse(data::LaTeXString ; showdebug=false) = texparse(data[2:end-1] ; showdebug=showdebug)
332+
texparse(data::LaTeXString ; showdebug=false) = texparse(data[2:end-1] ; showdebug=showdebug)

0 commit comments

Comments
 (0)