aboutsummaryrefslogtreecommitdiff
path: root/core/text.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-30 13:52:40 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-30 13:52:40 -0700
commit0d48b5add8b24b300ea3fd46290c25902d4f6720 (patch)
treeeeb553c25a4ac590d21861977fde976d6e228fae /core/text.nom
parentaafce3a76584d16950a19f81d8f62ca5c4bb1dca (diff)
Added parens for correctness and methods for accessing bytes and making
uppercase.
Diffstat (limited to 'core/text.nom')
-rw-r--r--core/text.nom24
1 files changed, 19 insertions, 5 deletions
diff --git a/core/text.nom b/core/text.nom
index 4373982..237c395 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -41,12 +41,26 @@ action [%texts joined with %glue] (..)
parse [joined %texts, %texts joined] as (%texts joined with "")
test:
- assume (("asdf" capitalized) == "Asdf") or barf "capitalized failed"
+ assume ((byte 2 of "BAR") == 65)
+ assume ((bytes 1 to 2 of "BAR") == [66, 65])
+compile [byte %i of %text] to (..)
+ Lua value "(\(%text as lua expr)):byte(\(%i as lua expr))"
+
+compile [bytes %start to %stop of %text] to (..)
+ Lua value "list{(\(%text as lua expr)):byte(\(%start as lua expr), \(%stop as lua expr))}"
+
+test:
+ assume (("asdf" capitalized) == "Asdf")
compile [capitalized %text, %text capitalized] to (..)
Lua value "((\(%text as lua expr)):gsub('%l', string.upper, 1))"
test:
+ assume (("asdf" uppercase) == "ASDF")
+compile [uppercase %text, %text uppercase] to (..)
+ Lua value "((\(%text as lua expr)):gsub('%l', string.upper))"
+
+test:
assume (("asdf" with "X" instead of "s") == "aXdf") or barf ".."
substitution failed
@@ -75,7 +89,7 @@ action [lines in %text, lines of %text] (..)
compile [for %match in %text matching %patt %body] to (..)
Lua ".."
- for \(%match as lua expr) in \(%text as lua expr):gmatch(\(%patt as lua expr)) do
+ for \(%match as lua expr) in (\(%text as lua expr)):gmatch(\(%patt as lua expr)) do
\(%body as lua statements)
\(compile as (===next %match ===))
end
@@ -85,7 +99,7 @@ compile [%expr for %match in %text matching %patt] to (..)
Lua value ".."
(function()
local ret = list{}
- for \(%match as lua expr) in \(%text as lua expr):gmatch(\(%patt as lua expr)) do
+ for \(%match as lua expr) in (\(%text as lua expr)):gmatch(\(%patt as lua expr)) do
ret[#ret+1] = \(%expr as lua statements)
end
return ret
@@ -93,10 +107,10 @@ compile [%expr for %match in %text matching %patt] to (..)
compile [%text matches %pattern] to (..)
Lua value ".."
- (\(%text as lua expr):match(\(%pattern as lua expr)) and true or false)
+ ((\(%text as lua expr)):match(\(%pattern as lua expr)) and true or false)
compile [%text matching %pattern] to (..)
- Lua value "\(%text as lua expr):match(\(%pattern as lua expr))"
+ Lua value "(\(%text as lua expr)):match(\(%pattern as lua expr))"
test:
assume ("\n" == (newline)) or barf "Text literals failed."