how to switch between the default and hidden token channels in an ANTLR grammar - switch-statement

I have a parser rule like this
if_stmt : IF_T condition THEN_T
{
/* Here I would like to change the channel and iterate through the tokens
from hidden channel*/
code.....
/* Here I would like to change it to default token channel again */
}

Related

How do I have bixby use app-launch to open google maps?

I am trying to open google maps using the on-click key from a compound card, but I don't know what to include in the payload-URI key for app-launch. The documentation uses the example which is commented out, but I do not know what to fill in for the application(google-maps).
I am getting two errors both being Unknown key message/app-launch.
This is the code we are trying to use, so that when a compound card is clicked, it opens google maps with app-launch.
// PersonSelectionView.view.bxb
input-view {
match: Spot (this)
// optional selection dialog to overwrite any other default dialog
message (Pick a spot)
render {
// used to iterate over the list of candidates
selection-of (this) {
navigation-mode {
read-none {
list-summary ("There are #{size(this)} #{value(categories)} spots near you")
item-selection-question (Which one would you like?)
}
}
where-each (one) {
// you can use conditional logic to control how candidates are displayed,
// using either a standard layout with a match pattern, or a layout macro
compound-card {
content {
map-card {
title-area {
slot1 {
text {
value("#{value (one.spotName)}")
}
}
slot3 {
single-line {
text {
value("#{value (one.distance)} Miles away")
}
}
}
}
aspect-ratio (1:1)
markers {
marker {
geo ("Location.point")
icon {
template (/images/icons/red-marker.png)
}
width (15)
height (20)
anchor-x (5)
anchor-y (15)
rotation (0)
}
}
}
paragraph {
value {
template ("#{raw(description)}")
}
style (Detail_L)
}
}
on-click {
message ("TESTING THIS MESSAGE")
app-launch {
//payload-uri ("bixby://com.android.systemui/DummySystem/punchOut")
}
}
}
}
}
}
}
An "Unknown Key" error means that the key you are trying to define is not one of the valid child keys of the key you are currently in. The reference section of the Bixby Developer Documentation provides each key with its valid child keys.
Both app-launch and message are not child keys of on-click.
app-launch cannot be defined within an on-click. It must be defined in its own result-view.
message can be defined in multiple keys but not on-click
Your on-click would need to redirect to a separate result-view which would contain the app-launch key with the correct payload-uri defined.
You would need the following to implement the behavior you described:
An Action (and backing Action Javascript) to return the URI
A Concept to hold the URI returned by the Action
A result-view with a match that matches the Concept
Example Action:
action (LaunchDefinedUri) {
description (Launches the defined uri)
type (Commit)
collect {
input (launchUri) {
type (LaunchUri)
min (Required) max (One)
}
}
output (LaunchUri)
}
Example Action Javascript:
module.exports = {
function: LaunchDefinedUri
}
function LaunchDefinedUri(launchUri) {
return launchUri
}
Example Concept:
text (LaunchUri) {
description (Uri to be launched)
}
Example Result View:
result-view {
match: LaunchUri(this)
app-launch {
payload-uri("#{value(this)}")
}
render {
nothing
}
}
As for Google Maps API in particular, the Google Maps documentation seems to provide information on how to define the correct URIs for your specific purpose and behavior.
Please look into this official library provided by the Bixby team, which provides punch-out to Google Maps.
https://bixbydevelopers.com/dev/docs/dev-guide/developers/library.navigation

How to remove the warning "this might be empty" from result view in bixby

I am showing few information to the user on card and structure has min(Optional) and I don't want to change that. There is possibility that it might be blank. But how to put it in condition in result-view. I tried like if(this.name) but then yellow line appears on condition and template both.
Using an if statement is the correct way.
For example, here is how a capsule I have written will handle an optional gameTitle property when displaying my Character structure.
if(exists(character.gameTitle)) {
cell-card {
slot2 {
content {
order (PrimarySecondary)
primary ("#{value(character.gameTitle)}")
}
}
}
}

Antlr4 - Getting name of matched rule

