Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hammer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sven M. Hallberg
hammer
Commits
8de5fa59
Commit
8de5fa59
authored
7 years ago
by
Andrea Shepard
Committed by
Andrea Shepard
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
name/description support for LALR backend
parent
71ec1dd0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backends/lalr.c
+69
-4
69 additions, 4 deletions
src/backends/lalr.c
with
69 additions
and
4 deletions
src/backends/lalr.c
+
69
−
4
View file @
8de5fa59
...
@@ -360,7 +360,69 @@ void h_lalr_free(HParser *parser)
...
@@ -360,7 +360,69 @@ void h_lalr_free(HParser *parser)
parser
->
backend
=
PB_PACKRAT
;
parser
->
backend
=
PB_PACKRAT
;
}
}
char
*
h_lalr_get_description
(
HAllocator
*
mm__
,
HParserBackend
be
,
void
*
param
)
{
const
char
*
format_str
=
"LALR(%zu) parser backend"
;
/* TODO fix the backend */
const
char
*
generic_descr_format_str
=
"LALR(k) parser backend (actually using the param is broken)"
;
uintptr_t
params_int
;
size_t
k
,
len
;
char
*
descr
=
NULL
;
params_int
=
(
uintptr_t
)
param
;
if
(
params_int
>
0
)
{
/* A specific k was given */
k
=
(
size_t
)
params_int
;
/* Measure how big a buffer we need */
len
=
snprintf
(
NULL
,
0
,
format_str
,
k
);
/* Allocate it and do the real snprintf */
descr
=
h_new
(
char
,
len
+
1
);
if
(
descr
)
{
snprintf
(
descr
,
len
+
1
,
format_str
,
k
);
}
}
else
{
/*
* No specific k; TODO actually have a default and fix the backend
*/
len
=
snprintf
(
NULL
,
0
,
generic_descr_format_str
);
/* Allocate and do the real snprintf */
descr
=
h_new
(
char
,
len
+
1
);
if
(
descr
)
{
snprintf
(
descr
,
len
+
1
,
generic_descr_format_str
);
}
}
return
descr
;
}
char
*
h_lalr_get_short_name
(
HAllocator
*
mm__
,
HParserBackend
be
,
void
*
param
)
{
const
char
*
format_str
=
"LALR(%zu)"
,
*
generic_name
=
"LALR(k)"
;
uintptr_t
params_int
;
size_t
k
,
len
;
char
*
name
=
NULL
;
params_int
=
(
uintptr_t
)
param
;
if
(
params_int
>
0
)
{
/* A specific k was given */
k
=
(
size_t
)
params_int
;
/* Measure how big a buffer we need */
len
=
snprintf
(
NULL
,
0
,
format_str
,
k
);
/* Allocate it and do the real snprintf */
name
=
h_new
(
char
,
len
+
1
);
if
(
name
)
{
snprintf
(
name
,
len
+
1
,
format_str
,
k
);
}
}
else
{
/* No specific k */
len
=
strlen
(
generic_name
);
name
=
h_new
(
char
,
len
+
1
);
strncpy
(
name
,
generic_name
,
len
+
1
);
}
return
name
;
}
HParserBackendVTable
h__lalr_backend_vtable
=
{
HParserBackendVTable
h__lalr_backend_vtable
=
{
.
compile
=
h_lalr_compile
,
.
compile
=
h_lalr_compile
,
...
@@ -369,12 +431,15 @@ HParserBackendVTable h__lalr_backend_vtable = {
...
@@ -369,12 +431,15 @@ HParserBackendVTable h__lalr_backend_vtable = {
.
parse_start
=
h_lr_parse_start
,
.
parse_start
=
h_lr_parse_start
,
.
parse_chunk
=
h_lr_parse_chunk
,
.
parse_chunk
=
h_lr_parse_chunk
,
.
parse_finish
=
h_lr_parse_finish
,
.
parse_finish
=
h_lr_parse_finish
,
.
copy_params
=
h_copy_numeric_param
.
copy_params
=
h_copy_numeric_param
,
/* No free_param needed, since it's not actually allocated */
/* No free_param needed, since it's not actually allocated */
};
/* Name/param resolution functions */
.
backend_short_name
=
"lalr"
,
.
backend_description
=
"LALR(k) parser backend"
,
.
get_description_with_params
=
h_lalr_get_description
,
.
get_short_name_with_params
=
h_lalr_get_short_name
};
// dummy!
// dummy!
int
test_lalr
(
void
)
int
test_lalr
(
void
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment