[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
help with peg module and character classes
From: |
Malte Frank Gerdes |
Subject: |
help with peg module and character classes |
Date: |
Thu, 13 Feb 2020 20:37:17 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Hey guile-user,
i'm currently trying to use the peg module to parse android bp files. I
have never used pegs before so i might have done an obvious mistake.
The current grammar looks like this:
(define-peg-string-patterns
"blueprint <-- ws* (modules* variables*)* .*
modules <-- (ws* module ws*)*
module <-- moduleName ws* map
variables <-- (ws* variable ws*)*
variable <-- identifier ws* eq ws* value
moduleName <-- 'cc_binary' / 'cc_test' / 'cc_library_headers' / 'cc_library'
/
'cc_defaults'
map <-- ws* maplb ws* attributes ws* maprb ws*
attributes <-- (ws* key ws* kvsep ws* (value / identifier) listsep? ws*)*
key <-- [a-zA-Z_]*
value <-- bool / string / integer / map / stringlist
stringlist <-- listlb ws* (ws* string listsep? ws*)* ws* listrb
bool <-- 'true' / 'false'
string <-- strdelim [-a-zA-Z/_.]* strdelim
integer <-- '-'? [0-9]+
identifier <-- [-a-zA-Z_]*
listsep < ','
listlb < '['
listrb < ']'
strdelim < '\"'
kvsep < ':'
maplb < '{'
maprb < '}'
eq < '='
ws < space+ / ('\t')+ / ('\n')+ / single
single < space* '//' space* ([-a-zA-Z0-9_(),.:;\"/] space*)* space* '\n'
space < (' ') ")
It fails to parse my test string (complete example at the end of mail),
because the string nonterminal doesn't contain numbers, if I add them
the test string gets even "less parsed" then without it.
So my question is: How do i properly use the character classes here?
Maybe i just have a confilct in that grammar, but i can't see it at the
moment ... and: Are there any predefined character classes available?
Thanks in advance for any advice :).
Malte
--------------------------------------------------------------------------------
(use-modules (ice-9 peg)
(ice-9 pretty-print)
(ice-9 rdelim))
(define *global*
"cc_library {
name: \"libcutils\",
vendor_available: true,
vndk: {
enabled: true,
support_system_process: true,
},
recovery_available: true,
host_supported: true,
srcs: [
\"config_utils.cpp\",
\"canned_fs_config.cpp\",
\"iosched_policy.cpp\",
\"load_file.cpp\",
\"native_handle.cpp\",
\"record_stream.cpp\",
\"sockets.cpp\",
\"strdup16to8.cpp\",
\"strdup8to16.cpp\",
\"strlcpy.c\",
\"threads.cpp\",
],
target: {
linux_bionic: {
enabled: true,
},
not_windows: {
srcs: libcutils_nonwindows_sources + [
\"ashmem-host.cpp\",
\"fs_config.cpp\",
\"trace-host.cpp\",
],
},
windows: {
host_ldlibs: [\"-lws2_32\"],
srcs: [
\"socket_inaddr_any_server_windows.cpp\",
\"socket_network_client_windows.cpp\",
\"sockets_windows.cpp\",
\"trace-host.cpp\",
],
enabled: true,
cflags: [
\"-D_GNU_SOURCE\",
],
},
android: {
srcs: libcutils_nonwindows_sources + [
\"android_get_control_file.cpp\",
\"android_reboot.cpp\",
\"ashmem-dev.cpp\",
\"fs_config.cpp\",
\"klog.cpp\",
\"partition_utils.cpp\",
\"properties.cpp\",
\"qtaguid.cpp\",
\"trace-dev.cpp\",
\"uevent.cpp\",
],
},
android_arm: {
srcs: [\"arch-arm/memset32.S\"],
sanitize: {
misc_undefined: [\"integer\"],
},
},
android_arm64: {
srcs: [\"arch-arm64/android_memset.S\"],
sanitize: {
misc_undefined: [\"integer\"],
},
},
android_mips: {
srcs: [\"arch-mips/android_memset.c\"],
sanitize: {
misc_undefined: [\"integer\"],
},
},
android_mips64: {
srcs: [\"arch-mips/android_memset.c\"],
sanitize: {
misc_undefined: [\"integer\"],
},
},
android_x86: {
srcs: [
\"arch-x86/android_memset16.S\",
\"arch-x86/android_memset32.S\",
],
// TODO: This is to work around b/29412086.
// Remove once __mulodi4 is available and move the \"sanitize\"
block
// to the android target.
sanitize: {
misc_undefined: [],
},
},
android_x86_64: {
srcs: [
\"arch-x86_64/android_memset16.S\",
\"arch-x86_64/android_memset32.S\",
],
sanitize: {
misc_undefined: [\"integer\"],
},
},
vendor: {
exclude_srcs: [
// qtaguid.cpp loads libnetd_client.so with dlopen(). Since
// the interface of libnetd_client.so may vary between AOSP
// releases, exclude qtaguid.cpp from the VNDK-SP variant.
\"qtaguid.cpp\",
],
}
},
shared_libs: [
\"liblog\",
\"libbase\",
],
header_libs: [
\"libbase_headers\",
\"libcutils_headers\",
\"libutils_headers\",
\"libprocessgroup_headers\",
],
export_header_lib_headers: [
\"libcutils_headers\",
\"libprocessgroup_headers\",
],
local_include_dirs: [\"include\"],
cflags: [
\"-Werror\",
\"-Wall\",
\"-Wextra\",
],
}
")
(define-peg-string-patterns
"blueprint <-- ws* (modules* variables*)* .*
modules <-- (ws* module ws*)*
module <-- moduleName ws* map
variables <-- (ws* variable ws*)*
variable <-- identifier ws* eq ws* value
moduleName <-- 'cc_binary' / 'cc_test' / 'cc_library_headers' / 'cc_library'
/
'cc_defaults'
map <-- ws* maplb ws* attributes ws* maprb ws*
attributes <-- (ws* key ws* kvsep ws* (value / identifier) listsep? ws*)*
key <-- [a-zA-Z_]*
value <-- bool / string / integer / map / stringlist
stringlist <-- listlb ws* (ws* string listsep? ws*)* ws* listrb
bool <-- 'true' / 'false'
string <-- strdelim [-a-zA-Z/_.]* strdelim
integer <-- '-'? [0-9]+
identifier <-- [-a-zA-Z_]*
listsep < ','
listlb < '['
listrb < ']'
strdelim < '\"'
kvsep < ':'
maplb < '{'
maprb < '}'
eq < '='
ws < space+ / ('\t')+ / ('\n')+ / single
single < space* '//' space* ([-a-zA-Z0-9_(),.:;\"/] space*)* space* '\n'
space < (' ') ")
(pretty-print (peg:tree (match-pattern blueprint *global*)))
- help with peg module and character classes,
Malte Frank Gerdes <=