I'm creating a relatively simple grammar which parses and breaks down strings into sub-components. A simplified version of the grammer is shown below
stmt: location type ID;
location :
location_A
| location_B
| location_C
;
location_A : 'LOCATION TOKEN 1';
location_B : 'LOCATION TOKEN 2';
location_C : 'LOCATION TOKEN 3';
Within my listener I have implemented ExitLocation to catch the token matched by this rule, but I would also like to extract the rule name of the sub-rule with which the token was matched (i.e. location_A/B/C).
Is it possible, from within the listener, to determine which sub-rule matched the token found?
Best Wishes
Dines Madsen
Alternative labels will help you here. Decorate all alternatives with a unique #name:
location
: location_A #alt1
| location_B #alt2
| location_C #alt3
;
and in your listener and visitor, there are enter- and exit-methods created for these labels (exitAlt1(...), exitAlt2(...), ...).
Another option is to assign the result of the subrules (which are by default rule contexts) to a local variable and check that in your listeners:
location:
value = location_A
| value = location_B
| value = location_C
;
LocationContext.value then contains the matched location rule.
I ended up simply grabbing the context name from the child node. As this information is only required for debugging purposes, it should be enough:
public override void ExitLocations([NotNull] TagParserParser.LocationsContext context)
{
try
{
this.myLocationToken = context.GetText();
this.myLocationRule = context.children[0].GetType().Name;
}
catch (Exception)
{
}
}
Thank you for your suggestions.

Template per url

I'm looking for an example of how to run a custom page template for a single url in drupal 6, would be nice to have a preprocess function too.
I used the following code in a recent Drupal 6 project; it requires entries into the template.php file which resides in the root of your theme folder. Simply drop the template page you create into the root of your theme folder, and you're off. {:¬)
You may have this function specified in your template.php file already; in which case, you'd probably have to refactor to add this. Here's the function in full:
function yourThemeName_preprocess_page(&$vars) {
if (isset($vars['node'])) {
$node = $vars['node'];
$vars['template_files'] = array();
switch ($node->nid) {
case '17': /* to override a specific node ID */
$vars['template_files'][] = 'page-my-page-name';
break;
default: /* to override a content type */
switch ($node->type) {
case 'page':
$vars['template_files'][] = 'page-normal-page';
break;
case 'my_own_content_type':
$vars['template_files'][] = 'page-my-own-content-type';
break;
default:
/* take no action */
}
}
}
}
Where I've specified 'page-my-page-name', note that Drupal (or rather, PHPTemplate) will add the '.tpl.php' part automatically.
This enables you to override by node ID first (more specific), and then more generally by content type, e.g. story or page. To add more overrides, just add more cases in the right place.
Hope this helps.
Humm, you might have to use the Module Panels3 and create a landing page. You can override every element of that page (even outside content area)

Hook into Drupal registration and validate user info against business logic

I want to hook into the registration module. I already have a database of 50000 users who use my old website. Now I am migrating to Drupal.
I still haven't migrated the entries to drupal database. I will be checking against my old database.
When a user tries to register in Drupal, I need to check whether the username he gave is already present in that list of 50000 (and growing) entries. If it exists, I need to cancel the registration showing an error msg saying username exists..
Which hook should I use? If my code figures that the validation failed, How can I tell drupal to display an error msg?
Edit: I hooked into the hook_user and checked for the 'validate' op. I am able to validate and assign error messages. But it is happening for all forms. I want to validate only the new account creation form. How can I do that?
Thanks.
You should register an additional validation callback function for the registration form using hook_form_FORM_ID_alter(), somewhat like so:
// Alter the registration form
function yourModuleName_form_user_register_alter(&$form, &$form_state) {
// Add your own function to the array of validation callbacks
$form['#validate'][] = 'yourModuleName_user_register_validate';
}
// Perform your own validation
function yourModuleName_user_register_validate($form, &$form_state) {
// Extract the submitted name
$name = $form_state['values']['name'];
// Check it according to your own logic
$is_valid_name = your_check_for_valid_name();
// File error, when not valid
if (!$is_valid) {
form_set_error('name', t('Name already taken, please choose a different one'));
}
}
Henrik Opel answer work on Drupal 6. For Drupal 7 use yourModuleName_form_user_register_form_alter
Here are some examples for Drupal 7:
/**
* Implements of hook_user_insert().
*/
function foo_user_insert(&$edit, $account, $category) {
// foo_user_submit($edit, $account);
}
/**
* Implementation of hook_user_delete().
*/
function foo_user_delete($account) {
// foo_user_delete($account);
}
/**
* Implements hook_form_FORM_ID_alter().
* Form ID: user_register_form
*/
function foo_form_user_register_form_alter($form, &$form_state) {
if ($form['#user_category'] == 'account' && !isset($form['#user']->uid)) {
// Foo code
}
}
/**
* Implements hook_form_FORM_ID_alter().
* Form ID: user_profile_form
*/
function foo_form_user_profile_form_alter($form, &$form_state) {
// Set a custom form validate and submit handlers.
$form['#validate'][] = 'foo_account_validate';
$form['#submit'][] = 'foo_account_submit';
}
/**
* Implements of hook_form_alter().
* This is the same as: hook_form_FORM_ID_alter()
*/
function foo_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case "user_profile_form":
case "user_register_form":
break;
}
}
Consider using the Username Originality AJAX check module: https://www.drupal.org/project/username_check

Resources