ALIAS and REFER

Overview of the ALIAS and REFER Operators

Use the ALIAS operator to create a set of reusable GLASS expressions that can be referenced in multiple places using the REFER operator.

The generic GLASS syntax for ALIAS and REFER is:

ALIAS '<label>' <expression>

REFER '<label>'

When an ALIAS label is referenced, the REFER keyword and label will be substituted with the previously defined ALIAS pattern. REFER operators can also be used when defining ALIAS expressions.

ALIAS and REFER Example 1

ACME Corporation wants to search for any occurrence of worldwide customer IDs in its storage systems.

The worldwide customer id is made up of several components that can be defined separately and joined together to form the anchor search pattern.

Part 1 - Prefix in Worldwide Customer ID

Case-insensitive search for WW prefix in the worldwide customer id.

WORD NOCASE 'ww'

Part 2 - Short Date in Worldwide Customer ID

GLASS expression to match the short date component (YYMMDD) in a worldwide customer id.

  1. YY is any two digits between 00 to 99.
    RANGE DIGIT TIMES 2
    
  2. MM is any valid month between 01 to 12. For this, we use the RANGE operator to search for 2 consecutive ASCII digits but limit the matches to specific values in a REQUIRE namespace.
    MAP 'MONTH_OF_YEAR_LOOKUP' 1-12
    
    RANGE DIGIT TIMES 2 REQUIRE 'MONTH_OF_YEAR_LOOKUP'
    
  3. DD is any valid month between 01 to 31. For this, we use the RANGE operator to search for 2 consecutive ASCII digits but limit the matches to specific values in a REQUIRE namespace.
    MAP 'DAY_OF_MONTH_LOOKUP' 1-31
    
    RANGE DIGIT TIMES 2 REQUIRE 'DAY_OF_MONTH_LOOKUP'
    

The three parts are joined together using the THEN connector, and the VALID_DATE_YYMMDD checksum module is applied to verify that the 6-digit pattern is a valid date between 1901-01-01 to 2099-12-31.

1 MAP 'MONTH_OF_YEAR_LOOKUP' 1-12
2 MAP 'DAY_OF_MONTH_LOOKUP' 1-31
3  
4 ( \
5   RANGE DIGIT TIMES 2 THEN \
6   (RANGE DIGIT TIMES 2 REQUIRE 'MONTH_OF_YEAR_LOOKUP') THEN \
7   (RANGE DIGIT TIMES 2 REQUIRE 'DAY_OF_MONTH_LOOKUP') \
8 ) CHECK 'VALID_DATE_YYMMDD'

To improve the readability of the GLASS code, we can use the ALIAS operator to group the expressions from Line 5 to Line 7, and reference it using the REFER operator.

1 MAP 'MONTH_OF_YEAR_LOOKUP' 1-12
2 MAP 'DAY_OF_MONTH_LOOKUP' 1-31
3  
4 ALIAS 'ACME_CUST_ID_WORLDWIDE_YYMMDD' \
5   RANGE DIGIT TIMES 2 THEN \
6   (RANGE DIGIT TIMES 2 REQUIRE 'MONTH_OF_YEAR_LOOKUP') THEN \
7   (RANGE DIGIT TIMES 2 REQUIRE 'DAY_OF_MONTH_LOOKUP')
8  
9 REFER 'ACME_CUST_ID_WORLDWIDE_YYMMDD' CHECK 'VALID_DATE_YYMMDD'

When the GLASS parser performs the substitution, the REFER 'ACME_CUST_ID_WORLDWIDE_YYMMDD' expression in Line 9 will be replaced with the (implicitly parenthesized) expressions from Line 5 to Line 7.

Part 3 - 5-digit Serial Number in Worldwide Customer ID

GLASS expression to match valid 5-digit serial numbers in a worldwide customer id.

MAP 'INVALID_SERIAL_NUM' 0

RANGE DIGIT TIMES 5 EXCLUDE 'INVALID_SERIAL_NUM'

Part 4 - Single Check Digit in Worldwide Customer ID

GLASS expression to match the single check digit in a worldwide customer id.

RANGE DIGIT

Part 4 - Joining the Anchor Patterns for Worldwide Customer ID

GLASS expression that joins the expressions from Part 1 to Part 3 to complete the anchor pattern for the worldwide customer id.

MAP 'MONTH_OF_YEAR_LOOKUP' 1-12
MAP 'DAY_OF_MONTH_LOOKUP' 1-31
MAP 'INVALID_SERIAL_NUM' 0

ALIAS 'ACME_CUST_ID_WORLDWIDE_YYMMDD' \
  RANGE DIGIT TIMES 2 THEN \
  (RANGE DIGIT TIMES 2 REQUIRE 'MONTH_OF_YEAR_LOOKUP') THEN \
  (RANGE DIGIT TIMES 2 REQUIRE 'DAY_OF_MONTH_LOOKUP')

WORD NOCASE 'ww' THEN \
REFER 'ACME_CUST_ID_WORLDWIDE_YYMMDD' CHECK 'VALID_DATE_YYMMDD' THEN \
RANGE DIGIT TIMES 5 EXCLUDE 'INVALID_SERIAL_NUM' THEN \
RANGE DIGIT

Part 5 - Checksum Validation and Boundary Rules for Worldwide Customer ID

GLASS expression to define the pattern boundaries and include the checksum validation for the worldwide customer id.

MAP 'MONTH_OF_YEAR_LOOKUP' 1-12
MAP 'DAY_OF_MONTH_LOOKUP' 1-31
MAP 'INVALID_SERIAL_NUM' 0

ALIAS 'ACME_CUST_ID_WORLDWIDE_YYMMDD' \
  RANGE DIGIT TIMES 2 THEN \
  (RANGE DIGIT TIMES 2 REQUIRE 'MONTH_OF_YEAR_LOOKUP') THEN \
  (RANGE DIGIT TIMES 2 REQUIRE 'DAY_OF_MONTH_LOOKUP')

( \
  WORD NOCASE 'ww' THEN \
  REFER 'ACME_CUST_ID_WORLDWIDE_YYMMDD' CHECK 'VALID_DATE_YYMMDD' THEN \
  RANGE DIGIT TIMES 5 EXCLUDE 'INVALID_SERIAL_NUM' THEN \
  RANGE DIGIT \
) CHECK 'PASSPORTMOD10' BOUND NONALNUM